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