Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsResponse.borrowed.rs

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