acl_create_response.go 1.7 KB

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