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 | //AddPartitionsToTxnRequest is a add paartition request |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 4 | type AddPartitionsToTxnRequest struct { |
| 5 | TransactionalID string |
| 6 | ProducerID int64 |
| 7 | ProducerEpoch int16 |
| 8 | TopicPartitions map[string][]int32 |
| 9 | } |
| 10 | |
| 11 | func (a *AddPartitionsToTxnRequest) encode(pe packetEncoder) error { |
| 12 | if err := pe.putString(a.TransactionalID); err != nil { |
| 13 | return err |
| 14 | } |
| 15 | pe.putInt64(a.ProducerID) |
| 16 | pe.putInt16(a.ProducerEpoch) |
| 17 | |
| 18 | if err := pe.putArrayLength(len(a.TopicPartitions)); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | for topic, partitions := range a.TopicPartitions { |
| 22 | if err := pe.putString(topic); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | if err := pe.putInt32Array(partitions); err != nil { |
| 26 | return err |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | func (a *AddPartitionsToTxnRequest) decode(pd packetDecoder, version int16) (err error) { |
| 34 | if a.TransactionalID, err = pd.getString(); err != nil { |
| 35 | return err |
| 36 | } |
| 37 | if a.ProducerID, err = pd.getInt64(); err != nil { |
| 38 | return err |
| 39 | } |
| 40 | if a.ProducerEpoch, err = pd.getInt16(); err != nil { |
| 41 | return err |
| 42 | } |
| 43 | |
| 44 | n, err := pd.getArrayLength() |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | a.TopicPartitions = make(map[string][]int32) |
| 50 | for i := 0; i < n; i++ { |
| 51 | topic, err := pd.getString() |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | partitions, err := pd.getInt32Array() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | a.TopicPartitions[topic] = partitions |
| 62 | } |
| 63 | |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | func (a *AddPartitionsToTxnRequest) key() int16 { |
| 68 | return 24 |
| 69 | } |
| 70 | |
| 71 | func (a *AddPartitionsToTxnRequest) version() int16 { |
| 72 | return 0 |
| 73 | } |
| 74 | |
| 75 | func (a *AddPartitionsToTxnRequest) requiredVersion() KafkaVersion { |
| 76 | return V0_11_0_0 |
| 77 | } |