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