Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupDescribeResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 69;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 1;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct ConsumerGroupDescribeResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub groups: Vec<DescribedGroup<'a>>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl ConsumerGroupDescribeResponse<'_> {
36    /// # Panics
37    ///
38    /// Panics if a records field contains an invalid encoded record batch.
39    #[must_use]
40    pub fn to_owned(
41        &self,
42    ) -> crate::owned::consumer_group_describe_response::ConsumerGroupDescribeResponse {
43        crate::owned::consumer_group_describe_response::ConsumerGroupDescribeResponse {
44            throttle_time_ms: (self.throttle_time_ms),
45            groups: (self.groups).iter().map(DescribedGroup::to_owned).collect(),
46            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
47        }
48    }
49}
50impl Encode for ConsumerGroupDescribeResponse<'_> {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion {
54                api_key: API_KEY,
55                version,
56            });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 {
60            put_i32(buf, self.throttle_time_ms);
61        }
62        if version >= 0 {
63            {
64                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
65                for it in &self.groups {
66                    it.encode(buf, version)?;
67                }
68            };
69        }
70        if flex {
71            let tagged = WriteTaggedFields::new();
72            tagged.write(buf, &self.unknown_tagged_fields);
73        }
74        Ok(())
75    }
76    fn encoded_len(&self, version: i16) -> usize {
77        let flex = is_flexible(version);
78        let mut n: usize = 0;
79        if version >= 0 {
80            n += 4;
81        }
82        if version >= 0 {
83            n += {
84                let prefix =
85                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
86                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
87                prefix + body
88            };
89        }
90        if flex {
91            let known_pairs: Vec<(u32, usize)> = Vec::new();
92            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
93        }
94        n
95    }
96}
97impl<'de> DecodeBorrow<'de> for ConsumerGroupDescribeResponse<'de> {
98    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
99        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
100            return Err(ProtocolError::UnsupportedVersion {
101                api_key: API_KEY,
102                version,
103            });
104        }
105        let flex = is_flexible(version);
106        let mut out = Self::default();
107        if version >= 0 {
108            out.throttle_time_ms = get_i32(buf)?;
109        }
110        if version >= 0 {
111            out.groups = {
112                let n = crate::primitives::array::get_array_len(buf, flex)?;
113                let mut v = Vec::with_capacity(n);
114                for _ in 0..n {
115                    v.push(DescribedGroup::decode_borrow(buf, version)?);
116                }
117                v
118            };
119        }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122        }
123        Ok(out)
124    }
125}
126#[cfg(test)]
127impl ConsumerGroupDescribeResponse<'_> {
128    #[must_use]
129    pub fn populated(version: i16) -> Self {
130        let mut m = Self::default();
131        if version >= 0 {
132            m.throttle_time_ms = 1i32;
133        }
134        if version >= 0 {
135            m.groups = vec![DescribedGroup::populated(version)];
136        }
137        m
138    }
139}
140#[derive(Debug, Clone, PartialEq, Eq)]
141pub struct DescribedGroup<'a> {
142    pub error_code: i16,
143    pub error_message: Option<&'a str>,
144    pub group_id: &'a str,
145    pub group_state: &'a str,
146    pub group_epoch: i32,
147    pub assignment_epoch: i32,
148    pub assignor_name: &'a str,
149    pub members: Vec<Member<'a>>,
150    pub authorized_operations: i32,
151    pub unknown_tagged_fields: UnknownTaggedFields,
152}
153impl Default for DescribedGroup<'_> {
154    fn default() -> Self {
155        Self {
156            error_code: 0i16,
157            error_message: None,
158            group_id: "",
159            group_state: "",
160            group_epoch: 0i32,
161            assignment_epoch: 0i32,
162            assignor_name: "",
163            members: Vec::new(),
164            authorized_operations: -2_147_483_648i32,
165            unknown_tagged_fields: UnknownTaggedFields::default(),
166        }
167    }
168}
169impl<'a> DescribedGroup<'a> {
170    /// # Panics
171    ///
172    /// Panics if a records field contains an invalid encoded record batch.
173    #[must_use]
174    pub fn to_owned(&self) -> crate::owned::consumer_group_describe_response::DescribedGroup {
175        crate::owned::consumer_group_describe_response::DescribedGroup {
176            error_code: (self.error_code),
177            error_message: (self.error_message).map(std::string::ToString::to_string),
178            group_id: (self.group_id).to_string(),
179            group_state: (self.group_state).to_string(),
180            group_epoch: (self.group_epoch),
181            assignment_epoch: (self.assignment_epoch),
182            assignor_name: (self.assignor_name).to_string(),
183            members: (self.members).iter().map(Member::to_owned).collect(),
184            authorized_operations: (self.authorized_operations),
185            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
186        }
187    }
188    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
189        if version >= 0 {
190            put_i16(buf, self.error_code);
191        }
192    }
193    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
194        if version >= 0 {
195            if flex {
196                let () = put_compact_nullable_string(buf, self.error_message);
197            } else {
198                let () = put_nullable_string(buf, self.error_message);
199            }
200        }
201    }
202    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
203        if version >= 0 {
204            if flex {
205                let () = put_compact_string(buf, self.group_id);
206            } else {
207                let () = put_string(buf, self.group_id);
208            }
209        }
210    }
211    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
212        if version >= 0 {
213            if flex {
214                let () = put_compact_string(buf, self.group_state);
215            } else {
216                let () = put_string(buf, self.group_state);
217            }
218        }
219    }
220    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
221        if version >= 0 {
222            put_i32(buf, self.group_epoch);
223        }
224    }
225    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
226        if version >= 0 {
227            put_i32(buf, self.assignment_epoch);
228        }
229    }
230    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
231        if version >= 0 {
232            if flex {
233                let () = put_compact_string(buf, self.assignor_name);
234            } else {
235                let () = put_string(buf, self.assignor_name);
236            }
237        }
238    }
239    fn encode_field_7<B: BufMut>(
240        &self,
241        buf: &mut B,
242        version: i16,
243        flex: bool,
244    ) -> Result<(), ProtocolError> {
245        if version >= 0 {
246            {
247                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
248                for it in &self.members {
249                    it.encode(buf, version)?;
250                }
251            };
252        }
253        Ok(())
254    }
255    fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
256        if version >= 0 {
257            put_i32(buf, self.authorized_operations);
258        }
259    }
260    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
261        if flex {
262            let tagged = WriteTaggedFields::new();
263            tagged.write(buf, &self.unknown_tagged_fields);
264        }
265    }
266    fn decode_field_0(
267        out: &mut Self,
268        buf: &mut &'a [u8],
269        version: i16,
270        _flex: bool,
271    ) -> Result<(), ProtocolError> {
272        if version >= 0 {
273            out.error_code = get_i16(buf)?;
274        }
275        Ok(())
276    }
277    fn decode_field_1(
278        out: &mut Self,
279        buf: &mut &'a [u8],
280        version: i16,
281        flex: bool,
282    ) -> Result<(), ProtocolError> {
283        if version >= 0 {
284            out.error_message = if flex {
285                get_compact_nullable_string_borrowed(buf)?
286            } else {
287                get_nullable_string_borrowed(buf)?
288            };
289        }
290        Ok(())
291    }
292    fn decode_field_2(
293        out: &mut Self,
294        buf: &mut &'a [u8],
295        version: i16,
296        flex: bool,
297    ) -> Result<(), ProtocolError> {
298        if version >= 0 {
299            out.group_id = if flex {
300                get_compact_string_borrowed(buf)?
301            } else {
302                get_string_borrowed(buf)?
303            };
304        }
305        Ok(())
306    }
307    fn decode_field_3(
308        out: &mut Self,
309        buf: &mut &'a [u8],
310        version: i16,
311        flex: bool,
312    ) -> Result<(), ProtocolError> {
313        if version >= 0 {
314            out.group_state = if flex {
315                get_compact_string_borrowed(buf)?
316            } else {
317                get_string_borrowed(buf)?
318            };
319        }
320        Ok(())
321    }
322    fn decode_field_4(
323        out: &mut Self,
324        buf: &mut &'a [u8],
325        version: i16,
326        _flex: bool,
327    ) -> Result<(), ProtocolError> {
328        if version >= 0 {
329            out.group_epoch = get_i32(buf)?;
330        }
331        Ok(())
332    }
333    fn decode_field_5(
334        out: &mut Self,
335        buf: &mut &'a [u8],
336        version: i16,
337        _flex: bool,
338    ) -> Result<(), ProtocolError> {
339        if version >= 0 {
340            out.assignment_epoch = get_i32(buf)?;
341        }
342        Ok(())
343    }
344    fn decode_field_6(
345        out: &mut Self,
346        buf: &mut &'a [u8],
347        version: i16,
348        flex: bool,
349    ) -> Result<(), ProtocolError> {
350        if version >= 0 {
351            out.assignor_name = if flex {
352                get_compact_string_borrowed(buf)?
353            } else {
354                get_string_borrowed(buf)?
355            };
356        }
357        Ok(())
358    }
359    fn decode_field_7(
360        out: &mut Self,
361        buf: &mut &'a [u8],
362        version: i16,
363        flex: bool,
364    ) -> Result<(), ProtocolError> {
365        if version >= 0 {
366            out.members = {
367                let n = crate::primitives::array::get_array_len(buf, flex)?;
368                let mut v = Vec::with_capacity(n);
369                for _ in 0..n {
370                    v.push(Member::decode_borrow(buf, version)?);
371                }
372                v
373            };
374        }
375        Ok(())
376    }
377    fn decode_field_8(
378        out: &mut Self,
379        buf: &mut &'a [u8],
380        version: i16,
381        _flex: bool,
382    ) -> Result<(), ProtocolError> {
383        if version >= 0 {
384            out.authorized_operations = get_i32(buf)?;
385        }
386        Ok(())
387    }
388    fn decode_tagged_fields(
389        out: &mut Self,
390        buf: &mut &'a [u8],
391        _version: i16,
392        flex: bool,
393    ) -> Result<(), ProtocolError> {
394        if flex {
395            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
396        }
397        Ok(())
398    }
399}
400impl Encode for DescribedGroup<'_> {
401    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
402        let flex = version >= 0;
403        self.encode_field_0(buf, version, flex);
404        self.encode_field_1(buf, version, flex);
405        self.encode_field_2(buf, version, flex);
406        self.encode_field_3(buf, version, flex);
407        self.encode_field_4(buf, version, flex);
408        self.encode_field_5(buf, version, flex);
409        self.encode_field_6(buf, version, flex);
410        self.encode_field_7(buf, version, flex)?;
411        self.encode_field_8(buf, version, flex);
412        self.encode_tagged_fields(buf, version, flex);
413        Ok(())
414    }
415    fn encoded_len(&self, version: i16) -> usize {
416        let flex = version >= 0;
417        let mut n: usize = 0;
418        if version >= 0 {
419            n += 2;
420        }
421        if version >= 0 {
422            n += if flex {
423                compact_nullable_string_len(self.error_message)
424            } else {
425                nullable_string_len(self.error_message)
426            };
427        }
428        if version >= 0 {
429            n += if flex {
430                compact_string_len(self.group_id)
431            } else {
432                string_len(self.group_id)
433            };
434        }
435        if version >= 0 {
436            n += if flex {
437                compact_string_len(self.group_state)
438            } else {
439                string_len(self.group_state)
440            };
441        }
442        if version >= 0 {
443            n += 4;
444        }
445        if version >= 0 {
446            n += 4;
447        }
448        if version >= 0 {
449            n += if flex {
450                compact_string_len(self.assignor_name)
451            } else {
452                string_len(self.assignor_name)
453            };
454        }
455        if version >= 0 {
456            n += {
457                let prefix =
458                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
459                let body: usize = (self.members)
460                    .iter()
461                    .map(|it| it.encoded_len(version))
462                    .sum();
463                prefix + body
464            };
465        }
466        if version >= 0 {
467            n += 4;
468        }
469        if flex {
470            let known_pairs: Vec<(u32, usize)> = Vec::new();
471            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
472        }
473        n
474    }
475}
476impl<'de> DecodeBorrow<'de> for DescribedGroup<'de> {
477    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
478        let flex = version >= 0;
479        let mut out = Self::default();
480        Self::decode_field_0(&mut out, buf, version, flex)?;
481        Self::decode_field_1(&mut out, buf, version, flex)?;
482        Self::decode_field_2(&mut out, buf, version, flex)?;
483        Self::decode_field_3(&mut out, buf, version, flex)?;
484        Self::decode_field_4(&mut out, buf, version, flex)?;
485        Self::decode_field_5(&mut out, buf, version, flex)?;
486        Self::decode_field_6(&mut out, buf, version, flex)?;
487        Self::decode_field_7(&mut out, buf, version, flex)?;
488        Self::decode_field_8(&mut out, buf, version, flex)?;
489        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
490        Ok(out)
491    }
492}
493#[cfg(test)]
494impl DescribedGroup<'_> {
495    #[must_use]
496    pub fn populated(version: i16) -> Self {
497        let mut m = Self::default();
498        if version >= 0 {
499            m.error_code = 1i16;
500        }
501        if version >= 0 {
502            m.error_message = Some("x");
503        }
504        if version >= 0 {
505            m.group_id = "x";
506        }
507        if version >= 0 {
508            m.group_state = "x";
509        }
510        if version >= 0 {
511            m.group_epoch = 1i32;
512        }
513        if version >= 0 {
514            m.assignment_epoch = 1i32;
515        }
516        if version >= 0 {
517            m.assignor_name = "x";
518        }
519        if version >= 0 {
520            m.members = vec![Member::populated(version)];
521        }
522        if version >= 0 {
523            m.authorized_operations = 1i32;
524        }
525        m
526    }
527}
528#[derive(Debug, Clone, PartialEq, Eq)]
529pub struct Member<'a> {
530    pub member_id: &'a str,
531    pub instance_id: Option<&'a str>,
532    pub rack_id: Option<&'a str>,
533    pub member_epoch: i32,
534    pub client_id: &'a str,
535    pub client_host: &'a str,
536    pub subscribed_topic_names: Vec<&'a str>,
537    pub subscribed_topic_regex: Option<&'a str>,
538    pub assignment: super::common::consumer_group_describe_response::assignment::Assignment<'a>,
539    pub target_assignment:
540        super::common::consumer_group_describe_response::assignment::Assignment<'a>,
541    pub member_type: i8,
542    pub unknown_tagged_fields: UnknownTaggedFields,
543}
544impl<'a> Default for Member<'a> {
545    fn default() -> Self {
546        Self {
547            member_id: "",
548            instance_id: None,
549            rack_id: None,
550            member_epoch: 0i32,
551            client_id: "",
552            client_host: "",
553            subscribed_topic_names: Vec::new(),
554            subscribed_topic_regex: None,
555            assignment: <super::common::consumer_group_describe_response::assignment::Assignment<'a>>::default(),
556            target_assignment: <super::common::consumer_group_describe_response::assignment::Assignment<'a>>::default(),
557            member_type: -1i8,
558            unknown_tagged_fields: UnknownTaggedFields::default(),
559        }
560    }
561}
562impl<'a> Member<'a> {
563    /// # Panics
564    ///
565    /// Panics if a records field contains an invalid encoded record batch.
566    #[must_use]
567    pub fn to_owned(&self) -> crate::owned::consumer_group_describe_response::Member {
568        crate::owned::consumer_group_describe_response::Member {
569            member_id: (self.member_id).to_string(),
570            instance_id: (self.instance_id).map(std::string::ToString::to_string),
571            rack_id: (self.rack_id).map(std::string::ToString::to_string),
572            member_epoch: (self.member_epoch),
573            client_id: (self.client_id).to_string(),
574            client_host: (self.client_host).to_string(),
575            subscribed_topic_names: (self.subscribed_topic_names)
576                .iter()
577                .map(std::string::ToString::to_string)
578                .collect(),
579            subscribed_topic_regex: (self.subscribed_topic_regex)
580                .map(std::string::ToString::to_string),
581            assignment: (self.assignment).to_owned(),
582            target_assignment: (self.target_assignment).to_owned(),
583            member_type: (self.member_type),
584            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
585        }
586    }
587    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
588        if version >= 0 {
589            if flex {
590                let () = put_compact_string(buf, self.member_id);
591            } else {
592                let () = put_string(buf, self.member_id);
593            }
594        }
595    }
596    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
597        if version >= 0 {
598            if flex {
599                let () = put_compact_nullable_string(buf, self.instance_id);
600            } else {
601                let () = put_nullable_string(buf, self.instance_id);
602            }
603        }
604    }
605    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
606        if version >= 0 {
607            if flex {
608                let () = put_compact_nullable_string(buf, self.rack_id);
609            } else {
610                let () = put_nullable_string(buf, self.rack_id);
611            }
612        }
613    }
614    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
615        if version >= 0 {
616            put_i32(buf, self.member_epoch);
617        }
618    }
619    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
620        if version >= 0 {
621            if flex {
622                let () = put_compact_string(buf, self.client_id);
623            } else {
624                let () = put_string(buf, self.client_id);
625            }
626        }
627    }
628    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
629        if version >= 0 {
630            if flex {
631                let () = put_compact_string(buf, self.client_host);
632            } else {
633                let () = put_string(buf, self.client_host);
634            }
635        }
636    }
637    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
638        if version >= 0 {
639            {
640                crate::primitives::array::put_array_len(
641                    buf,
642                    (self.subscribed_topic_names).len(),
643                    flex,
644                );
645                for it in &self.subscribed_topic_names {
646                    if flex {
647                        let () = put_compact_string(buf, it);
648                    } else {
649                        let () = put_string(buf, it);
650                    }
651                }
652            };
653        }
654    }
655    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
656        if version >= 0 {
657            if flex {
658                let () = put_compact_nullable_string(buf, self.subscribed_topic_regex);
659            } else {
660                let () = put_nullable_string(buf, self.subscribed_topic_regex);
661            }
662        }
663    }
664    fn encode_field_8<B: BufMut>(
665        &self,
666        buf: &mut B,
667        version: i16,
668        _flex: bool,
669    ) -> Result<(), ProtocolError> {
670        if version >= 0 {
671            self.assignment.encode(buf, version)?;
672        }
673        Ok(())
674    }
675    fn encode_field_9<B: BufMut>(
676        &self,
677        buf: &mut B,
678        version: i16,
679        _flex: bool,
680    ) -> Result<(), ProtocolError> {
681        if version >= 0 {
682            self.target_assignment.encode(buf, version)?;
683        }
684        Ok(())
685    }
686    fn encode_field_10<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
687        if version >= 1 {
688            put_i8(buf, self.member_type);
689        }
690    }
691    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
692        if flex {
693            let tagged = WriteTaggedFields::new();
694            tagged.write(buf, &self.unknown_tagged_fields);
695        }
696    }
697    fn decode_field_0(
698        out: &mut Self,
699        buf: &mut &'a [u8],
700        version: i16,
701        flex: bool,
702    ) -> Result<(), ProtocolError> {
703        if version >= 0 {
704            out.member_id = if flex {
705                get_compact_string_borrowed(buf)?
706            } else {
707                get_string_borrowed(buf)?
708            };
709        }
710        Ok(())
711    }
712    fn decode_field_1(
713        out: &mut Self,
714        buf: &mut &'a [u8],
715        version: i16,
716        flex: bool,
717    ) -> Result<(), ProtocolError> {
718        if version >= 0 {
719            out.instance_id = if flex {
720                get_compact_nullable_string_borrowed(buf)?
721            } else {
722                get_nullable_string_borrowed(buf)?
723            };
724        }
725        Ok(())
726    }
727    fn decode_field_2(
728        out: &mut Self,
729        buf: &mut &'a [u8],
730        version: i16,
731        flex: bool,
732    ) -> Result<(), ProtocolError> {
733        if version >= 0 {
734            out.rack_id = if flex {
735                get_compact_nullable_string_borrowed(buf)?
736            } else {
737                get_nullable_string_borrowed(buf)?
738            };
739        }
740        Ok(())
741    }
742    fn decode_field_3(
743        out: &mut Self,
744        buf: &mut &'a [u8],
745        version: i16,
746        _flex: bool,
747    ) -> Result<(), ProtocolError> {
748        if version >= 0 {
749            out.member_epoch = get_i32(buf)?;
750        }
751        Ok(())
752    }
753    fn decode_field_4(
754        out: &mut Self,
755        buf: &mut &'a [u8],
756        version: i16,
757        flex: bool,
758    ) -> Result<(), ProtocolError> {
759        if version >= 0 {
760            out.client_id = if flex {
761                get_compact_string_borrowed(buf)?
762            } else {
763                get_string_borrowed(buf)?
764            };
765        }
766        Ok(())
767    }
768    fn decode_field_5(
769        out: &mut Self,
770        buf: &mut &'a [u8],
771        version: i16,
772        flex: bool,
773    ) -> Result<(), ProtocolError> {
774        if version >= 0 {
775            out.client_host = if flex {
776                get_compact_string_borrowed(buf)?
777            } else {
778                get_string_borrowed(buf)?
779            };
780        }
781        Ok(())
782    }
783    fn decode_field_6(
784        out: &mut Self,
785        buf: &mut &'a [u8],
786        version: i16,
787        flex: bool,
788    ) -> Result<(), ProtocolError> {
789        if version >= 0 {
790            out.subscribed_topic_names = {
791                let n = crate::primitives::array::get_array_len(buf, flex)?;
792                let mut v = Vec::with_capacity(n);
793                for _ in 0..n {
794                    v.push(if flex {
795                        get_compact_string_borrowed(buf)?
796                    } else {
797                        get_string_borrowed(buf)?
798                    });
799                }
800                v
801            };
802        }
803        Ok(())
804    }
805    fn decode_field_7(
806        out: &mut Self,
807        buf: &mut &'a [u8],
808        version: i16,
809        flex: bool,
810    ) -> Result<(), ProtocolError> {
811        if version >= 0 {
812            out.subscribed_topic_regex = if flex {
813                get_compact_nullable_string_borrowed(buf)?
814            } else {
815                get_nullable_string_borrowed(buf)?
816            };
817        }
818        Ok(())
819    }
820    fn decode_field_8(
821        out: &mut Self,
822        buf: &mut &'a [u8],
823        version: i16,
824        _flex: bool,
825    ) -> Result<(), ProtocolError> {
826        if version >= 0 {
827            out.assignment = super::common::consumer_group_describe_response::assignment::Assignment::decode_borrow(buf, version)?;
828        }
829        Ok(())
830    }
831    fn decode_field_9(
832        out: &mut Self,
833        buf: &mut &'a [u8],
834        version: i16,
835        _flex: bool,
836    ) -> Result<(), ProtocolError> {
837        if version >= 0 {
838            out.target_assignment = super::common::consumer_group_describe_response::assignment::Assignment::decode_borrow(buf, version)?;
839        }
840        Ok(())
841    }
842    fn decode_field_10(
843        out: &mut Self,
844        buf: &mut &'a [u8],
845        version: i16,
846        _flex: bool,
847    ) -> Result<(), ProtocolError> {
848        if version >= 1 {
849            out.member_type = get_i8(buf)?;
850        }
851        Ok(())
852    }
853    fn decode_tagged_fields(
854        out: &mut Self,
855        buf: &mut &'a [u8],
856        _version: i16,
857        flex: bool,
858    ) -> Result<(), ProtocolError> {
859        if flex {
860            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
861        }
862        Ok(())
863    }
864}
865impl Encode for Member<'_> {
866    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
867        let flex = version >= 0;
868        self.encode_field_0(buf, version, flex);
869        self.encode_field_1(buf, version, flex);
870        self.encode_field_2(buf, version, flex);
871        self.encode_field_3(buf, version, flex);
872        self.encode_field_4(buf, version, flex);
873        self.encode_field_5(buf, version, flex);
874        self.encode_field_6(buf, version, flex);
875        self.encode_field_7(buf, version, flex);
876        self.encode_field_8(buf, version, flex)?;
877        self.encode_field_9(buf, version, flex)?;
878        self.encode_field_10(buf, version, flex);
879        self.encode_tagged_fields(buf, version, flex);
880        Ok(())
881    }
882    fn encoded_len(&self, version: i16) -> usize {
883        let flex = version >= 0;
884        let mut n: usize = 0;
885        if version >= 0 {
886            n += if flex {
887                compact_string_len(self.member_id)
888            } else {
889                string_len(self.member_id)
890            };
891        }
892        if version >= 0 {
893            n += if flex {
894                compact_nullable_string_len(self.instance_id)
895            } else {
896                nullable_string_len(self.instance_id)
897            };
898        }
899        if version >= 0 {
900            n += if flex {
901                compact_nullable_string_len(self.rack_id)
902            } else {
903                nullable_string_len(self.rack_id)
904            };
905        }
906        if version >= 0 {
907            n += 4;
908        }
909        if version >= 0 {
910            n += if flex {
911                compact_string_len(self.client_id)
912            } else {
913                string_len(self.client_id)
914            };
915        }
916        if version >= 0 {
917            n += if flex {
918                compact_string_len(self.client_host)
919            } else {
920                string_len(self.client_host)
921            };
922        }
923        if version >= 0 {
924            n += {
925                let prefix = crate::primitives::array::array_len_prefix_len(
926                    (self.subscribed_topic_names).len(),
927                    flex,
928                );
929                let body: usize = (self.subscribed_topic_names)
930                    .iter()
931                    .map(|it| {
932                        if flex {
933                            compact_string_len(it)
934                        } else {
935                            string_len(it)
936                        }
937                    })
938                    .sum();
939                prefix + body
940            };
941        }
942        if version >= 0 {
943            n += if flex {
944                compact_nullable_string_len(self.subscribed_topic_regex)
945            } else {
946                nullable_string_len(self.subscribed_topic_regex)
947            };
948        }
949        if version >= 0 {
950            n += self.assignment.encoded_len(version);
951        }
952        if version >= 0 {
953            n += self.target_assignment.encoded_len(version);
954        }
955        if version >= 1 {
956            n += 1;
957        }
958        if flex {
959            let known_pairs: Vec<(u32, usize)> = Vec::new();
960            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
961        }
962        n
963    }
964}
965impl<'de> DecodeBorrow<'de> for Member<'de> {
966    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
967        let flex = version >= 0;
968        let mut out = Self::default();
969        Self::decode_field_0(&mut out, buf, version, flex)?;
970        Self::decode_field_1(&mut out, buf, version, flex)?;
971        Self::decode_field_2(&mut out, buf, version, flex)?;
972        Self::decode_field_3(&mut out, buf, version, flex)?;
973        Self::decode_field_4(&mut out, buf, version, flex)?;
974        Self::decode_field_5(&mut out, buf, version, flex)?;
975        Self::decode_field_6(&mut out, buf, version, flex)?;
976        Self::decode_field_7(&mut out, buf, version, flex)?;
977        Self::decode_field_8(&mut out, buf, version, flex)?;
978        Self::decode_field_9(&mut out, buf, version, flex)?;
979        Self::decode_field_10(&mut out, buf, version, flex)?;
980        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
981        Ok(out)
982    }
983}
984#[cfg(test)]
985impl Member<'_> {
986    #[must_use]
987    pub fn populated(version: i16) -> Self {
988        let mut m = Self::default();
989        if version >= 0 {
990            m.member_id = "x";
991        }
992        if version >= 0 {
993            m.instance_id = Some("x");
994        }
995        if version >= 0 {
996            m.rack_id = Some("x");
997        }
998        if version >= 0 {
999            m.member_epoch = 1i32;
1000        }
1001        if version >= 0 {
1002            m.client_id = "x";
1003        }
1004        if version >= 0 {
1005            m.client_host = "x";
1006        }
1007        if version >= 0 {
1008            m.subscribed_topic_names = vec!["x"];
1009        }
1010        if version >= 0 {
1011            m.subscribed_topic_regex = Some("x");
1012        }
1013        if version >= 0 {
1014            m.assignment =
1015                super::common::consumer_group_describe_response::assignment::Assignment::populated(
1016                    version,
1017                );
1018        }
1019        if version >= 0 {
1020            m.target_assignment =
1021                super::common::consumer_group_describe_response::assignment::Assignment::populated(
1022                    version,
1023                );
1024        }
1025        if version >= 1 {
1026            m.member_type = 1i8;
1027        }
1028        m
1029    }
1030}