acl_delete_response.go 3.1 KB

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