Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeShareGroupOffsetsRequest.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 = 90;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 1;
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, Default)]
19pub struct DescribeShareGroupOffsetsRequest<'a> {
20    pub groups: Vec<DescribeShareGroupOffsetsRequestGroup<'a>>,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl DescribeShareGroupOffsetsRequest<'_> {
24    pub fn to_owned(
25        &self,
26    ) -> crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequest {
27        crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequest {
28            groups: (self.groups)
29                .iter()
30                .map(DescribeShareGroupOffsetsRequestGroup::to_owned)
31                .collect(),
32            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
33        }
34    }
35}
36impl Encode for DescribeShareGroupOffsetsRequest<'_> {
37    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39            return Err(ProtocolError::UnsupportedVersion {
40                api_key: API_KEY,
41                version,
42            });
43        }
44        let flex = is_flexible(version);
45        if version >= 0 {
46            {
47                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
48                for it in &self.groups {
49                    it.encode(buf, version)?;
50                }
51            }
52        }
53        if flex {
54            let tagged = WriteTaggedFields::new();
55            tagged.write(buf, &self.unknown_tagged_fields);
56        }
57        Ok(())
58    }
59    fn encoded_len(&self, version: i16) -> usize {
60        let flex = is_flexible(version);
61        let mut n: usize = 0;
62        if version >= 0 {
63            n += {
64                let prefix =
65                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
66                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
67                prefix + body
68            };
69        }
70        if flex {
71            let known_pairs: Vec<(u32, usize)> = Vec::new();
72            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73        }
74        n
75    }
76}
77impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsRequest<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion {
81                api_key: API_KEY,
82                version,
83            });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 {
88            out.groups = {
89                let n = crate::primitives::array::get_array_len(buf, flex)?;
90                let mut v = Vec::with_capacity(n);
91                for _ in 0..n {
92                    v.push(DescribeShareGroupOffsetsRequestGroup::decode_borrow(
93                        buf, version,
94                    )?);
95                }
96                v
97            };
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl DescribeShareGroupOffsetsRequest<'_> {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.groups = vec![DescribeShareGroupOffsetsRequestGroup::populated(version)];
112        }
113        m
114    }
115}
116#[derive(Debug, Clone, PartialEq, Eq, Default)]
117pub struct DescribeShareGroupOffsetsRequestGroup<'a> {
118    pub group_id: &'a str,
119    pub topics: Option<Vec<DescribeShareGroupOffsetsRequestTopic<'a>>>,
120    pub unknown_tagged_fields: UnknownTaggedFields,
121}
122impl DescribeShareGroupOffsetsRequestGroup<'_> {
123    pub fn to_owned(
124        &self,
125    ) -> crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequestGroup
126    {
127        crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequestGroup {
128            group_id: (self.group_id).to_string(),
129            topics: (self.topics).as_ref().map(|v| {
130                v.iter()
131                    .map(DescribeShareGroupOffsetsRequestTopic::to_owned)
132                    .collect()
133            }),
134            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
135        }
136    }
137}
138impl Encode for DescribeShareGroupOffsetsRequestGroup<'_> {
139    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
140        let flex = version >= 0;
141        if version >= 0 {
142            if flex {
143                put_compact_string(buf, self.group_id);
144            } else {
145                put_string(buf, self.group_id);
146            }
147        }
148        if version >= 0 {
149            {
150                let len = (self.topics).as_ref().map(Vec::len);
151                crate::primitives::array::put_nullable_array_len(buf, len, flex);
152                if let Some(v) = &self.topics {
153                    for it in v {
154                        it.encode(buf, version)?;
155                    }
156                }
157            }
158        }
159        if flex {
160            let tagged = WriteTaggedFields::new();
161            tagged.write(buf, &self.unknown_tagged_fields);
162        }
163        Ok(())
164    }
165    fn encoded_len(&self, version: i16) -> usize {
166        let flex = version >= 0;
167        let mut n: usize = 0;
168        if version >= 0 {
169            n += if flex {
170                compact_string_len(self.group_id)
171            } else {
172                string_len(self.group_id)
173            };
174        }
175        if version >= 0 {
176            n += {
177                let opt: Option<&Vec<_>> = (self.topics).as_ref();
178                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
179                    opt.map(std::vec::Vec::len),
180                    flex,
181                );
182                let body: usize =
183                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
184                prefix + body
185            };
186        }
187        if flex {
188            let known_pairs: Vec<(u32, usize)> = Vec::new();
189            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
190        }
191        n
192    }
193}
194impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsRequestGroup<'de> {
195    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
196        let flex = version >= 0;
197        let mut out = Self::default();
198        if version >= 0 {
199            out.group_id = if flex {
200                get_compact_string_borrowed(buf)?
201            } else {
202                get_string_borrowed(buf)?
203            };
204        }
205        if version >= 0 {
206            out.topics = {
207                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
208                match opt {
209                    None => None,
210                    Some(n) => {
211                        let mut v = Vec::with_capacity(n);
212                        for _ in 0..n {
213                            v.push(DescribeShareGroupOffsetsRequestTopic::decode_borrow(
214                                buf, version,
215                            )?);
216                        }
217                        Some(v)
218                    }
219                }
220            };
221        }
222        if flex {
223            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
224        }
225        Ok(out)
226    }
227}
228#[cfg(test)]
229impl DescribeShareGroupOffsetsRequestGroup<'_> {
230    #[must_use]
231    pub fn populated(version: i16) -> Self {
232        let mut m = Self::default();
233        if version >= 0 {
234            m.group_id = "x";
235        }
236        if version >= 0 {
237            m.topics = Some(vec![DescribeShareGroupOffsetsRequestTopic::populated(
238                version,
239            )]);
240        }
241        m
242    }
243}
244#[derive(Debug, Clone, PartialEq, Eq, Default)]
245pub struct DescribeShareGroupOffsetsRequestTopic<'a> {
246    pub topic_name: &'a str,
247    pub partitions: Vec<i32>,
248    pub unknown_tagged_fields: UnknownTaggedFields,
249}
250impl DescribeShareGroupOffsetsRequestTopic<'_> {
251    pub fn to_owned(
252        &self,
253    ) -> crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequestTopic
254    {
255        crate::owned::describe_share_group_offsets_request::DescribeShareGroupOffsetsRequestTopic {
256            topic_name: (self.topic_name).to_string(),
257            partitions: (self.partitions).clone(),
258            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
259        }
260    }
261}
262impl Encode for DescribeShareGroupOffsetsRequestTopic<'_> {
263    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
264        let flex = version >= 0;
265        if version >= 0 {
266            if flex {
267                put_compact_string(buf, self.topic_name);
268            } else {
269                put_string(buf, self.topic_name);
270            }
271        }
272        if version >= 0 {
273            {
274                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
275                for it in &self.partitions {
276                    put_i32(buf, *it);
277                }
278            }
279        }
280        if flex {
281            let tagged = WriteTaggedFields::new();
282            tagged.write(buf, &self.unknown_tagged_fields);
283        }
284        Ok(())
285    }
286    fn encoded_len(&self, version: i16) -> usize {
287        let flex = version >= 0;
288        let mut n: usize = 0;
289        if version >= 0 {
290            n += if flex {
291                compact_string_len(self.topic_name)
292            } else {
293                string_len(self.topic_name)
294            };
295        }
296        if version >= 0 {
297            n += {
298                let prefix =
299                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
300                let body: usize = (self.partitions).iter().map(|_| 4).sum();
301                prefix + body
302            };
303        }
304        if flex {
305            let known_pairs: Vec<(u32, usize)> = Vec::new();
306            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
307        }
308        n
309    }
310}
311impl<'de> DecodeBorrow<'de> for DescribeShareGroupOffsetsRequestTopic<'de> {
312    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
313        let flex = version >= 0;
314        let mut out = Self::default();
315        if version >= 0 {
316            out.topic_name = if flex {
317                get_compact_string_borrowed(buf)?
318            } else {
319                get_string_borrowed(buf)?
320            };
321        }
322        if version >= 0 {
323            out.partitions = {
324                let n = crate::primitives::array::get_array_len(buf, flex)?;
325                let mut v = Vec::with_capacity(n);
326                for _ in 0..n {
327                    v.push(get_i32(buf)?);
328                }
329                v
330            };
331        }
332        if flex {
333            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
334        }
335        Ok(out)
336    }
337}
338#[cfg(test)]
339impl DescribeShareGroupOffsetsRequestTopic<'_> {
340    #[must_use]
341    pub fn populated(version: i16) -> Self {
342        let mut m = Self::default();
343        if version >= 0 {
344            m.topic_name = "x";
345        }
346        if version >= 0 {
347            m.partitions = vec![1i32];
348        }
349        m
350    }
351}