acl_create_response.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sarama
  2. import "time"
  3. //CreateAclsResponse is a an acl reponse creation type
  4. type CreateAclsResponse struct {
  5. ThrottleTime time.Duration
  6. AclCreationResponses []*AclCreationResponse
  7. }
  8. func (c *CreateAclsResponse) encode(pe packetEncoder) error {
  9. pe.putInt32(int32(c.ThrottleTime / time.Millisecond))
  10. if err := pe.putArrayLength(len(c.AclCreationResponses)); err != nil {
  11. return err
  12. }
  13. for _, aclCreationResponse := range c.AclCreationResponses {
  14. if err := aclCreationResponse.encode(pe); err != nil {
  15. return err
  16. }
  17. }
  18. return nil
  19. }
  20. func (c *CreateAclsResponse) decode(pd packetDecoder, version int16) (err error) {
  21. throttleTime, err := pd.getInt32()
  22. if err != nil {
  23. return err
  24. }
  25. c.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  26. n, err := pd.getArrayLength()
  27. if err != nil {
  28. return err
  29. }
  30. c.AclCreationResponses = make([]*AclCreationResponse, n)
  31. for i := 0; i < n; i++ {
  32. c.AclCreationResponses[i] = new(AclCreationResponse)
  33. if err := c.AclCreationResponses[i].decode(pd, version); err != nil {
  34. return err
  35. }
  36. }
  37. return nil
  38. }
  39. func (c *CreateAclsResponse) key() int16 {
  40. return 30
  41. }
  42. func (c *CreateAclsResponse) version() int16 {
  43. return 0
  44. }
  45. func (c *CreateAclsResponse) requiredVersion() KafkaVersion {
  46. return V0_11_0_0
  47. }
  48. //AclCreationResponse is an acl creation response type
  49. type AclCreationResponse struct {
  50. Err KError
  51. ErrMsg *string
  52. }
  53. func (a *AclCreationResponse) encode(pe packetEncoder) error {
  54. pe.putInt16(int16(a.Err))
  55. if err := pe.putNullableString(a.ErrMsg); err != nil {
  56. return err
  57. }
  58. return nil
  59. }
  60. func (a *AclCreationResponse) decode(pd packetDecoder, version int16) (err error) {
  61. kerr, err := pd.getInt16()
  62. if err != nil {
  63. return err
  64. }
  65. a.Err = KError(kerr)
  66. if a.ErrMsg, err = pd.getNullableString(); err != nil {
  67. return err
  68. }
  69. return nil
  70. }