Skip to main content

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