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