blob: c1ffa9ba02b71f083c5ec3303b302757e800a3d1 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001package sarama
2
3type ListPartitionReassignmentsRequest struct {
4 TimeoutMs int32
5 blocks map[string][]int32
6 Version int16
7}
8
9func (r *ListPartitionReassignmentsRequest) encode(pe packetEncoder) error {
10 pe.putInt32(r.TimeoutMs)
11
12 pe.putCompactArrayLength(len(r.blocks))
13
14 for topic, partitions := range r.blocks {
15 if err := pe.putCompactString(topic); err != nil {
16 return err
17 }
18
19 if err := pe.putCompactInt32Array(partitions); err != nil {
20 return err
21 }
22
23 pe.putEmptyTaggedFieldArray()
24 }
25
26 pe.putEmptyTaggedFieldArray()
27
28 return nil
29}
30
31func (r *ListPartitionReassignmentsRequest) decode(pd packetDecoder, version int16) (err error) {
32 r.Version = version
33
34 if r.TimeoutMs, err = pd.getInt32(); err != nil {
35 return err
36 }
37
38 topicCount, err := pd.getCompactArrayLength()
39 if err != nil {
40 return err
41 }
42 if topicCount > 0 {
43 r.blocks = make(map[string][]int32)
44 for i := 0; i < topicCount; i++ {
45 topic, err := pd.getCompactString()
46 if err != nil {
47 return err
48 }
49 partitionCount, err := pd.getCompactArrayLength()
50 if err != nil {
51 return err
52 }
53 r.blocks[topic] = make([]int32, partitionCount)
54 for j := 0; j < partitionCount; j++ {
55 partition, err := pd.getInt32()
56 if err != nil {
57 return err
58 }
59 r.blocks[topic][j] = partition
60 }
61 if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
62 return err
63 }
64 }
65 }
66
67 if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
68 return err
69 }
70
71 return
72}
73
74func (r *ListPartitionReassignmentsRequest) key() int16 {
75 return 46
76}
77
78func (r *ListPartitionReassignmentsRequest) version() int16 {
79 return r.Version
80}
81
82func (r *ListPartitionReassignmentsRequest) headerVersion() int16 {
83 return 2
84}
85
86func (r *ListPartitionReassignmentsRequest) requiredVersion() KafkaVersion {
87 return V2_4_0_0
88}
89
90func (r *ListPartitionReassignmentsRequest) AddBlock(topic string, partitionIDs []int32) {
91 if r.blocks == nil {
92 r.blocks = make(map[string][]int32)
93 }
94
95 if r.blocks[topic] == nil {
96 r.blocks[topic] = partitionIDs
97 }
98}