Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeShareGroupOffsetsResponse.borrowed.rs

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