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