Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 1 | package sarama |
| 2 | |
| 3 | import "time" |
| 4 | |
Scott Baker | f579f13 | 2019-10-24 14:31:41 -0700 | [diff] [blame] | 5 | //DescribeAclsResponse is a describe acl response type |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 6 | type DescribeAclsResponse struct { |
| 7 | Version int16 |
| 8 | ThrottleTime time.Duration |
| 9 | Err KError |
| 10 | ErrMsg *string |
| 11 | ResourceAcls []*ResourceAcls |
| 12 | } |
| 13 | |
| 14 | func (d *DescribeAclsResponse) encode(pe packetEncoder) error { |
| 15 | pe.putInt32(int32(d.ThrottleTime / time.Millisecond)) |
| 16 | pe.putInt16(int16(d.Err)) |
| 17 | |
| 18 | if err := pe.putNullableString(d.ErrMsg); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | |
| 22 | if err := pe.putArrayLength(len(d.ResourceAcls)); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | |
| 26 | for _, resourceAcl := range d.ResourceAcls { |
| 27 | if err := resourceAcl.encode(pe, d.Version); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | func (d *DescribeAclsResponse) decode(pd packetDecoder, version int16) (err error) { |
| 36 | throttleTime, err := pd.getInt32() |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | d.ThrottleTime = time.Duration(throttleTime) * time.Millisecond |
| 41 | |
| 42 | kerr, err := pd.getInt16() |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | d.Err = KError(kerr) |
| 47 | |
| 48 | errmsg, err := pd.getString() |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | if errmsg != "" { |
| 53 | d.ErrMsg = &errmsg |
| 54 | } |
| 55 | |
| 56 | n, err := pd.getArrayLength() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | d.ResourceAcls = make([]*ResourceAcls, n) |
| 61 | |
| 62 | for i := 0; i < n; i++ { |
| 63 | d.ResourceAcls[i] = new(ResourceAcls) |
| 64 | if err := d.ResourceAcls[i].decode(pd, version); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (d *DescribeAclsResponse) key() int16 { |
| 73 | return 29 |
| 74 | } |
| 75 | |
| 76 | func (d *DescribeAclsResponse) version() int16 { |
| 77 | return int16(d.Version) |
| 78 | } |
| 79 | |
| 80 | func (d *DescribeAclsResponse) requiredVersion() KafkaVersion { |
| 81 | switch d.Version { |
| 82 | case 1: |
| 83 | return V2_0_0_0 |
| 84 | default: |
| 85 | return V0_11_0_0 |
| 86 | } |
| 87 | } |