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