crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 56;
10pub const MIN_VERSION: i16 = 2;
11pub const MAX_VERSION: i16 = 3;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct AlterPartitionResponse {
21 pub throttle_time_ms: i32,
22 pub error_code: i16,
23 pub topics: Vec<TopicData>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for AlterPartitionResponse {
27 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29 return Err(ProtocolError::UnsupportedVersion {
30 api_key: API_KEY,
31 version,
32 });
33 }
34 let flex = is_flexible(version);
35 if version >= 0 {
36 put_i32(buf, self.throttle_time_ms);
37 }
38 if version >= 0 {
39 put_i16(buf, self.error_code);
40 }
41 if version >= 0 {
42 {
43 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
44 for it in &self.topics {
45 it.encode(buf, version)?;
46 }
47 }
48 }
49 if flex {
50 let tagged = WriteTaggedFields::new();
51 tagged.write(buf, &self.unknown_tagged_fields);
52 }
53 Ok(())
54 }
55 fn encoded_len(&self, version: i16) -> usize {
56 let flex = is_flexible(version);
57 let mut n: usize = 0;
58 if version >= 0 {
59 n += 4;
60 }
61 if version >= 0 {
62 n += 2;
63 }
64 if version >= 0 {
65 n += {
66 let prefix =
67 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
68 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
69 prefix + body
70 };
71 }
72 if flex {
73 let known_pairs: Vec<(u32, usize)> = Vec::new();
74 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75 }
76 n
77 }
78}
79impl Decode<'_> for AlterPartitionResponse {
80 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
81 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82 return Err(ProtocolError::UnsupportedVersion {
83 api_key: API_KEY,
84 version,
85 });
86 }
87 let flex = is_flexible(version);
88 let mut out = Self::default();
89 if version >= 0 {
90 out.throttle_time_ms = get_i32(buf)?;
91 }
92 if version >= 0 {
93 out.error_code = get_i16(buf)?;
94 }
95 if version >= 0 {
96 out.topics = {
97 let n = crate::primitives::array::get_array_len(buf, flex)?;
98 let mut v = Vec::with_capacity(n);
99 for _ in 0..n {
100 v.push(TopicData::decode(buf, version)?);
101 }
102 v
103 };
104 }
105 if flex {
106 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
107 }
108 Ok(out)
109 }
110}
111#[cfg(test)]
112impl AlterPartitionResponse {
113 #[must_use]
114 pub fn populated(version: i16) -> Self {
115 let mut m = Self::default();
116 if version >= 0 {
117 m.throttle_time_ms = 1i32;
118 }
119 if version >= 0 {
120 m.error_code = 1i16;
121 }
122 if version >= 0 {
123 m.topics = vec![TopicData::populated(version)];
124 }
125 m
126 }
127}
128#[derive(Debug, Clone, PartialEq, Eq, Default)]
129pub struct TopicData {
130 pub topic_id: crate::primitives::uuid::Uuid,
131 pub partitions: Vec<PartitionData>,
132 pub unknown_tagged_fields: UnknownTaggedFields,
133}
134impl Encode for TopicData {
135 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136 let flex = version >= 0;
137 if version >= 2 {
138 crate::primitives::uuid::put_uuid(buf, self.topic_id);
139 }
140 if version >= 0 {
141 {
142 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
143 for it in &self.partitions {
144 it.encode(buf, version)?;
145 }
146 }
147 }
148 if flex {
149 let tagged = WriteTaggedFields::new();
150 tagged.write(buf, &self.unknown_tagged_fields);
151 }
152 Ok(())
153 }
154 fn encoded_len(&self, version: i16) -> usize {
155 let flex = version >= 0;
156 let mut n: usize = 0;
157 if version >= 2 {
158 n += 16;
159 }
160 if version >= 0 {
161 n += {
162 let prefix =
163 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
164 let body: usize = (self.partitions)
165 .iter()
166 .map(|it| it.encoded_len(version))
167 .sum();
168 prefix + body
169 };
170 }
171 if flex {
172 let known_pairs: Vec<(u32, usize)> = Vec::new();
173 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
174 }
175 n
176 }
177}
178impl Decode<'_> for TopicData {
179 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
180 let flex = version >= 0;
181 let mut out = Self::default();
182 if version >= 2 {
183 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
184 }
185 if version >= 0 {
186 out.partitions = {
187 let n = crate::primitives::array::get_array_len(buf, flex)?;
188 let mut v = Vec::with_capacity(n);
189 for _ in 0..n {
190 v.push(PartitionData::decode(buf, version)?);
191 }
192 v
193 };
194 }
195 if flex {
196 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
197 }
198 Ok(out)
199 }
200}
201#[cfg(test)]
202impl TopicData {
203 #[must_use]
204 pub fn populated(version: i16) -> Self {
205 let mut m = Self::default();
206 if version >= 2 {
207 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
208 }
209 if version >= 0 {
210 m.partitions = vec![PartitionData::populated(version)];
211 }
212 m
213 }
214}
215#[derive(Debug, Clone, PartialEq, Eq, Default)]
216pub struct PartitionData {
217 pub partition_index: i32,
218 pub error_code: i16,
219 pub leader_id: i32,
220 pub leader_epoch: i32,
221 pub isr: Vec<i32>,
222 pub leader_recovery_state: i8,
223 pub partition_epoch: i32,
224 pub unknown_tagged_fields: UnknownTaggedFields,
225}
226impl Encode for PartitionData {
227 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
228 let flex = version >= 0;
229 if version >= 0 {
230 put_i32(buf, self.partition_index);
231 }
232 if version >= 0 {
233 put_i16(buf, self.error_code);
234 }
235 if version >= 0 {
236 put_i32(buf, self.leader_id);
237 }
238 if version >= 0 {
239 put_i32(buf, self.leader_epoch);
240 }
241 if version >= 0 {
242 {
243 crate::primitives::array::put_array_len(buf, (self.isr).len(), flex);
244 for it in &self.isr {
245 put_i32(buf, *it);
246 }
247 }
248 }
249 if version >= 1 {
250 put_i8(buf, self.leader_recovery_state);
251 }
252 if version >= 0 {
253 put_i32(buf, self.partition_epoch);
254 }
255 if flex {
256 let tagged = WriteTaggedFields::new();
257 tagged.write(buf, &self.unknown_tagged_fields);
258 }
259 Ok(())
260 }
261 fn encoded_len(&self, version: i16) -> usize {
262 let flex = version >= 0;
263 let mut n: usize = 0;
264 if version >= 0 {
265 n += 4;
266 }
267 if version >= 0 {
268 n += 2;
269 }
270 if version >= 0 {
271 n += 4;
272 }
273 if version >= 0 {
274 n += 4;
275 }
276 if version >= 0 {
277 n += {
278 let prefix = crate::primitives::array::array_len_prefix_len((self.isr).len(), flex);
279 let body: usize = (self.isr).iter().map(|_| 4).sum();
280 prefix + body
281 };
282 }
283 if version >= 1 {
284 n += 1;
285 }
286 if version >= 0 {
287 n += 4;
288 }
289 if flex {
290 let known_pairs: Vec<(u32, usize)> = Vec::new();
291 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
292 }
293 n
294 }
295}
296impl Decode<'_> for PartitionData {
297 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
298 let flex = version >= 0;
299 let mut out = Self::default();
300 if version >= 0 {
301 out.partition_index = get_i32(buf)?;
302 }
303 if version >= 0 {
304 out.error_code = get_i16(buf)?;
305 }
306 if version >= 0 {
307 out.leader_id = get_i32(buf)?;
308 }
309 if version >= 0 {
310 out.leader_epoch = get_i32(buf)?;
311 }
312 if version >= 0 {
313 out.isr = {
314 let n = crate::primitives::array::get_array_len(buf, flex)?;
315 let mut v = Vec::with_capacity(n);
316 for _ in 0..n {
317 v.push(get_i32(buf)?);
318 }
319 v
320 };
321 }
322 if version >= 1 {
323 out.leader_recovery_state = get_i8(buf)?;
324 }
325 if version >= 0 {
326 out.partition_epoch = get_i32(buf)?;
327 }
328 if flex {
329 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
330 }
331 Ok(out)
332 }
333}
334#[cfg(test)]
335impl PartitionData {
336 #[must_use]
337 pub fn populated(version: i16) -> Self {
338 let mut m = Self::default();
339 if version >= 0 {
340 m.partition_index = 1i32;
341 }
342 if version >= 0 {
343 m.error_code = 1i16;
344 }
345 if version >= 0 {
346 m.leader_id = 1i32;
347 }
348 if version >= 0 {
349 m.leader_epoch = 1i32;
350 }
351 if version >= 0 {
352 m.isr = vec![1i32];
353 }
354 if version >= 1 {
355 m.leader_recovery_state = 1i8;
356 }
357 if version >= 0 {
358 m.partition_epoch = 1i32;
359 }
360 m
361 }
362}
363
364#[must_use]
367#[allow(unused_comparisons)]
368pub fn default_json(version: i16) -> ::serde_json::Value {
369 let mut obj = ::serde_json::Map::new();
370 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
371 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
372 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
373 ::serde_json::Value::Object(obj)
374}