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