acl_delete_response.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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) requiredVersion() KafkaVersion {
  50. return V0_11_0_0
  51. }
  52. //FilterResponse is a filter response type
  53. type FilterResponse struct {
  54. Err KError
  55. ErrMsg *string
  56. MatchingAcls []*MatchingAcl
  57. }
  58. func (f *FilterResponse) encode(pe packetEncoder, version int16) error {
  59. pe.putInt16(int16(f.Err))
  60. if err := pe.putNullableString(f.ErrMsg); err != nil {
  61. return err
  62. }
  63. if err := pe.putArrayLength(len(f.MatchingAcls)); err != nil {
  64. return err
  65. }
  66. for _, matchingAcl := range f.MatchingAcls {
  67. if err := matchingAcl.encode(pe, version); err != nil {
  68. return err
  69. }
  70. }
  71. return nil
  72. }
  73. func (f *FilterResponse) decode(pd packetDecoder, version int16) (err error) {
  74. kerr, err := pd.getInt16()
  75. if err != nil {
  76. return err
  77. }
  78. f.Err = KError(kerr)
  79. if f.ErrMsg, err = pd.getNullableString(); err != nil {
  80. return err
  81. }
  82. n, err := pd.getArrayLength()
  83. if err != nil {
  84. return err
  85. }
  86. f.MatchingAcls = make([]*MatchingAcl, n)
  87. for i := 0; i < n; i++ {
  88. f.MatchingAcls[i] = new(MatchingAcl)
  89. if err := f.MatchingAcls[i].decode(pd, version); err != nil {
  90. return err
  91. }
  92. }
  93. return nil
  94. }
  95. //MatchingAcl is a matching acl type
  96. type MatchingAcl struct {
  97. Err KError
  98. ErrMsg *string
  99. Resource
  100. Acl
  101. }
  102. func (m *MatchingAcl) encode(pe packetEncoder, version int16) error {
  103. pe.putInt16(int16(m.Err))
  104. if err := pe.putNullableString(m.ErrMsg); err != nil {
  105. return err
  106. }
  107. if err := m.Resource.encode(pe, version); err != nil {
  108. return err
  109. }
  110. if err := m.Acl.encode(pe); err != nil {
  111. return err
  112. }
  113. return nil
  114. }
  115. func (m *MatchingAcl) decode(pd packetDecoder, version int16) (err error) {
  116. kerr, err := pd.getInt16()
  117. if err != nil {
  118. return err
  119. }
  120. m.Err = KError(kerr)
  121. if m.ErrMsg, err = pd.getNullableString(); err != nil {
  122. return err
  123. }
  124. if err := m.Resource.decode(pd, version); err != nil {
  125. return err
  126. }
  127. if err := m.Acl.decode(pd, version); err != nil {
  128. return err
  129. }
  130. return nil
  131. }