Skip to main content

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

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