acl_bindings.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package sarama
  2. type Resource struct {
  3. ResourceType AclResourceType
  4. ResourceName string
  5. }
  6. func (r *Resource) encode(pe packetEncoder) error {
  7. pe.putInt8(int8(r.ResourceType))
  8. if err := pe.putString(r.ResourceName); err != nil {
  9. return err
  10. }
  11. return nil
  12. }
  13. func (r *Resource) decode(pd packetDecoder, version int16) (err error) {
  14. resourceType, err := pd.getInt8()
  15. if err != nil {
  16. return err
  17. }
  18. r.ResourceType = AclResourceType(resourceType)
  19. if r.ResourceName, err = pd.getString(); err != nil {
  20. return err
  21. }
  22. return nil
  23. }
  24. type Acl struct {
  25. Principal string
  26. Host string
  27. Operation AclOperation
  28. PermissionType AclPermissionType
  29. }
  30. func (a *Acl) encode(pe packetEncoder) error {
  31. if err := pe.putString(a.Principal); err != nil {
  32. return err
  33. }
  34. if err := pe.putString(a.Host); err != nil {
  35. return err
  36. }
  37. pe.putInt8(int8(a.Operation))
  38. pe.putInt8(int8(a.PermissionType))
  39. return nil
  40. }
  41. func (a *Acl) decode(pd packetDecoder, version int16) (err error) {
  42. if a.Principal, err = pd.getString(); err != nil {
  43. return err
  44. }
  45. if a.Host, err = pd.getString(); err != nil {
  46. return err
  47. }
  48. operation, err := pd.getInt8()
  49. if err != nil {
  50. return err
  51. }
  52. a.Operation = AclOperation(operation)
  53. permissionType, err := pd.getInt8()
  54. if err != nil {
  55. return err
  56. }
  57. a.PermissionType = AclPermissionType(permissionType)
  58. return nil
  59. }
  60. type ResourceAcls struct {
  61. Resource
  62. Acls []*Acl
  63. }
  64. func (r *ResourceAcls) encode(pe packetEncoder) error {
  65. if err := r.Resource.encode(pe); err != nil {
  66. return err
  67. }
  68. if err := pe.putArrayLength(len(r.Acls)); err != nil {
  69. return err
  70. }
  71. for _, acl := range r.Acls {
  72. if err := acl.encode(pe); err != nil {
  73. return err
  74. }
  75. }
  76. return nil
  77. }
  78. func (r *ResourceAcls) decode(pd packetDecoder, version int16) error {
  79. if err := r.Resource.decode(pd, version); err != nil {
  80. return err
  81. }
  82. n, err := pd.getArrayLength()
  83. if err != nil {
  84. return err
  85. }
  86. r.Acls = make([]*Acl, n)
  87. for i := 0; i < n; i++ {
  88. r.Acls[i] = new(Acl)
  89. if err := r.Acls[i].decode(pd, version); err != nil {
  90. return err
  91. }
  92. }
  93. return nil
  94. }