acl_delete_response.go 3.4 KB

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