Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeShareGroupOffsetsResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 90;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25    version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DescribeShareGroupOffsetsResponse {
29    pub throttle_time_ms: i32,
30    pub groups: Vec<DescribeShareGroupOffsetsResponseGroup>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DescribeShareGroupOffsetsResponse {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion {
37                api_key: API_KEY,
38                version,
39            });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            put_i32(buf, self.throttle_time_ms);
44        }
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 += 4;
64        }
65        if version >= 0 {
66            n += {
67                let prefix =
68                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
69                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
70                prefix + body
71            };
72        }
73        if flex {
74            let known_pairs: Vec<(u32, usize)> = Vec::new();
75            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76        }
77        n
78    }
79}
80impl Decode<'_> for DescribeShareGroupOffsetsResponse {
81    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion {
84                api_key: API_KEY,
85                version,
86            });
87        }
88        let flex = is_flexible(version);
89        let mut out = Self::default();
90        if version >= 0 {
91            out.throttle_time_ms = get_i32(buf)?;
92        }
93        if version >= 0 {
94            out.groups = {
95                let n = crate::primitives::array::get_array_len(buf, flex)?;
96                let mut v = Vec::with_capacity(n);
97                for _ in 0..n {
98                    v.push(DescribeShareGroupOffsetsResponseGroup::decode(
99                        buf, version,
100                    )?);
101                }
102                v
103            };
104        }
105        if flex {
106            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
107        }
108        Ok(out)
109    }
110}
111#[cfg(test)]
112impl DescribeShareGroupOffsetsResponse {
113    #[must_use]
114    pub fn populated(version: i16) -> Self {
115        let mut m = Self::default();
116        if version >= 0 {
117            m.throttle_time_ms = 1i32;
118        }
119        if version >= 0 {
120            m.groups = vec![DescribeShareGroupOffsetsResponseGroup::populated(version)];
121        }
122        m
123    }
124}
125#[derive(Debug, Clone, PartialEq, Eq, Default)]
126pub struct DescribeShareGroupOffsetsResponseGroup {
127    pub group_id: String,
128    pub topics: Vec<DescribeShareGroupOffsetsResponseTopic>,
129    pub error_code: i16,
130    pub error_message: Option<String>,
131    pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Encode for DescribeShareGroupOffsetsResponseGroup {
134    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
135        let flex = version >= 0;
136        if version >= 0 {
137            if flex {
138                let () = put_compact_string(buf, &self.group_id);
139            } else {
140                let () = put_string(buf, &self.group_id);
141            }
142        }
143        if version >= 0 {
144            {
145                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
146                for it in &self.topics {
147                    it.encode(buf, version)?;
148                }
149            };
150        }
151        if version >= 0 {
152            put_i16(buf, self.error_code);
153        }
154        if version >= 0 {
155            if flex {
156                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
157            } else {
158                let () = put_nullable_string(buf, self.error_message.as_deref());
159            }
160        }
161        if flex {
162            let tagged = WriteTaggedFields::new();
163            tagged.write(buf, &self.unknown_tagged_fields);
164        }
165        Ok(())
166    }
167    fn encoded_len(&self, version: i16) -> usize {
168        let flex = version >= 0;
169        let mut n: usize = 0;
170        if version >= 0 {
171            n += if flex {
172                compact_string_len(&self.group_id)
173            } else {
174                string_len(&self.group_id)
175            };
176        }
177        if version >= 0 {
178            n += {
179                let prefix =
180                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
181                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
182                prefix + body
183            };
184        }
185        if version >= 0 {
186            n += 2;
187        }
188        if version >= 0 {
189            n += if flex {
190                compact_nullable_string_len(self.error_message.as_deref())
191            } else {
192                nullable_string_len(self.error_message.as_deref())
193            };
194        }
195        if flex {
196            let known_pairs: Vec<(u32, usize)> = Vec::new();
197            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
198        }
199        n
200    }
201}
202impl Decode<'_> for DescribeShareGroupOffsetsResponseGroup {
203    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
204        let flex = version >= 0;
205        let mut out = Self::default();
206        if version >= 0 {
207            out.group_id = if flex {
208                get_compact_string_owned(buf)?
209            } else {
210                get_string_owned(buf)?
211            };
212        }
213        if version >= 0 {
214            out.topics = {
215                let n = crate::primitives::array::get_array_len(buf, flex)?;
216                let mut v = Vec::with_capacity(n);
217                for _ in 0..n {
218                    v.push(DescribeShareGroupOffsetsResponseTopic::decode(
219                        buf, version,
220                    )?);
221                }
222                v
223            };
224        }
225        if version >= 0 {
226            out.error_code = get_i16(buf)?;
227        }
228        if version >= 0 {
229            out.error_message = if flex {
230                get_compact_nullable_string_owned(buf)?
231            } else {
232                get_nullable_string_owned(buf)?
233            };
234        }
235        if flex {
236            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
237        }
238        Ok(out)
239    }
240}
241#[cfg(test)]
242impl DescribeShareGroupOffsetsResponseGroup {
243    #[must_use]
244    pub fn populated(version: i16) -> Self {
245        let mut m = Self::default();
246        if version >= 0 {
247            m.group_id = "x".to_string();
248        }
249        if version >= 0 {
250            m.topics = vec![DescribeShareGroupOffsetsResponseTopic::populated(version)];
251        }
252        if version >= 0 {
253            m.error_code = 1i16;
254        }
255        if version >= 0 {
256            m.error_message = Some("x".to_string());
257        }
258        m
259    }
260}
261#[derive(Debug, Clone, PartialEq, Eq, Default)]
262pub struct DescribeShareGroupOffsetsResponseTopic {
263    pub topic_name: String,
264    pub topic_id: crate::primitives::uuid::Uuid,
265    pub partitions: Vec<DescribeShareGroupOffsetsResponsePartition>,
266    pub unknown_tagged_fields: UnknownTaggedFields,
267}
268impl Encode for DescribeShareGroupOffsetsResponseTopic {
269    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
270        let flex = version >= 0;
271        if version >= 0 {
272            if flex {
273                let () = put_compact_string(buf, &self.topic_name);
274            } else {
275                let () = put_string(buf, &self.topic_name);
276            }
277        }
278        if version >= 0 {
279            crate::primitives::uuid::put_uuid(buf, self.topic_id);
280        }
281        if version >= 0 {
282            {
283                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
284                for it in &self.partitions {
285                    it.encode(buf, version)?;
286                }
287            };
288        }
289        if flex {
290            let tagged = WriteTaggedFields::new();
291            tagged.write(buf, &self.unknown_tagged_fields);
292        }
293        Ok(())
294    }
295    fn encoded_len(&self, version: i16) -> usize {
296        let flex = version >= 0;
297        let mut n: usize = 0;
298        if version >= 0 {
299            n += if flex {
300                compact_string_len(&self.topic_name)
301            } else {
302                string_len(&self.topic_name)
303            };
304        }
305        if version >= 0 {
306            n += 16;
307        }
308        if version >= 0 {
309            n += {
310                let prefix =
311                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
312                let body: usize = (self.partitions)
313                    .iter()
314                    .map(|it| it.encoded_len(version))
315                    .sum();
316                prefix + body
317            };
318        }
319        if flex {
320            let known_pairs: Vec<(u32, usize)> = Vec::new();
321            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
322        }
323        n
324    }
325}
326impl Decode<'_> for DescribeShareGroupOffsetsResponseTopic {
327    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
328        let flex = version >= 0;
329        let mut out = Self::default();
330        if version >= 0 {
331            out.topic_name = if flex {
332                get_compact_string_owned(buf)?
333            } else {
334                get_string_owned(buf)?
335            };
336        }
337        if version >= 0 {
338            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
339        }
340        if version >= 0 {
341            out.partitions = {
342                let n = crate::primitives::array::get_array_len(buf, flex)?;
343                let mut v = Vec::with_capacity(n);
344                for _ in 0..n {
345                    v.push(DescribeShareGroupOffsetsResponsePartition::decode(
346                        buf, version,
347                    )?);
348                }
349                v
350            };
351        }
352        if flex {
353            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
354        }
355        Ok(out)
356    }
357}
358#[cfg(test)]
359impl DescribeShareGroupOffsetsResponseTopic {
360    #[must_use]
361    pub fn populated(version: i16) -> Self {
362        let mut m = Self::default();
363        if version >= 0 {
364            m.topic_name = "x".to_string();
365        }
366        if version >= 0 {
367            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
368        }
369        if version >= 0 {
370            m.partitions = vec![DescribeShareGroupOffsetsResponsePartition::populated(
371                version,
372            )];
373        }
374        m
375    }
376}
377#[derive(Debug, Clone, PartialEq, Eq)]
378pub struct DescribeShareGroupOffsetsResponsePartition {
379    pub partition_index: i32,
380    pub start_offset: i64,
381    pub leader_epoch: i32,
382    pub lag: i64,
383    pub error_code: i16,
384    pub error_message: Option<String>,
385    pub unknown_tagged_fields: UnknownTaggedFields,
386}
387impl Default for DescribeShareGroupOffsetsResponsePartition {
388    fn default() -> Self {
389        Self {
390            partition_index: 0i32,
391            start_offset: 0i64,
392            leader_epoch: 0i32,
393            lag: -1i64,
394            error_code: 0i16,
395            error_message: None,
396            unknown_tagged_fields: UnknownTaggedFields::default(),
397        }
398    }
399}
400impl Encode for DescribeShareGroupOffsetsResponsePartition {
401    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
402        let flex = version >= 0;
403        if version >= 0 {
404            put_i32(buf, self.partition_index);
405        }
406        if version >= 0 {
407            put_i64(buf, self.start_offset);
408        }
409        if version >= 0 {
410            put_i32(buf, self.leader_epoch);
411        }
412        if version >= 1 {
413            put_i64(buf, self.lag);
414        }
415        if version >= 0 {
416            put_i16(buf, self.error_code);
417        }
418        if version >= 0 {
419            if flex {
420                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
421            } else {
422                let () = put_nullable_string(buf, self.error_message.as_deref());
423            }
424        }
425        if flex {
426            let tagged = WriteTaggedFields::new();
427            tagged.write(buf, &self.unknown_tagged_fields);
428        }
429        Ok(())
430    }
431    fn encoded_len(&self, version: i16) -> usize {
432        let flex = version >= 0;
433        let mut n: usize = 0;
434        if version >= 0 {
435            n += 4;
436        }
437        if version >= 0 {
438            n += 8;
439        }
440        if version >= 0 {
441            n += 4;
442        }
443        if version >= 1 {
444            n += 8;
445        }
446        if version >= 0 {
447            n += 2;
448        }
449        if version >= 0 {
450            n += if flex {
451                compact_nullable_string_len(self.error_message.as_deref())
452            } else {
453                nullable_string_len(self.error_message.as_deref())
454            };
455        }
456        if flex {
457            let known_pairs: Vec<(u32, usize)> = Vec::new();
458            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
459        }
460        n
461    }
462}
463impl Decode<'_> for DescribeShareGroupOffsetsResponsePartition {
464    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
465        let flex = version >= 0;
466        let mut out = Self::default();
467        if version >= 0 {
468            out.partition_index = get_i32(buf)?;
469        }
470        if version >= 0 {
471            out.start_offset = get_i64(buf)?;
472        }
473        if version >= 0 {
474            out.leader_epoch = get_i32(buf)?;
475        }
476        if version >= 1 {
477            out.lag = get_i64(buf)?;
478        }
479        if version >= 0 {
480            out.error_code = get_i16(buf)?;
481        }
482        if version >= 0 {
483            out.error_message = if flex {
484                get_compact_nullable_string_owned(buf)?
485            } else {
486                get_nullable_string_owned(buf)?
487            };
488        }
489        if flex {
490            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
491        }
492        Ok(out)
493    }
494}
495#[cfg(test)]
496impl DescribeShareGroupOffsetsResponsePartition {
497    #[must_use]
498    pub fn populated(version: i16) -> Self {
499        let mut m = Self::default();
500        if version >= 0 {
501            m.partition_index = 1i32;
502        }
503        if version >= 0 {
504            m.start_offset = 1i64;
505        }
506        if version >= 0 {
507            m.leader_epoch = 1i32;
508        }
509        if version >= 1 {
510            m.lag = 1i64;
511        }
512        if version >= 0 {
513            m.error_code = 1i16;
514        }
515        if version >= 0 {
516            m.error_message = Some("x".to_string());
517        }
518        m
519    }
520}
521/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
522/// Only includes fields valid for the given version.
523#[must_use]
524#[allow(unused_comparisons)]
525pub fn default_json(_version: i16) -> ::serde_json::Value {
526    let mut obj = ::serde_json::Map::new();
527    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
528    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
529    ::serde_json::Value::Object(obj)
530}