acl_create_response.go 2.2 KB

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