acl_delete_response.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package sarama
  2. import "time"
  3. type DeleteAclsResponse struct {
  4. ThrottleTime time.Duration
  5. FilterResponses []*FilterResponse
  6. }
  7. func (a *DeleteAclsResponse) encode(pe packetEncoder) error {
  8. pe.putInt32(int32(a.ThrottleTime / time.Millisecond))
  9. if err := pe.putArrayLength(len(a.FilterResponses)); err != nil {
  10. return err
  11. }
  12. for _, filterResponse := range a.FilterResponses {
  13. if err := filterResponse.encode(pe); err != nil {
  14. return err
  15. }
  16. }
  17. return nil
  18. }
  19. func (a *DeleteAclsResponse) decode(pd packetDecoder, version int16) (err error) {
  20. throttleTime, err := pd.getInt32()
  21. if err != nil {
  22. return err
  23. }
  24. a.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  25. n, err := pd.getArrayLength()
  26. if err != nil {
  27. return err
  28. }
  29. a.FilterResponses = make([]*FilterResponse, n)
  30. for i := 0; i < n; i++ {
  31. a.FilterResponses[i] = new(FilterResponse)
  32. if err := a.FilterResponses[i].decode(pd, version); err != nil {
  33. return err
  34. }
  35. }
  36. return nil
  37. }
  38. func (d *DeleteAclsResponse) key() int16 {
  39. return 31
  40. }
  41. func (d *DeleteAclsResponse) version() int16 {
  42. return 0
  43. }
  44. func (d *DeleteAclsResponse) requiredVersion() KafkaVersion {
  45. return V0_11_0_0
  46. }
  47. type FilterResponse struct {
  48. Err KError
  49. ErrMsg *string
  50. MatchingAcls []*MatchingAcl
  51. }
  52. func (f *FilterResponse) encode(pe packetEncoder) error {
  53. pe.putInt16(int16(f.Err))
  54. if err := pe.putNullableString(f.ErrMsg); err != nil {
  55. return err
  56. }
  57. if err := pe.putArrayLength(len(f.MatchingAcls)); err != nil {
  58. return err
  59. }
  60. for _, matchingAcl := range f.MatchingAcls {
  61. if err := matchingAcl.encode(pe); err != nil {
  62. return err
  63. }
  64. }
  65. return nil
  66. }
  67. func (f *FilterResponse) decode(pd packetDecoder, version int16) (err error) {
  68. kerr, err := pd.getInt16()
  69. if err != nil {
  70. return err
  71. }
  72. f.Err = KError(kerr)
  73. if f.ErrMsg, err = pd.getNullableString(); err != nil {
  74. return err
  75. }
  76. n, err := pd.getArrayLength()
  77. if err != nil {
  78. return err
  79. }
  80. f.MatchingAcls = make([]*MatchingAcl, n)
  81. for i := 0; i < n; i++ {
  82. f.MatchingAcls[i] = new(MatchingAcl)
  83. if err := f.MatchingAcls[i].decode(pd, version); err != nil {
  84. return err
  85. }
  86. }
  87. return nil
  88. }
  89. type MatchingAcl struct {
  90. Err KError
  91. ErrMsg *string
  92. Resource
  93. Acl
  94. }
  95. func (m *MatchingAcl) encode(pe packetEncoder) error {
  96. pe.putInt16(int16(m.Err))
  97. if err := pe.putNullableString(m.ErrMsg); err != nil {
  98. return err
  99. }
  100. if err := m.Resource.encode(pe); err != nil {
  101. return err
  102. }
  103. if err := m.Acl.encode(pe); err != nil {
  104. return err
  105. }
  106. return nil
  107. }
  108. func (m *MatchingAcl) decode(pd packetDecoder, version int16) (err error) {
  109. kerr, err := pd.getInt16()
  110. if err != nil {
  111. return err
  112. }
  113. m.Err = KError(kerr)
  114. if m.ErrMsg, err = pd.getNullableString(); err != nil {
  115. return err
  116. }
  117. if err := m.Resource.decode(pd, version); err != nil {
  118. return err
  119. }
  120. if err := m.Acl.decode(pd, version); err != nil {
  121. return err
  122. }
  123. return nil
  124. }