acl_create_request.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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) isValidVersion() bool {
  43. return c.Version >= 0 && c.Version <= 1
  44. }
  45. func (c *CreateAclsRequest) requiredVersion() KafkaVersion {
  46. switch c.Version {
  47. case 1:
  48. return V2_0_0_0
  49. default:
  50. return V0_11_0_0
  51. }
  52. }
  53. // AclCreation is a wrapper around Resource and Acl type
  54. type AclCreation struct {
  55. Resource
  56. Acl
  57. }
  58. func (a *AclCreation) encode(pe packetEncoder, version int16) error {
  59. if err := a.Resource.encode(pe, version); err != nil {
  60. return err
  61. }
  62. if err := a.Acl.encode(pe); err != nil {
  63. return err
  64. }
  65. return nil
  66. }
  67. func (a *AclCreation) decode(pd packetDecoder, version int16) (err error) {
  68. if err := a.Resource.decode(pd, version); err != nil {
  69. return err
  70. }
  71. if err := a.Acl.decode(pd, version); err != nil {
  72. return err
  73. }
  74. return nil
  75. }