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