acl_create_response.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package sarama
  2. import "time"
  3. //CreateAclsResponse is a an acl response 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) headerVersion() int16 {
  46. return 0
  47. }
  48. func (c *CreateAclsResponse) requiredVersion() KafkaVersion {
  49. return V0_11_0_0
  50. }
  51. //AclCreationResponse is an acl creation response type
  52. type AclCreationResponse struct {
  53. Err KError
  54. ErrMsg *string
  55. }
  56. func (a *AclCreationResponse) encode(pe packetEncoder) error {
  57. pe.putInt16(int16(a.Err))
  58. if err := pe.putNullableString(a.ErrMsg); err != nil {
  59. return err
  60. }
  61. return nil
  62. }
  63. func (a *AclCreationResponse) decode(pd packetDecoder, version int16) (err error) {
  64. kerr, err := pd.getInt16()
  65. if err != nil {
  66. return err
  67. }
  68. a.Err = KError(kerr)
  69. if a.ErrMsg, err = pd.getNullableString(); err != nil {
  70. return err
  71. }
  72. return nil
  73. }