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