Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i32, put_i32};
3use crate::primitives::string_bytes::{
4    compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10pub const API_KEY: i16 = 46;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct ListPartitionReassignmentsRequest<'a> {
20    pub timeout_ms: i32,
21    pub topics: Option<Vec<ListPartitionReassignmentsTopics<'a>>>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Default for ListPartitionReassignmentsRequest<'_> {
25    fn default() -> Self {
26        Self {
27            timeout_ms: 60_000i32,
28            topics: None,
29            unknown_tagged_fields: Default::default(),
30        }
31    }
32}
33impl ListPartitionReassignmentsRequest<'_> {
34    pub fn to_owned(
35        &self,
36    ) -> crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsRequest {
37        crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsRequest {
38            timeout_ms: (self.timeout_ms),
39            topics: (self.topics).as_ref().map(|v| {
40                v.iter()
41                    .map(ListPartitionReassignmentsTopics::to_owned)
42                    .collect()
43            }),
44            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45        }
46    }
47}
48impl Encode for ListPartitionReassignmentsRequest<'_> {
49    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51            return Err(ProtocolError::UnsupportedVersion {
52                api_key: API_KEY,
53                version,
54            });
55        }
56        let flex = is_flexible(version);
57        if version >= 0 {
58            put_i32(buf, self.timeout_ms);
59        }
60        if version >= 0 {
61            {
62                let len = (self.topics).as_ref().map(Vec::len);
63                crate::primitives::array::put_nullable_array_len(buf, len, flex);
64                if let Some(v) = &self.topics {
65                    for it in v {
66                        it.encode(buf, version)?;
67                    }
68                }
69            }
70        }
71        if flex {
72            let tagged = WriteTaggedFields::new();
73            tagged.write(buf, &self.unknown_tagged_fields);
74        }
75        Ok(())
76    }
77    fn encoded_len(&self, version: i16) -> usize {
78        let flex = is_flexible(version);
79        let mut n: usize = 0;
80        if version >= 0 {
81            n += 4;
82        }
83        if version >= 0 {
84            n += {
85                let opt: Option<&Vec<_>> = (self.topics).as_ref();
86                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
87                    opt.map(std::vec::Vec::len),
88                    flex,
89                );
90                let body: usize =
91                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
92                prefix + body
93            };
94        }
95        if flex {
96            let known_pairs: Vec<(u32, usize)> = Vec::new();
97            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
98        }
99        n
100    }
101}
102impl<'de> DecodeBorrow<'de> for ListPartitionReassignmentsRequest<'de> {
103    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
104        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
105            return Err(ProtocolError::UnsupportedVersion {
106                api_key: API_KEY,
107                version,
108            });
109        }
110        let flex = is_flexible(version);
111        let mut out = Self::default();
112        if version >= 0 {
113            out.timeout_ms = get_i32(buf)?;
114        }
115        if version >= 0 {
116            out.topics = {
117                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
118                match opt {
119                    None => None,
120                    Some(n) => {
121                        let mut v = Vec::with_capacity(n);
122                        for _ in 0..n {
123                            v.push(ListPartitionReassignmentsTopics::decode_borrow(
124                                buf, version,
125                            )?);
126                        }
127                        Some(v)
128                    }
129                }
130            };
131        }
132        if flex {
133            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
134        }
135        Ok(out)
136    }
137}
138#[cfg(test)]
139impl ListPartitionReassignmentsRequest<'_> {
140    #[must_use]
141    pub fn populated(version: i16) -> Self {
142        let mut m = Self::default();
143        if version >= 0 {
144            m.timeout_ms = 1i32;
145        }
146        if version >= 0 {
147            m.topics = Some(vec![ListPartitionReassignmentsTopics::populated(version)]);
148        }
149        m
150    }
151}
152#[derive(Debug, Clone, PartialEq, Eq, Default)]
153pub struct ListPartitionReassignmentsTopics<'a> {
154    pub name: &'a str,
155    pub partition_indexes: Vec<i32>,
156    pub unknown_tagged_fields: UnknownTaggedFields,
157}
158impl ListPartitionReassignmentsTopics<'_> {
159    pub fn to_owned(
160        &self,
161    ) -> crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsTopics {
162        crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsTopics {
163            name: (self.name).to_string(),
164            partition_indexes: (self.partition_indexes).clone(),
165            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
166        }
167    }
168}
169impl Encode for ListPartitionReassignmentsTopics<'_> {
170    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
171        let flex = version >= 0;
172        if version >= 0 {
173            if flex {
174                put_compact_string(buf, self.name);
175            } else {
176                put_string(buf, self.name);
177            }
178        }
179        if version >= 0 {
180            {
181                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
182                for it in &self.partition_indexes {
183                    put_i32(buf, *it);
184                }
185            }
186        }
187        if flex {
188            let tagged = WriteTaggedFields::new();
189            tagged.write(buf, &self.unknown_tagged_fields);
190        }
191        Ok(())
192    }
193    fn encoded_len(&self, version: i16) -> usize {
194        let flex = version >= 0;
195        let mut n: usize = 0;
196        if version >= 0 {
197            n += if flex {
198                compact_string_len(self.name)
199            } else {
200                string_len(self.name)
201            };
202        }
203        if version >= 0 {
204            n += {
205                let prefix = crate::primitives::array::array_len_prefix_len(
206                    (self.partition_indexes).len(),
207                    flex,
208                );
209                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
210                prefix + body
211            };
212        }
213        if flex {
214            let known_pairs: Vec<(u32, usize)> = Vec::new();
215            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
216        }
217        n
218    }
219}
220impl<'de> DecodeBorrow<'de> for ListPartitionReassignmentsTopics<'de> {
221    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
222        let flex = version >= 0;
223        let mut out = Self::default();
224        if version >= 0 {
225            out.name = if flex {
226                get_compact_string_borrowed(buf)?
227            } else {
228                get_string_borrowed(buf)?
229            };
230        }
231        if version >= 0 {
232            out.partition_indexes = {
233                let n = crate::primitives::array::get_array_len(buf, flex)?;
234                let mut v = Vec::with_capacity(n);
235                for _ in 0..n {
236                    v.push(get_i32(buf)?);
237                }
238                v
239            };
240        }
241        if flex {
242            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
243        }
244        Ok(out)
245    }
246}
247#[cfg(test)]
248impl ListPartitionReassignmentsTopics<'_> {
249    #[must_use]
250    pub fn populated(version: i16) -> Self {
251        let mut m = Self::default();
252        if version >= 0 {
253            m.name = "x";
254        }
255        if version >= 0 {
256            m.partition_indexes = vec![1i32];
257        }
258        m
259    }
260}