blob: 57ecf64884de9a6b27c36107c938feaf02a63506 [file] [log] [blame]
Scott Bakered4efab2020-01-13 19:12:25 -08001package sarama
2
David K. Bainbridgebd6b2882021-08-26 13:31:02 +00003// AddPartitionsToTxnRequest is a add paartition request
Scott Bakered4efab2020-01-13 19:12:25 -08004type AddPartitionsToTxnRequest struct {
5 TransactionalID string
6 ProducerID int64
7 ProducerEpoch int16
8 TopicPartitions map[string][]int32
9}
10
11func (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
33func (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
67func (a *AddPartitionsToTxnRequest) key() int16 {
68 return 24
69}
70
71func (a *AddPartitionsToTxnRequest) version() int16 {
72 return 0
73}
74
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000075func (a *AddPartitionsToTxnRequest) headerVersion() int16 {
76 return 1
77}
78
Scott Bakered4efab2020-01-13 19:12:25 -080079func (a *AddPartitionsToTxnRequest) requiredVersion() KafkaVersion {
80 return V0_11_0_0
81}