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