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