blob: f0a2f9dd59b11a19d8af56f17c6c2621a87c21b2 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001package sarama
2
3type alterPartitionReassignmentsBlock struct {
4 replicas []int32
5}
6
7func (b *alterPartitionReassignmentsBlock) encode(pe packetEncoder) error {
8 if err := pe.putNullableCompactInt32Array(b.replicas); err != nil {
9 return err
10 }
11
12 pe.putEmptyTaggedFieldArray()
13 return nil
14}
15
16func (b *alterPartitionReassignmentsBlock) decode(pd packetDecoder) (err error) {
17 if b.replicas, err = pd.getCompactInt32Array(); err != nil {
18 return err
19 }
20 return nil
21}
22
23type AlterPartitionReassignmentsRequest struct {
24 TimeoutMs int32
25 blocks map[string]map[int32]*alterPartitionReassignmentsBlock
26 Version int16
27}
28
29func (r *AlterPartitionReassignmentsRequest) encode(pe packetEncoder) error {
30 pe.putInt32(r.TimeoutMs)
31
32 pe.putCompactArrayLength(len(r.blocks))
33
34 for topic, partitions := range r.blocks {
35 if err := pe.putCompactString(topic); err != nil {
36 return err
37 }
38 pe.putCompactArrayLength(len(partitions))
39 for partition, block := range partitions {
40 pe.putInt32(partition)
41 if err := block.encode(pe); err != nil {
42 return err
43 }
44 }
45 pe.putEmptyTaggedFieldArray()
46 }
47
48 pe.putEmptyTaggedFieldArray()
49
50 return nil
51}
52
53func (r *AlterPartitionReassignmentsRequest) decode(pd packetDecoder, version int16) (err error) {
54 r.Version = version
55
56 if r.TimeoutMs, err = pd.getInt32(); err != nil {
57 return err
58 }
59
60 topicCount, err := pd.getCompactArrayLength()
61 if err != nil {
62 return err
63 }
64 if topicCount > 0 {
65 r.blocks = make(map[string]map[int32]*alterPartitionReassignmentsBlock)
66 for i := 0; i < topicCount; i++ {
67 topic, err := pd.getCompactString()
68 if err != nil {
69 return err
70 }
71 partitionCount, err := pd.getCompactArrayLength()
72 if err != nil {
73 return err
74 }
75 r.blocks[topic] = make(map[int32]*alterPartitionReassignmentsBlock)
76 for j := 0; j < partitionCount; j++ {
77 partition, err := pd.getInt32()
78 if err != nil {
79 return err
80 }
81 block := &alterPartitionReassignmentsBlock{}
82 if err := block.decode(pd); err != nil {
83 return err
84 }
85 r.blocks[topic][partition] = block
86
87 if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
88 return err
89 }
90 }
91 if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
92 return err
93 }
94 }
95 }
96
97 if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
98 return err
99 }
100
101 return
102}
103
104func (r *AlterPartitionReassignmentsRequest) key() int16 {
105 return 45
106}
107
108func (r *AlterPartitionReassignmentsRequest) version() int16 {
109 return r.Version
110}
111
112func (r *AlterPartitionReassignmentsRequest) headerVersion() int16 {
113 return 2
114}
115
116func (r *AlterPartitionReassignmentsRequest) requiredVersion() KafkaVersion {
117 return V2_4_0_0
118}
119
120func (r *AlterPartitionReassignmentsRequest) AddBlock(topic string, partitionID int32, replicas []int32) {
121 if r.blocks == nil {
122 r.blocks = make(map[string]map[int32]*alterPartitionReassignmentsBlock)
123 }
124
125 if r.blocks[topic] == nil {
126 r.blocks[topic] = make(map[int32]*alterPartitionReassignmentsBlock)
127 }
128
129 r.blocks[topic][partitionID] = &alterPartitionReassignmentsBlock{replicas}
130}