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