Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeShareGroupOffsetsRequest.owned.rs

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