acl_create_request.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package sarama
  2. //CreateAclsRequest is an acl creation request
  3. type CreateAclsRequest struct {
  4. Version int16
  5. AclCreations []*AclCreation
  6. }
  7. func (c *CreateAclsRequest) encode(pe packetEncoder) error {
  8. if err := pe.putArrayLength(len(c.AclCreations)); err != nil {
  9. return err
  10. }
  11. for _, aclCreation := range c.AclCreations {
  12. if err := aclCreation.encode(pe, c.Version); err != nil {
  13. return err
  14. }
  15. }
  16. return nil
  17. }
  18. func (c *CreateAclsRequest) decode(pd packetDecoder, version int16) (err error) {
  19. c.Version = version
  20. n, err := pd.getArrayLength()
  21. if err != nil {
  22. return err
  23. }
  24. c.AclCreations = make([]*AclCreation, n)
  25. for i := 0; i < n; i++ {
  26. c.AclCreations[i] = new(AclCreation)
  27. if err := c.AclCreations[i].decode(pd, version); err != nil {
  28. return err
  29. }
  30. }
  31. return nil
  32. }
  33. func (c *CreateAclsRequest) key() int16 {
  34. return 30
  35. }
  36. func (c *CreateAclsRequest) version() int16 {
  37. return c.Version
  38. }
  39. func (c *CreateAclsRequest) headerVersion() int16 {
  40. return 1
  41. }
  42. func (c *CreateAclsRequest) requiredVersion() KafkaVersion {
  43. switch c.Version {
  44. case 1:
  45. return V2_0_0_0
  46. default:
  47. return V0_11_0_0
  48. }
  49. }
  50. //AclCreation is a wrapper around Resource and Acl type
  51. type AclCreation struct {
  52. Resource
  53. Acl
  54. }
  55. func (a *AclCreation) encode(pe packetEncoder, version int16) error {
  56. if err := a.Resource.encode(pe, version); err != nil {
  57. return err
  58. }
  59. if err := a.Acl.encode(pe); err != nil {
  60. return err
  61. }
  62. return nil
  63. }
  64. func (a *AclCreation) decode(pd packetDecoder, version int16) (err error) {
  65. if err := a.Resource.decode(pd, version); err != nil {
  66. return err
  67. }
  68. if err := a.Acl.decode(pd, version); err != nil {
  69. return err
  70. }
  71. return nil
  72. }