acl_create_request.go 1.6 KB

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