Debian Codegraph @

alter_partition_reassignments_response.go

raw symbols SCIP
1 package sarama
2
3 import "time"
4
5 type alterPartitionReassignmentsErrorBlock struct {
6 errorCode KError
7 errorMessage *string
8 }
9
10 func (b *alterPartitionReassignmentsErrorBlock) encode(pe packetEncoder) error {
11 pe.putKError(b.errorCode)
12 if err := pe.putNullableString(b.errorMessage); err != nil {
13 return err
14 }
15 pe.putEmptyTaggedFieldArray()
16
17 return nil
18 }
19
20 func (b *alterPartitionReassignmentsErrorBlock) decode(pd packetDecoder) (err error) {
21 b.errorCode, err = pd.getKError()
22 if err != nil {
23 return err
24 }
25 b.errorMessage, err = pd.getNullableString()
26 if err != nil {
27 return err
28 }
29
30 _, err = pd.getEmptyTaggedFieldArray()
31 return err
32 }
33
34 type AlterPartitionReassignmentsResponse struct {
35 Version int16
36 ThrottleTimeMs int32
37 ErrorCode KError
38 ErrorMessage *string
39 Errors map[string]map[int32]*alterPartitionReassignmentsErrorBlock
40 }
41
42 func (r *AlterPartitionReassignmentsResponse) setVersion(v int16) {
43 r.Version = v
44 }
45
46 func (r *AlterPartitionReassignmentsResponse) AddError(topic string, partition int32, kerror KError, message *string) {
47 if r.Errors == nil {
48 r.Errors = make(map[string]map[int32]*alterPartitionReassignmentsErrorBlock)
49 }
50 partitions := r.Errors[topic]
51 if partitions == nil {
52 partitions = make(map[int32]*alterPartitionReassignmentsErrorBlock)
53 r.Errors[topic] = partitions
54 }
55
56 partitions[partition] = &alterPartitionReassignmentsErrorBlock{errorCode: kerror, errorMessage: message}
57 }
58
59 func (r *AlterPartitionReassignmentsResponse) encode(pe packetEncoder) error {
60 pe.putInt32(r.ThrottleTimeMs)
61 pe.putKError(r.ErrorCode)
62 if err := pe.putNullableString(r.ErrorMessage); err != nil {
63 return err
64 }
65
66 if err := pe.putArrayLength(len(r.Errors)); err != nil {
67 return err
68 }
69 for topic, partitions := range r.Errors {
70 if err := pe.putString(topic); err != nil {
71 return err
72 }
73 if err := pe.putArrayLength(len(partitions)); err != nil {
74 return err
75 }
76 for partition, block := range partitions {
77 pe.putInt32(partition)
78
79 if err := block.encode(pe); err != nil {
80 return err
81 }
82 }
83 pe.putEmptyTaggedFieldArray()
84 }
85
86 pe.putEmptyTaggedFieldArray()
87 return nil
88 }
89
90 func (r *AlterPartitionReassignmentsResponse) decode(pd packetDecoder, version int16) (err error) {
91 r.Version = version
92
93 if r.ThrottleTimeMs, err = pd.getInt32(); err != nil {
94 return err
95 }
96
97 r.ErrorCode, err = pd.getKError()
98 if err != nil {
99 return err
100 }
101
102 if r.ErrorMessage, err = pd.getNullableString(); err != nil {
103 return err
104 }
105
106 numTopics, err := pd.getArrayLength()
107 if err != nil {
108 return err
109 }
110
111 if numTopics > 0 {
112 r.Errors = make(map[string]map[int32]*alterPartitionReassignmentsErrorBlock, numTopics)
113 for i := 0; i < numTopics; i++ {
114 topic, err := pd.getString()
115 if err != nil {
116 return err
117 }
118
119 ongoingPartitionReassignments, err := pd.getArrayLength()
120 if err != nil {
121 return err
122 }
123
124 r.Errors[topic] = make(map[int32]*alterPartitionReassignmentsErrorBlock, ongoingPartitionReassignments)
125
126 for j := 0; j < ongoingPartitionReassignments; j++ {
127 partition, err := pd.getInt32()
128 if err != nil {
129 return err
130 }
131 block := &alterPartitionReassignmentsErrorBlock{}
132 if err := block.decode(pd); err != nil {
133 return err
134 }
135
136 r.Errors[topic][partition] = block
137 }
138 if _, err = pd.getEmptyTaggedFieldArray(); err != nil {
139 return err
140 }
141 }
142 }
143
144 _, err = pd.getEmptyTaggedFieldArray()
145 return err
146 }
147
148 func (r *AlterPartitionReassignmentsResponse) key() int16 {
149 return apiKeyAlterPartitionReassignments
150 }
151
152 func (r *AlterPartitionReassignmentsResponse) version() int16 {
153 return r.Version
154 }
155
156 func (r *AlterPartitionReassignmentsResponse) headerVersion() int16 {
157 return 1
158 }
159
160 func (r *AlterPartitionReassignmentsResponse) isValidVersion() bool {
161 return r.Version == 0
162 }
163
164 func (r *AlterPartitionReassignmentsResponse) isFlexible() bool {
165 return r.isFlexibleVersion(r.Version)
166 }
167
168 func (r *AlterPartitionReassignmentsResponse) isFlexibleVersion(version int16) bool {
169 return version >= 0
170 }
171
172 func (r *AlterPartitionReassignmentsResponse) requiredVersion() KafkaVersion {
173 return V2_4_0_0
174 }
175
176 func (r *AlterPartitionReassignmentsResponse) throttleTime() time.Duration {
177 return time.Duration(r.ThrottleTimeMs) * time.Millisecond
178 }