Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupHeartbeatRequest.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_bool, get_i8, get_i16, get_i32, put_bool, put_i16, put_i32},
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 = 88;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const LATEST_STABLE_VERSION: i16 = 1;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct StreamsGroupHeartbeatRequest {
30    pub group_id: String,
31    pub member_id: String,
32    pub member_epoch: i32,
33    pub endpoint_information_epoch: i32,
34    pub instance_id: Option<String>,
35    pub rack_id: Option<String>,
36    pub rebalance_timeout_ms: i32,
37    pub topology: Option<Topology>,
38    pub active_tasks:
39        Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds>>,
40    pub standby_tasks:
41        Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds>>,
42    pub warmup_tasks:
43        Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds>>,
44    pub process_id: Option<String>,
45    pub user_endpoint: Option<super::common::streams_group_heartbeat_request::endpoint::Endpoint>,
46    pub client_tags:
47        Option<Vec<super::common::streams_group_heartbeat_request::key_value::KeyValue>>,
48    pub task_offsets:
49        Option<Vec<super::common::streams_group_heartbeat_request::task_offset::TaskOffset>>,
50    pub task_end_offsets:
51        Option<Vec<super::common::streams_group_heartbeat_request::task_offset::TaskOffset>>,
52    pub shutdown_application: bool,
53    pub unknown_tagged_fields: UnknownTaggedFields,
54}
55impl Default for StreamsGroupHeartbeatRequest {
56    fn default() -> Self {
57        Self {
58            group_id: String::new(),
59            member_id: String::new(),
60            member_epoch: 0i32,
61            endpoint_information_epoch: 0i32,
62            instance_id: None,
63            rack_id: None,
64            rebalance_timeout_ms: -1i32,
65            topology: None,
66            active_tasks: None,
67            standby_tasks: None,
68            warmup_tasks: None,
69            process_id: None,
70            user_endpoint: None,
71            client_tags: None,
72            task_offsets: None,
73            task_end_offsets: None,
74            shutdown_application: false,
75            unknown_tagged_fields: UnknownTaggedFields::default(),
76        }
77    }
78}
79impl StreamsGroupHeartbeatRequest {
80    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
81        if version >= 0 {
82            if flex {
83                let () = put_compact_string(buf, &self.group_id);
84            } else {
85                let () = put_string(buf, &self.group_id);
86            }
87        }
88    }
89    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
90        if version >= 0 {
91            if flex {
92                let () = put_compact_string(buf, &self.member_id);
93            } else {
94                let () = put_string(buf, &self.member_id);
95            }
96        }
97    }
98    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
99        if version >= 0 {
100            put_i32(buf, self.member_epoch);
101        }
102    }
103    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
104        if version >= 0 {
105            put_i32(buf, self.endpoint_information_epoch);
106        }
107    }
108    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
109        if version >= 0 {
110            if flex {
111                let () = put_compact_nullable_string(buf, self.instance_id.as_deref());
112            } else {
113                let () = put_nullable_string(buf, self.instance_id.as_deref());
114            }
115        }
116    }
117    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
118        if version >= 0 {
119            if flex {
120                let () = put_compact_nullable_string(buf, self.rack_id.as_deref());
121            } else {
122                let () = put_nullable_string(buf, self.rack_id.as_deref());
123            }
124        }
125    }
126    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
127        if version >= 0 {
128            put_i32(buf, self.rebalance_timeout_ms);
129        }
130    }
131    fn encode_field_7<B: BufMut>(
132        &self,
133        buf: &mut B,
134        version: i16,
135        _flex: bool,
136    ) -> Result<(), ProtocolError> {
137        if version >= 0 {
138            match &self.topology {
139                None => {
140                    buf.put_i8(-1);
141                }
142                Some(v) => {
143                    buf.put_i8(1);
144                    v.encode(buf, version)?;
145                }
146            }
147        }
148        Ok(())
149    }
150    fn encode_field_8<B: BufMut>(
151        &self,
152        buf: &mut B,
153        version: i16,
154        flex: bool,
155    ) -> Result<(), ProtocolError> {
156        if version >= 0 {
157            {
158                let len = (self.active_tasks).as_ref().map(Vec::len);
159                crate::primitives::array::put_nullable_array_len(buf, len, flex);
160                if let Some(v) = &self.active_tasks {
161                    for it in v {
162                        it.encode(buf, version)?;
163                    }
164                }
165            };
166        }
167        Ok(())
168    }
169    fn encode_field_9<B: BufMut>(
170        &self,
171        buf: &mut B,
172        version: i16,
173        flex: bool,
174    ) -> Result<(), ProtocolError> {
175        if version >= 0 {
176            {
177                let len = (self.standby_tasks).as_ref().map(Vec::len);
178                crate::primitives::array::put_nullable_array_len(buf, len, flex);
179                if let Some(v) = &self.standby_tasks {
180                    for it in v {
181                        it.encode(buf, version)?;
182                    }
183                }
184            };
185        }
186        Ok(())
187    }
188    fn encode_field_10<B: BufMut>(
189        &self,
190        buf: &mut B,
191        version: i16,
192        flex: bool,
193    ) -> Result<(), ProtocolError> {
194        if version >= 0 {
195            {
196                let len = (self.warmup_tasks).as_ref().map(Vec::len);
197                crate::primitives::array::put_nullable_array_len(buf, len, flex);
198                if let Some(v) = &self.warmup_tasks {
199                    for it in v {
200                        it.encode(buf, version)?;
201                    }
202                }
203            };
204        }
205        Ok(())
206    }
207    fn encode_field_11<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
208        if version >= 0 {
209            if flex {
210                let () = put_compact_nullable_string(buf, self.process_id.as_deref());
211            } else {
212                let () = put_nullable_string(buf, self.process_id.as_deref());
213            }
214        }
215    }
216    fn encode_field_12<B: BufMut>(
217        &self,
218        buf: &mut B,
219        version: i16,
220        _flex: bool,
221    ) -> Result<(), ProtocolError> {
222        if version >= 0 {
223            match &self.user_endpoint {
224                None => {
225                    buf.put_i8(-1);
226                }
227                Some(v) => {
228                    buf.put_i8(1);
229                    v.encode(buf, version)?;
230                }
231            }
232        }
233        Ok(())
234    }
235    fn encode_field_13<B: BufMut>(
236        &self,
237        buf: &mut B,
238        version: i16,
239        flex: bool,
240    ) -> Result<(), ProtocolError> {
241        if version >= 0 {
242            {
243                let len = (self.client_tags).as_ref().map(Vec::len);
244                crate::primitives::array::put_nullable_array_len(buf, len, flex);
245                if let Some(v) = &self.client_tags {
246                    for it in v {
247                        it.encode(buf, version)?;
248                    }
249                }
250            };
251        }
252        Ok(())
253    }
254    fn encode_field_14<B: BufMut>(
255        &self,
256        buf: &mut B,
257        version: i16,
258        flex: bool,
259    ) -> Result<(), ProtocolError> {
260        if version >= 0 {
261            {
262                let len = (self.task_offsets).as_ref().map(Vec::len);
263                crate::primitives::array::put_nullable_array_len(buf, len, flex);
264                if let Some(v) = &self.task_offsets {
265                    for it in v {
266                        it.encode(buf, version)?;
267                    }
268                }
269            };
270        }
271        Ok(())
272    }
273    fn encode_field_15<B: BufMut>(
274        &self,
275        buf: &mut B,
276        version: i16,
277        flex: bool,
278    ) -> Result<(), ProtocolError> {
279        if version >= 0 {
280            {
281                let len = (self.task_end_offsets).as_ref().map(Vec::len);
282                crate::primitives::array::put_nullable_array_len(buf, len, flex);
283                if let Some(v) = &self.task_end_offsets {
284                    for it in v {
285                        it.encode(buf, version)?;
286                    }
287                }
288            };
289        }
290        Ok(())
291    }
292    fn encode_field_16<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
293        if version >= 0 {
294            put_bool(buf, self.shutdown_application);
295        }
296    }
297    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
298        if flex {
299            let tagged = WriteTaggedFields::new();
300            tagged.write(buf, &self.unknown_tagged_fields);
301        }
302    }
303    fn decode_field_0<B: Buf>(
304        out: &mut Self,
305        buf: &mut B,
306        version: i16,
307        flex: bool,
308    ) -> Result<(), ProtocolError> {
309        if version >= 0 {
310            out.group_id = if flex {
311                get_compact_string_owned(buf)?
312            } else {
313                get_string_owned(buf)?
314            };
315        }
316        Ok(())
317    }
318    fn decode_field_1<B: Buf>(
319        out: &mut Self,
320        buf: &mut B,
321        version: i16,
322        flex: bool,
323    ) -> Result<(), ProtocolError> {
324        if version >= 0 {
325            out.member_id = if flex {
326                get_compact_string_owned(buf)?
327            } else {
328                get_string_owned(buf)?
329            };
330        }
331        Ok(())
332    }
333    fn decode_field_2<B: Buf>(
334        out: &mut Self,
335        buf: &mut B,
336        version: i16,
337        _flex: bool,
338    ) -> Result<(), ProtocolError> {
339        if version >= 0 {
340            out.member_epoch = get_i32(buf)?;
341        }
342        Ok(())
343    }
344    fn decode_field_3<B: Buf>(
345        out: &mut Self,
346        buf: &mut B,
347        version: i16,
348        _flex: bool,
349    ) -> Result<(), ProtocolError> {
350        if version >= 0 {
351            out.endpoint_information_epoch = get_i32(buf)?;
352        }
353        Ok(())
354    }
355    fn decode_field_4<B: Buf>(
356        out: &mut Self,
357        buf: &mut B,
358        version: i16,
359        flex: bool,
360    ) -> Result<(), ProtocolError> {
361        if version >= 0 {
362            out.instance_id = if flex {
363                get_compact_nullable_string_owned(buf)?
364            } else {
365                get_nullable_string_owned(buf)?
366            };
367        }
368        Ok(())
369    }
370    fn decode_field_5<B: Buf>(
371        out: &mut Self,
372        buf: &mut B,
373        version: i16,
374        flex: bool,
375    ) -> Result<(), ProtocolError> {
376        if version >= 0 {
377            out.rack_id = if flex {
378                get_compact_nullable_string_owned(buf)?
379            } else {
380                get_nullable_string_owned(buf)?
381            };
382        }
383        Ok(())
384    }
385    fn decode_field_6<B: Buf>(
386        out: &mut Self,
387        buf: &mut B,
388        version: i16,
389        _flex: bool,
390    ) -> Result<(), ProtocolError> {
391        if version >= 0 {
392            out.rebalance_timeout_ms = get_i32(buf)?;
393        }
394        Ok(())
395    }
396    fn decode_field_7<B: Buf>(
397        out: &mut Self,
398        buf: &mut B,
399        version: i16,
400        _flex: bool,
401    ) -> Result<(), ProtocolError> {
402        if version >= 0 {
403            out.topology = if get_i8(buf)? < 0 {
404                None
405            } else {
406                Some(Topology::decode(buf, version)?)
407            };
408        }
409        Ok(())
410    }
411    fn decode_field_8<B: Buf>(
412        out: &mut Self,
413        buf: &mut B,
414        version: i16,
415        flex: bool,
416    ) -> Result<(), ProtocolError> {
417        if version >= 0 {
418            out.active_tasks = {
419                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
420                match opt {
421                    None => None,
422                    Some(n) => {
423                        let mut v = Vec::with_capacity(n);
424                        for _ in 0..n {
425                            v.push(super::common::streams_group_heartbeat_request::task_ids::TaskIds::decode(buf, version)?);
426                        }
427                        Some(v)
428                    }
429                }
430            };
431        }
432        Ok(())
433    }
434    fn decode_field_9<B: Buf>(
435        out: &mut Self,
436        buf: &mut B,
437        version: i16,
438        flex: bool,
439    ) -> Result<(), ProtocolError> {
440        if version >= 0 {
441            out.standby_tasks = {
442                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
443                match opt {
444                    None => None,
445                    Some(n) => {
446                        let mut v = Vec::with_capacity(n);
447                        for _ in 0..n {
448                            v.push(super::common::streams_group_heartbeat_request::task_ids::TaskIds::decode(buf, version)?);
449                        }
450                        Some(v)
451                    }
452                }
453            };
454        }
455        Ok(())
456    }
457    fn decode_field_10<B: Buf>(
458        out: &mut Self,
459        buf: &mut B,
460        version: i16,
461        flex: bool,
462    ) -> Result<(), ProtocolError> {
463        if version >= 0 {
464            out.warmup_tasks = {
465                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
466                match opt {
467                    None => None,
468                    Some(n) => {
469                        let mut v = Vec::with_capacity(n);
470                        for _ in 0..n {
471                            v.push(super::common::streams_group_heartbeat_request::task_ids::TaskIds::decode(buf, version)?);
472                        }
473                        Some(v)
474                    }
475                }
476            };
477        }
478        Ok(())
479    }
480    fn decode_field_11<B: Buf>(
481        out: &mut Self,
482        buf: &mut B,
483        version: i16,
484        flex: bool,
485    ) -> Result<(), ProtocolError> {
486        if version >= 0 {
487            out.process_id = if flex {
488                get_compact_nullable_string_owned(buf)?
489            } else {
490                get_nullable_string_owned(buf)?
491            };
492        }
493        Ok(())
494    }
495    fn decode_field_12<B: Buf>(
496        out: &mut Self,
497        buf: &mut B,
498        version: i16,
499        _flex: bool,
500    ) -> Result<(), ProtocolError> {
501        if version >= 0 {
502            out.user_endpoint = if get_i8(buf)? < 0 {
503                None
504            } else {
505                Some(
506                    super::common::streams_group_heartbeat_request::endpoint::Endpoint::decode(
507                        buf, version,
508                    )?,
509                )
510            };
511        }
512        Ok(())
513    }
514    fn decode_field_13<B: Buf>(
515        out: &mut Self,
516        buf: &mut B,
517        version: i16,
518        flex: bool,
519    ) -> Result<(), ProtocolError> {
520        if version >= 0 {
521            out.client_tags = {
522                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
523                match opt {
524                    None => None,
525                    Some(n) => {
526                        let mut v = Vec::with_capacity(n);
527                        for _ in 0..n {
528                            v.push(super::common::streams_group_heartbeat_request::key_value::KeyValue::decode(buf, version)?);
529                        }
530                        Some(v)
531                    }
532                }
533            };
534        }
535        Ok(())
536    }
537    fn decode_field_14<B: Buf>(
538        out: &mut Self,
539        buf: &mut B,
540        version: i16,
541        flex: bool,
542    ) -> Result<(), ProtocolError> {
543        if version >= 0 {
544            out.task_offsets = {
545                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
546                match opt {
547                    None => None,
548                    Some(n) => {
549                        let mut v = Vec::with_capacity(n);
550                        for _ in 0..n {
551                            v.push(super::common::streams_group_heartbeat_request::task_offset::TaskOffset::decode(buf, version)?);
552                        }
553                        Some(v)
554                    }
555                }
556            };
557        }
558        Ok(())
559    }
560    fn decode_field_15<B: Buf>(
561        out: &mut Self,
562        buf: &mut B,
563        version: i16,
564        flex: bool,
565    ) -> Result<(), ProtocolError> {
566        if version >= 0 {
567            out.task_end_offsets = {
568                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
569                match opt {
570                    None => None,
571                    Some(n) => {
572                        let mut v = Vec::with_capacity(n);
573                        for _ in 0..n {
574                            v.push(super::common::streams_group_heartbeat_request::task_offset::TaskOffset::decode(buf, version)?);
575                        }
576                        Some(v)
577                    }
578                }
579            };
580        }
581        Ok(())
582    }
583    fn decode_field_16<B: Buf>(
584        out: &mut Self,
585        buf: &mut B,
586        version: i16,
587        _flex: bool,
588    ) -> Result<(), ProtocolError> {
589        if version >= 0 {
590            out.shutdown_application = get_bool(buf)?;
591        }
592        Ok(())
593    }
594    fn decode_tagged_fields<B: Buf>(
595        out: &mut Self,
596        buf: &mut B,
597        _version: i16,
598        flex: bool,
599    ) -> Result<(), ProtocolError> {
600        if flex {
601            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
602        }
603        Ok(())
604    }
605}
606impl Encode for StreamsGroupHeartbeatRequest {
607    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
608        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
609            return Err(ProtocolError::UnsupportedVersion {
610                api_key: API_KEY,
611                version,
612            });
613        }
614        let flex = is_flexible(version);
615        self.encode_field_0(buf, version, flex);
616        self.encode_field_1(buf, version, flex);
617        self.encode_field_2(buf, version, flex);
618        self.encode_field_3(buf, version, flex);
619        self.encode_field_4(buf, version, flex);
620        self.encode_field_5(buf, version, flex);
621        self.encode_field_6(buf, version, flex);
622        self.encode_field_7(buf, version, flex)?;
623        self.encode_field_8(buf, version, flex)?;
624        self.encode_field_9(buf, version, flex)?;
625        self.encode_field_10(buf, version, flex)?;
626        self.encode_field_11(buf, version, flex);
627        self.encode_field_12(buf, version, flex)?;
628        self.encode_field_13(buf, version, flex)?;
629        self.encode_field_14(buf, version, flex)?;
630        self.encode_field_15(buf, version, flex)?;
631        self.encode_field_16(buf, version, flex);
632        self.encode_tagged_fields(buf, version, flex);
633        Ok(())
634    }
635    fn encoded_len(&self, version: i16) -> usize {
636        let flex = is_flexible(version);
637        let mut n: usize = 0;
638        if version >= 0 {
639            n += if flex {
640                compact_string_len(&self.group_id)
641            } else {
642                string_len(&self.group_id)
643            };
644        }
645        if version >= 0 {
646            n += if flex {
647                compact_string_len(&self.member_id)
648            } else {
649                string_len(&self.member_id)
650            };
651        }
652        if version >= 0 {
653            n += 4;
654        }
655        if version >= 0 {
656            n += 4;
657        }
658        if version >= 0 {
659            n += if flex {
660                compact_nullable_string_len(self.instance_id.as_deref())
661            } else {
662                nullable_string_len(self.instance_id.as_deref())
663            };
664        }
665        if version >= 0 {
666            n += if flex {
667                compact_nullable_string_len(self.rack_id.as_deref())
668            } else {
669                nullable_string_len(self.rack_id.as_deref())
670            };
671        }
672        if version >= 0 {
673            n += 4;
674        }
675        if version >= 0 {
676            n += 1 + self.topology.as_ref().map_or(0, |v| v.encoded_len(version));
677        }
678        if version >= 0 {
679            n += {
680                let opt: Option<&Vec<_>> = (self.active_tasks).as_ref();
681                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
682                    opt.map(std::vec::Vec::len),
683                    flex,
684                );
685                let body: usize =
686                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
687                prefix + body
688            };
689        }
690        if version >= 0 {
691            n += {
692                let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref();
693                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
694                    opt.map(std::vec::Vec::len),
695                    flex,
696                );
697                let body: usize =
698                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
699                prefix + body
700            };
701        }
702        if version >= 0 {
703            n += {
704                let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref();
705                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
706                    opt.map(std::vec::Vec::len),
707                    flex,
708                );
709                let body: usize =
710                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
711                prefix + body
712            };
713        }
714        if version >= 0 {
715            n += if flex {
716                compact_nullable_string_len(self.process_id.as_deref())
717            } else {
718                nullable_string_len(self.process_id.as_deref())
719            };
720        }
721        if version >= 0 {
722            n += 1 + self
723                .user_endpoint
724                .as_ref()
725                .map_or(0, |v| v.encoded_len(version));
726        }
727        if version >= 0 {
728            n += {
729                let opt: Option<&Vec<_>> = (self.client_tags).as_ref();
730                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
731                    opt.map(std::vec::Vec::len),
732                    flex,
733                );
734                let body: usize =
735                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
736                prefix + body
737            };
738        }
739        if version >= 0 {
740            n += {
741                let opt: Option<&Vec<_>> = (self.task_offsets).as_ref();
742                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
743                    opt.map(std::vec::Vec::len),
744                    flex,
745                );
746                let body: usize =
747                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
748                prefix + body
749            };
750        }
751        if version >= 0 {
752            n += {
753                let opt: Option<&Vec<_>> = (self.task_end_offsets).as_ref();
754                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
755                    opt.map(std::vec::Vec::len),
756                    flex,
757                );
758                let body: usize =
759                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
760                prefix + body
761            };
762        }
763        if version >= 0 {
764            n += 1;
765        }
766        if flex {
767            let known_pairs: Vec<(u32, usize)> = Vec::new();
768            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
769        }
770        n
771    }
772}
773impl Decode<'_> for StreamsGroupHeartbeatRequest {
774    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
775        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
776            return Err(ProtocolError::UnsupportedVersion {
777                api_key: API_KEY,
778                version,
779            });
780        }
781        let flex = is_flexible(version);
782        let mut out = Self::default();
783        Self::decode_field_0(&mut out, buf, version, flex)?;
784        Self::decode_field_1(&mut out, buf, version, flex)?;
785        Self::decode_field_2(&mut out, buf, version, flex)?;
786        Self::decode_field_3(&mut out, buf, version, flex)?;
787        Self::decode_field_4(&mut out, buf, version, flex)?;
788        Self::decode_field_5(&mut out, buf, version, flex)?;
789        Self::decode_field_6(&mut out, buf, version, flex)?;
790        Self::decode_field_7(&mut out, buf, version, flex)?;
791        Self::decode_field_8(&mut out, buf, version, flex)?;
792        Self::decode_field_9(&mut out, buf, version, flex)?;
793        Self::decode_field_10(&mut out, buf, version, flex)?;
794        Self::decode_field_11(&mut out, buf, version, flex)?;
795        Self::decode_field_12(&mut out, buf, version, flex)?;
796        Self::decode_field_13(&mut out, buf, version, flex)?;
797        Self::decode_field_14(&mut out, buf, version, flex)?;
798        Self::decode_field_15(&mut out, buf, version, flex)?;
799        Self::decode_field_16(&mut out, buf, version, flex)?;
800        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
801        Ok(out)
802    }
803}
804#[cfg(test)]
805impl StreamsGroupHeartbeatRequest {
806    #[must_use]
807    pub fn populated(version: i16) -> Self {
808        let mut m = Self::default();
809        if version >= 0 {
810            m.group_id = "x".to_string();
811        }
812        if version >= 0 {
813            m.member_id = "x".to_string();
814        }
815        if version >= 0 {
816            m.member_epoch = 1i32;
817        }
818        if version >= 0 {
819            m.endpoint_information_epoch = 1i32;
820        }
821        if version >= 0 {
822            m.instance_id = Some("x".to_string());
823        }
824        if version >= 0 {
825            m.rack_id = Some("x".to_string());
826        }
827        if version >= 0 {
828            m.rebalance_timeout_ms = 1i32;
829        }
830        if version >= 0 {
831            m.topology = Some(Topology::populated(version));
832        }
833        if version >= 0 {
834            m.active_tasks = Some(vec![
835                super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
836                    version,
837                ),
838            ]);
839        }
840        if version >= 0 {
841            m.standby_tasks = Some(vec![
842                super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
843                    version,
844                ),
845            ]);
846        }
847        if version >= 0 {
848            m.warmup_tasks = Some(vec![
849                super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
850                    version,
851                ),
852            ]);
853        }
854        if version >= 0 {
855            m.process_id = Some("x".to_string());
856        }
857        if version >= 0 {
858            m.user_endpoint = Some(
859                super::common::streams_group_heartbeat_request::endpoint::Endpoint::populated(
860                    version,
861                ),
862            );
863        }
864        if version >= 0 {
865            m.client_tags = Some(vec![
866                super::common::streams_group_heartbeat_request::key_value::KeyValue::populated(
867                    version,
868                ),
869            ]);
870        }
871        if version >= 0 {
872            m.task_offsets = Some(vec![
873                super::common::streams_group_heartbeat_request::task_offset::TaskOffset::populated(
874                    version,
875                ),
876            ]);
877        }
878        if version >= 0 {
879            m.task_end_offsets = Some(vec![
880                super::common::streams_group_heartbeat_request::task_offset::TaskOffset::populated(
881                    version,
882                ),
883            ]);
884        }
885        if version >= 0 {
886            m.shutdown_application = true;
887        }
888        m
889    }
890}
891#[derive(Debug, Clone, PartialEq, Eq, Default)]
892pub struct Topology {
893    pub epoch: i32,
894    pub subtopologies: Vec<Subtopology>,
895    pub unknown_tagged_fields: UnknownTaggedFields,
896}
897impl Encode for Topology {
898    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
899        let flex = version >= 0;
900        if version >= 0 {
901            put_i32(buf, self.epoch);
902        }
903        if version >= 0 {
904            {
905                crate::primitives::array::put_array_len(buf, (self.subtopologies).len(), flex);
906                for it in &self.subtopologies {
907                    it.encode(buf, version)?;
908                }
909            };
910        }
911        if flex {
912            let tagged = WriteTaggedFields::new();
913            tagged.write(buf, &self.unknown_tagged_fields);
914        }
915        Ok(())
916    }
917    fn encoded_len(&self, version: i16) -> usize {
918        let flex = version >= 0;
919        let mut n: usize = 0;
920        if version >= 0 {
921            n += 4;
922        }
923        if version >= 0 {
924            n += {
925                let prefix = crate::primitives::array::array_len_prefix_len(
926                    (self.subtopologies).len(),
927                    flex,
928                );
929                let body: usize = (self.subtopologies)
930                    .iter()
931                    .map(|it| it.encoded_len(version))
932                    .sum();
933                prefix + body
934            };
935        }
936        if flex {
937            let known_pairs: Vec<(u32, usize)> = Vec::new();
938            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
939        }
940        n
941    }
942}
943impl Decode<'_> for Topology {
944    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
945        let flex = version >= 0;
946        let mut out = Self::default();
947        if version >= 0 {
948            out.epoch = get_i32(buf)?;
949        }
950        if version >= 0 {
951            out.subtopologies = {
952                let n = crate::primitives::array::get_array_len(buf, flex)?;
953                let mut v = Vec::with_capacity(n);
954                for _ in 0..n {
955                    v.push(Subtopology::decode(buf, version)?);
956                }
957                v
958            };
959        }
960        if flex {
961            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
962        }
963        Ok(out)
964    }
965}
966#[cfg(test)]
967impl Topology {
968    #[must_use]
969    pub fn populated(version: i16) -> Self {
970        let mut m = Self::default();
971        if version >= 0 {
972            m.epoch = 1i32;
973        }
974        if version >= 0 {
975            m.subtopologies = vec![Subtopology::populated(version)];
976        }
977        m
978    }
979}
980#[derive(Debug, Clone, PartialEq, Eq, Default)]
981pub struct Subtopology {
982    pub subtopology_id: String,
983    pub source_topics: Vec<String>,
984    pub source_topic_regex: Vec<String>,
985    pub state_changelog_topics:
986        Vec<super::common::streams_group_heartbeat_request::topic_info::TopicInfo>,
987    pub repartition_sink_topics: Vec<String>,
988    pub repartition_source_topics:
989        Vec<super::common::streams_group_heartbeat_request::topic_info::TopicInfo>,
990    pub copartition_groups: Vec<CopartitionGroup>,
991    pub unknown_tagged_fields: UnknownTaggedFields,
992}
993impl Encode for Subtopology {
994    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
995        let flex = version >= 0;
996        if version >= 0 {
997            if flex {
998                let () = put_compact_string(buf, &self.subtopology_id);
999            } else {
1000                let () = put_string(buf, &self.subtopology_id);
1001            }
1002        }
1003        if version >= 0 {
1004            {
1005                crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex);
1006                for it in &self.source_topics {
1007                    if flex {
1008                        let () = put_compact_string(buf, it);
1009                    } else {
1010                        let () = put_string(buf, it);
1011                    }
1012                }
1013            };
1014        }
1015        if version >= 0 {
1016            {
1017                crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex);
1018                for it in &self.source_topic_regex {
1019                    if flex {
1020                        let () = put_compact_string(buf, it);
1021                    } else {
1022                        let () = put_string(buf, it);
1023                    }
1024                }
1025            };
1026        }
1027        if version >= 0 {
1028            {
1029                crate::primitives::array::put_array_len(
1030                    buf,
1031                    (self.state_changelog_topics).len(),
1032                    flex,
1033                );
1034                for it in &self.state_changelog_topics {
1035                    it.encode(buf, version)?;
1036                }
1037            };
1038        }
1039        if version >= 0 {
1040            {
1041                crate::primitives::array::put_array_len(
1042                    buf,
1043                    (self.repartition_sink_topics).len(),
1044                    flex,
1045                );
1046                for it in &self.repartition_sink_topics {
1047                    if flex {
1048                        let () = put_compact_string(buf, it);
1049                    } else {
1050                        let () = put_string(buf, it);
1051                    }
1052                }
1053            };
1054        }
1055        if version >= 0 {
1056            {
1057                crate::primitives::array::put_array_len(
1058                    buf,
1059                    (self.repartition_source_topics).len(),
1060                    flex,
1061                );
1062                for it in &self.repartition_source_topics {
1063                    it.encode(buf, version)?;
1064                }
1065            };
1066        }
1067        if version >= 0 {
1068            {
1069                crate::primitives::array::put_array_len(buf, (self.copartition_groups).len(), flex);
1070                for it in &self.copartition_groups {
1071                    it.encode(buf, version)?;
1072                }
1073            };
1074        }
1075        if flex {
1076            let tagged = WriteTaggedFields::new();
1077            tagged.write(buf, &self.unknown_tagged_fields);
1078        }
1079        Ok(())
1080    }
1081    fn encoded_len(&self, version: i16) -> usize {
1082        let flex = version >= 0;
1083        let mut n: usize = 0;
1084        if version >= 0 {
1085            n += if flex {
1086                compact_string_len(&self.subtopology_id)
1087            } else {
1088                string_len(&self.subtopology_id)
1089            };
1090        }
1091        if version >= 0 {
1092            n += {
1093                let prefix = crate::primitives::array::array_len_prefix_len(
1094                    (self.source_topics).len(),
1095                    flex,
1096                );
1097                let body: usize = (self.source_topics)
1098                    .iter()
1099                    .map(|it| {
1100                        if flex {
1101                            compact_string_len(it)
1102                        } else {
1103                            string_len(it)
1104                        }
1105                    })
1106                    .sum();
1107                prefix + body
1108            };
1109        }
1110        if version >= 0 {
1111            n += {
1112                let prefix = crate::primitives::array::array_len_prefix_len(
1113                    (self.source_topic_regex).len(),
1114                    flex,
1115                );
1116                let body: usize = (self.source_topic_regex)
1117                    .iter()
1118                    .map(|it| {
1119                        if flex {
1120                            compact_string_len(it)
1121                        } else {
1122                            string_len(it)
1123                        }
1124                    })
1125                    .sum();
1126                prefix + body
1127            };
1128        }
1129        if version >= 0 {
1130            n += {
1131                let prefix = crate::primitives::array::array_len_prefix_len(
1132                    (self.state_changelog_topics).len(),
1133                    flex,
1134                );
1135                let body: usize = (self.state_changelog_topics)
1136                    .iter()
1137                    .map(|it| it.encoded_len(version))
1138                    .sum();
1139                prefix + body
1140            };
1141        }
1142        if version >= 0 {
1143            n += {
1144                let prefix = crate::primitives::array::array_len_prefix_len(
1145                    (self.repartition_sink_topics).len(),
1146                    flex,
1147                );
1148                let body: usize = (self.repartition_sink_topics)
1149                    .iter()
1150                    .map(|it| {
1151                        if flex {
1152                            compact_string_len(it)
1153                        } else {
1154                            string_len(it)
1155                        }
1156                    })
1157                    .sum();
1158                prefix + body
1159            };
1160        }
1161        if version >= 0 {
1162            n += {
1163                let prefix = crate::primitives::array::array_len_prefix_len(
1164                    (self.repartition_source_topics).len(),
1165                    flex,
1166                );
1167                let body: usize = (self.repartition_source_topics)
1168                    .iter()
1169                    .map(|it| it.encoded_len(version))
1170                    .sum();
1171                prefix + body
1172            };
1173        }
1174        if version >= 0 {
1175            n += {
1176                let prefix = crate::primitives::array::array_len_prefix_len(
1177                    (self.copartition_groups).len(),
1178                    flex,
1179                );
1180                let body: usize = (self.copartition_groups)
1181                    .iter()
1182                    .map(|it| it.encoded_len(version))
1183                    .sum();
1184                prefix + body
1185            };
1186        }
1187        if flex {
1188            let known_pairs: Vec<(u32, usize)> = Vec::new();
1189            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
1190        }
1191        n
1192    }
1193}
1194impl Decode<'_> for Subtopology {
1195    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
1196        let flex = version >= 0;
1197        let mut out = Self::default();
1198        if version >= 0 {
1199            out.subtopology_id = if flex {
1200                get_compact_string_owned(buf)?
1201            } else {
1202                get_string_owned(buf)?
1203            };
1204        }
1205        if version >= 0 {
1206            out.source_topics = {
1207                let n = crate::primitives::array::get_array_len(buf, flex)?;
1208                let mut v = Vec::with_capacity(n);
1209                for _ in 0..n {
1210                    v.push(if flex {
1211                        get_compact_string_owned(buf)?
1212                    } else {
1213                        get_string_owned(buf)?
1214                    });
1215                }
1216                v
1217            };
1218        }
1219        if version >= 0 {
1220            out.source_topic_regex = {
1221                let n = crate::primitives::array::get_array_len(buf, flex)?;
1222                let mut v = Vec::with_capacity(n);
1223                for _ in 0..n {
1224                    v.push(if flex {
1225                        get_compact_string_owned(buf)?
1226                    } else {
1227                        get_string_owned(buf)?
1228                    });
1229                }
1230                v
1231            };
1232        }
1233        if version >= 0 {
1234            out.state_changelog_topics = {
1235                let n = crate::primitives::array::get_array_len(buf, flex)?;
1236                let mut v = Vec::with_capacity(n);
1237                for _ in 0..n {
1238                    v.push(super::common::streams_group_heartbeat_request::topic_info::TopicInfo::decode(buf, version)?);
1239                }
1240                v
1241            };
1242        }
1243        if version >= 0 {
1244            out.repartition_sink_topics = {
1245                let n = crate::primitives::array::get_array_len(buf, flex)?;
1246                let mut v = Vec::with_capacity(n);
1247                for _ in 0..n {
1248                    v.push(if flex {
1249                        get_compact_string_owned(buf)?
1250                    } else {
1251                        get_string_owned(buf)?
1252                    });
1253                }
1254                v
1255            };
1256        }
1257        if version >= 0 {
1258            out.repartition_source_topics = {
1259                let n = crate::primitives::array::get_array_len(buf, flex)?;
1260                let mut v = Vec::with_capacity(n);
1261                for _ in 0..n {
1262                    v.push(super::common::streams_group_heartbeat_request::topic_info::TopicInfo::decode(buf, version)?);
1263                }
1264                v
1265            };
1266        }
1267        if version >= 0 {
1268            out.copartition_groups = {
1269                let n = crate::primitives::array::get_array_len(buf, flex)?;
1270                let mut v = Vec::with_capacity(n);
1271                for _ in 0..n {
1272                    v.push(CopartitionGroup::decode(buf, version)?);
1273                }
1274                v
1275            };
1276        }
1277        if flex {
1278            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
1279        }
1280        Ok(out)
1281    }
1282}
1283#[cfg(test)]
1284impl Subtopology {
1285    #[must_use]
1286    pub fn populated(version: i16) -> Self {
1287        let mut m = Self::default();
1288        if version >= 0 {
1289            m.subtopology_id = "x".to_string();
1290        }
1291        if version >= 0 {
1292            m.source_topics = vec!["x".to_string()];
1293        }
1294        if version >= 0 {
1295            m.source_topic_regex = vec!["x".to_string()];
1296        }
1297        if version >= 0 {
1298            m.state_changelog_topics = vec![
1299                super::common::streams_group_heartbeat_request::topic_info::TopicInfo::populated(
1300                    version,
1301                ),
1302            ];
1303        }
1304        if version >= 0 {
1305            m.repartition_sink_topics = vec!["x".to_string()];
1306        }
1307        if version >= 0 {
1308            m.repartition_source_topics = vec![
1309                super::common::streams_group_heartbeat_request::topic_info::TopicInfo::populated(
1310                    version,
1311                ),
1312            ];
1313        }
1314        if version >= 0 {
1315            m.copartition_groups = vec![CopartitionGroup::populated(version)];
1316        }
1317        m
1318    }
1319}
1320#[derive(Debug, Clone, PartialEq, Eq, Default)]
1321pub struct CopartitionGroup {
1322    pub source_topics: Vec<i16>,
1323    pub source_topic_regex: Vec<i16>,
1324    pub repartition_source_topics: Vec<i16>,
1325    pub unknown_tagged_fields: UnknownTaggedFields,
1326}
1327impl Encode for CopartitionGroup {
1328    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
1329        let flex = version >= 0;
1330        if version >= 0 {
1331            {
1332                crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex);
1333                for it in &self.source_topics {
1334                    put_i16(buf, *it);
1335                }
1336            };
1337        }
1338        if version >= 0 {
1339            {
1340                crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex);
1341                for it in &self.source_topic_regex {
1342                    put_i16(buf, *it);
1343                }
1344            };
1345        }
1346        if version >= 0 {
1347            {
1348                crate::primitives::array::put_array_len(
1349                    buf,
1350                    (self.repartition_source_topics).len(),
1351                    flex,
1352                );
1353                for it in &self.repartition_source_topics {
1354                    put_i16(buf, *it);
1355                }
1356            };
1357        }
1358        if flex {
1359            let tagged = WriteTaggedFields::new();
1360            tagged.write(buf, &self.unknown_tagged_fields);
1361        }
1362        Ok(())
1363    }
1364    fn encoded_len(&self, version: i16) -> usize {
1365        let flex = version >= 0;
1366        let mut n: usize = 0;
1367        if version >= 0 {
1368            n += {
1369                let prefix = crate::primitives::array::array_len_prefix_len(
1370                    (self.source_topics).len(),
1371                    flex,
1372                );
1373                let body: usize = (self.source_topics).iter().map(|_| 2).sum();
1374                prefix + body
1375            };
1376        }
1377        if version >= 0 {
1378            n += {
1379                let prefix = crate::primitives::array::array_len_prefix_len(
1380                    (self.source_topic_regex).len(),
1381                    flex,
1382                );
1383                let body: usize = (self.source_topic_regex).iter().map(|_| 2).sum();
1384                prefix + body
1385            };
1386        }
1387        if version >= 0 {
1388            n += {
1389                let prefix = crate::primitives::array::array_len_prefix_len(
1390                    (self.repartition_source_topics).len(),
1391                    flex,
1392                );
1393                let body: usize = (self.repartition_source_topics).iter().map(|_| 2).sum();
1394                prefix + body
1395            };
1396        }
1397        if flex {
1398            let known_pairs: Vec<(u32, usize)> = Vec::new();
1399            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
1400        }
1401        n
1402    }
1403}
1404impl Decode<'_> for CopartitionGroup {
1405    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
1406        let flex = version >= 0;
1407        let mut out = Self::default();
1408        if version >= 0 {
1409            out.source_topics = {
1410                let n = crate::primitives::array::get_array_len(buf, flex)?;
1411                let mut v = Vec::with_capacity(n);
1412                for _ in 0..n {
1413                    v.push(get_i16(buf)?);
1414                }
1415                v
1416            };
1417        }
1418        if version >= 0 {
1419            out.source_topic_regex = {
1420                let n = crate::primitives::array::get_array_len(buf, flex)?;
1421                let mut v = Vec::with_capacity(n);
1422                for _ in 0..n {
1423                    v.push(get_i16(buf)?);
1424                }
1425                v
1426            };
1427        }
1428        if version >= 0 {
1429            out.repartition_source_topics = {
1430                let n = crate::primitives::array::get_array_len(buf, flex)?;
1431                let mut v = Vec::with_capacity(n);
1432                for _ in 0..n {
1433                    v.push(get_i16(buf)?);
1434                }
1435                v
1436            };
1437        }
1438        if flex {
1439            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
1440        }
1441        Ok(out)
1442    }
1443}
1444#[cfg(test)]
1445impl CopartitionGroup {
1446    #[must_use]
1447    pub fn populated(version: i16) -> Self {
1448        let mut m = Self::default();
1449        if version >= 0 {
1450            m.source_topics = vec![1i16];
1451        }
1452        if version >= 0 {
1453            m.source_topic_regex = vec![1i16];
1454        }
1455        if version >= 0 {
1456            m.repartition_source_topics = vec![1i16];
1457        }
1458        m
1459    }
1460}
1461/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
1462/// Only includes fields valid for the given version.
1463#[must_use]
1464#[allow(unused_comparisons)]
1465pub fn default_json(_version: i16) -> ::serde_json::Value {
1466    let mut obj = ::serde_json::Map::new();
1467    obj.insert(
1468        "groupId".to_string(),
1469        ::serde_json::Value::String(String::new()),
1470    );
1471    obj.insert(
1472        "memberId".to_string(),
1473        ::serde_json::Value::String(String::new()),
1474    );
1475    obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
1476    obj.insert(
1477        "endpointInformationEpoch".to_string(),
1478        ::serde_json::json!(0),
1479    );
1480    obj.insert("instanceId".to_string(), ::serde_json::Value::Null);
1481    obj.insert("rackId".to_string(), ::serde_json::Value::Null);
1482    obj.insert("rebalanceTimeoutMs".to_string(), ::serde_json::json!(-1));
1483    obj.insert("topology".to_string(), ::serde_json::Value::Null);
1484    obj.insert("activeTasks".to_string(), ::serde_json::Value::Null);
1485    obj.insert("standbyTasks".to_string(), ::serde_json::Value::Null);
1486    obj.insert("warmupTasks".to_string(), ::serde_json::Value::Null);
1487    obj.insert("processId".to_string(), ::serde_json::Value::Null);
1488    obj.insert("userEndpoint".to_string(), ::serde_json::Value::Null);
1489    obj.insert("clientTags".to_string(), ::serde_json::Value::Null);
1490    obj.insert("taskOffsets".to_string(), ::serde_json::Value::Null);
1491    obj.insert("taskEndOffsets".to_string(), ::serde_json::Value::Null);
1492    obj.insert(
1493        "shutdownApplication".to_string(),
1494        ::serde_json::Value::Bool(false),
1495    );
1496    ::serde_json::Value::Object(obj)
1497}
1498impl crate::ProtocolRequest for StreamsGroupHeartbeatRequest {
1499    const API_KEY: i16 = API_KEY;
1500    const MIN_VERSION: i16 = MIN_VERSION;
1501    const MAX_VERSION: i16 = MAX_VERSION;
1502    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
1503    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
1504    type Response = super::streams_group_heartbeat_response::StreamsGroupHeartbeatResponse;
1505}