Skip to main content

kacrab_protocol/generated/
fetch_response.rs

1//! Generated from FetchResponse.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct FetchResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The top level response error code.
21    pub error_code: i16,
22    /// The fetch session ID, or 0 if this is not part of a fetch session.
23    pub session_id: i32,
24    /// The response topics.
25    pub responses: Vec<FetchableTopicResponse>,
26    /// Endpoints for all current-leaders enumerated in PartitionData, with errors
27    /// NOT_LEADER_OR_FOLLOWER & FENCED_LEADER_EPOCH.
28    pub node_endpoints: Vec<NodeEndpoint>,
29    pub _unknown_tagged_fields: Vec<RawTaggedField>,
30}
31impl Default for FetchResponseData {
32    fn default() -> Self {
33        Self {
34            throttle_time_ms: 0_i32,
35            error_code: 0_i16,
36            session_id: 0i32,
37            responses: Vec::new(),
38            node_endpoints: Vec::new(),
39            _unknown_tagged_fields: Vec::new(),
40        }
41    }
42}
43impl FetchResponseData {
44    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45        self.throttle_time_ms = value;
46        self
47    }
48    pub fn with_error_code(mut self, value: i16) -> Self {
49        self.error_code = value;
50        self
51    }
52    pub fn with_session_id(mut self, value: i32) -> Self {
53        self.session_id = value;
54        self
55    }
56    pub fn with_responses(mut self, value: Vec<FetchableTopicResponse>) -> Self {
57        self.responses = value;
58        self
59    }
60    pub fn with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
61        self.node_endpoints = value;
62        self
63    }
64    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
65        if version < 4 || version > 18 {
66            return Err(UnsupportedVersion::new(1, version).into());
67        }
68        let throttle_time_ms;
69        let mut error_code = 0_i16;
70        let mut session_id = 0i32;
71        let responses;
72        let mut node_endpoints = Vec::new();
73        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
74        throttle_time_ms = read_i32(buf)?;
75        if version >= 7 {
76            error_code = read_i16(buf)?;
77        }
78        if version >= 7 {
79            session_id = read_i32(buf)?;
80        }
81        if version >= 12 {
82            responses = {
83                let len = read_compact_array_length(buf)?;
84                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
85                for _ in 0..len {
86                    arr.push(FetchableTopicResponse::read(buf, version)?);
87                }
88                arr
89            };
90        } else {
91            responses = {
92                let len = read_array_length(buf)?;
93                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
94                for _ in 0..len {
95                    arr.push(FetchableTopicResponse::read(buf, version)?);
96                }
97                arr
98            };
99        }
100        if version >= 12 {
101            let tagged_fields = read_tagged_fields(buf)?;
102            for field in &tagged_fields {
103                match field.tag {
104                    0 => {
105                        if version >= 16 {
106                            let mut tag_buf = field.data.clone();
107                            node_endpoints = {
108                                let len = read_compact_array_length(&mut tag_buf)?;
109                                let mut arr = Vec::with_capacity(array_read_capacity(
110                                    len,
111                                    (&mut tag_buf).len(),
112                                ));
113                                for _ in 0..len {
114                                    arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
115                                }
116                                arr
117                            };
118                        }
119                    },
120                    _ => {
121                        _unknown_tagged_fields.push(field.clone());
122                    },
123                }
124            }
125        }
126        Ok(Self {
127            throttle_time_ms,
128            error_code,
129            session_id,
130            responses,
131            node_endpoints,
132            _unknown_tagged_fields,
133        })
134    }
135    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
136        if version < 4 || version > 18 {
137            return Err(UnsupportedVersion::new(1, version).into());
138        }
139        write_i32(buf, self.throttle_time_ms);
140        if version >= 7 {
141            write_i16(buf, self.error_code);
142        } else if self.error_code != 0_i16 {
143            return Err(UnsupportedFieldVersion::new(1, "error_code", version).into());
144        }
145        if version >= 7 {
146            write_i32(buf, self.session_id);
147        } else if self.session_id != 0i32 {
148            return Err(UnsupportedFieldVersion::new(1, "session_id", version).into());
149        }
150        if version >= 12 {
151            write_compact_array_length(buf, self.responses.len() as i32);
152            for el in &self.responses {
153                el.write(buf, version)?;
154            }
155        } else {
156            write_array_length(buf, self.responses.len() as i32);
157            for el in &self.responses {
158                el.write(buf, version)?;
159            }
160        }
161        if version >= 12 {
162            let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
163            if version >= 16 && !self.node_endpoints.is_empty() {
164                let mut tag_buf = BytesMut::new();
165                write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
166                for el in &self.node_endpoints {
167                    el.write(&mut tag_buf, version)?;
168                }
169                known_tagged_fields.push(RawTaggedField {
170                    tag: 0,
171                    data: tag_buf.freeze(),
172                });
173            }
174            let mut all_tags = known_tagged_fields;
175            all_tags.extend(self._unknown_tagged_fields.iter().cloned());
176            all_tags.sort_by_key(|f| f.tag);
177            write_tagged_fields(buf, &all_tags)?;
178        }
179        Ok(())
180    }
181    pub fn encoded_len(&self, version: i16) -> Result<usize> {
182        if version < 4 || version > 18 {
183            return Err(UnsupportedVersion::new(1, version).into());
184        }
185        let mut len: usize = 0;
186        len += 4;
187        if version >= 7 {
188            len += 2;
189        } else if self.error_code != 0_i16 {
190            return Err(UnsupportedFieldVersion::new(1, "error_code", version).into());
191        }
192        if version >= 7 {
193            len += 4;
194        } else if self.session_id != 0i32 {
195            return Err(UnsupportedFieldVersion::new(1, "session_id", version).into());
196        }
197        if version >= 12 {
198            len += compact_array_length_len(self.responses.len() as i32);
199            for el in &self.responses {
200                len += el.encoded_len(version)?;
201            }
202        } else {
203            len += array_length_len();
204            for el in &self.responses {
205                len += el.encoded_len(version)?;
206            }
207        }
208        if version >= 12 {
209            let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
210            if version >= 16 && !self.node_endpoints.is_empty() {
211                let mut tag_buf = BytesMut::new();
212                write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
213                for el in &self.node_endpoints {
214                    el.write(&mut tag_buf, version)?;
215                }
216                known_tagged_fields.push(RawTaggedField {
217                    tag: 0,
218                    data: tag_buf.freeze(),
219                });
220            }
221            let mut all_tags = known_tagged_fields;
222            all_tags.extend(self._unknown_tagged_fields.iter().cloned());
223            all_tags.sort_by_key(|f| f.tag);
224            len += tagged_fields_len(&all_tags)?;
225        }
226        Ok(len)
227    }
228}
229#[derive(Debug, Clone, PartialEq)]
230pub struct FetchableTopicResponse {
231    /// The topic name.
232    pub topic: KafkaString,
233    /// The unique topic ID.
234    pub topic_id: KafkaUuid,
235    /// The topic partitions.
236    pub partitions: Vec<PartitionData>,
237    pub _unknown_tagged_fields: Vec<RawTaggedField>,
238}
239impl Default for FetchableTopicResponse {
240    fn default() -> Self {
241        Self {
242            topic: KafkaString::default(),
243            topic_id: KafkaUuid::ZERO,
244            partitions: Vec::new(),
245            _unknown_tagged_fields: Vec::new(),
246        }
247    }
248}
249impl FetchableTopicResponse {
250    pub fn with_topic(mut self, value: KafkaString) -> Self {
251        self.topic = value;
252        self
253    }
254    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
255        self.topic_id = value;
256        self
257    }
258    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
259        self.partitions = value;
260        self
261    }
262    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
263        let mut topic = KafkaString::default();
264        let mut topic_id = KafkaUuid::ZERO;
265        let partitions;
266        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
267        if version <= 12 {
268            if version >= 12 {
269                topic = read_compact_string(buf)?;
270            } else {
271                topic = read_string(buf)?;
272            }
273        }
274        if version >= 13 {
275            topic_id = read_uuid(buf)?;
276        }
277        if version >= 12 {
278            partitions = {
279                let len = read_compact_array_length(buf)?;
280                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
281                for _ in 0..len {
282                    arr.push(PartitionData::read(buf, version)?);
283                }
284                arr
285            };
286        } else {
287            partitions = {
288                let len = read_array_length(buf)?;
289                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
290                for _ in 0..len {
291                    arr.push(PartitionData::read(buf, version)?);
292                }
293                arr
294            };
295        }
296        if version >= 12 {
297            let tagged_fields = read_tagged_fields(buf)?;
298            for field in &tagged_fields {
299                match field.tag {
300                    _ => {
301                        _unknown_tagged_fields.push(field.clone());
302                    },
303                }
304            }
305        }
306        Ok(Self {
307            topic,
308            topic_id,
309            partitions,
310            _unknown_tagged_fields,
311        })
312    }
313    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
314        if version <= 12 {
315            if version >= 12 {
316                write_compact_string(buf, &self.topic)?;
317            } else {
318                write_string(buf, &self.topic)?;
319            }
320        } else if self.topic != KafkaString::default() {
321            return Err(UnsupportedFieldVersion::new(1, "topic", version).into());
322        }
323        if version >= 13 {
324            write_uuid(buf, &self.topic_id);
325        } else if self.topic_id != KafkaUuid::ZERO {
326            return Err(UnsupportedFieldVersion::new(1, "topic_id", version).into());
327        }
328        if version >= 12 {
329            write_compact_array_length(buf, self.partitions.len() as i32);
330            for el in &self.partitions {
331                el.write(buf, version)?;
332            }
333        } else {
334            write_array_length(buf, self.partitions.len() as i32);
335            for el in &self.partitions {
336                el.write(buf, version)?;
337            }
338        }
339        if version >= 12 {
340            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
341            all_tags.sort_by_key(|f| f.tag);
342            write_tagged_fields(buf, &all_tags)?;
343        }
344        Ok(())
345    }
346    pub fn encoded_len(&self, version: i16) -> Result<usize> {
347        let mut len: usize = 0;
348        if version <= 12 {
349            if version >= 12 {
350                len += compact_string_len(&self.topic)?;
351            } else {
352                len += string_len(&self.topic)?;
353            }
354        } else if self.topic != KafkaString::default() {
355            return Err(UnsupportedFieldVersion::new(1, "topic", version).into());
356        }
357        if version >= 13 {
358            len += 16;
359        } else if self.topic_id != KafkaUuid::ZERO {
360            return Err(UnsupportedFieldVersion::new(1, "topic_id", version).into());
361        }
362        if version >= 12 {
363            len += compact_array_length_len(self.partitions.len() as i32);
364            for el in &self.partitions {
365                len += el.encoded_len(version)?;
366            }
367        } else {
368            len += array_length_len();
369            for el in &self.partitions {
370                len += el.encoded_len(version)?;
371            }
372        }
373        if version >= 12 {
374            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
375            all_tags.sort_by_key(|f| f.tag);
376            len += tagged_fields_len(&all_tags)?;
377        }
378        Ok(len)
379    }
380}
381#[derive(Debug, Clone, PartialEq)]
382pub struct PartitionData {
383    /// The partition index.
384    pub partition_index: i32,
385    /// The error code, or 0 if there was no fetch error.
386    pub error_code: i16,
387    /// The current high water mark.
388    pub high_watermark: i64,
389    /// The last stable offset (or LSO) of the partition. This is the last offset such that the
390    /// state of all transactional records prior to this offset have been decided (ABORTED or
391    /// COMMITTED).
392    pub last_stable_offset: i64,
393    /// The current log start offset.
394    pub log_start_offset: i64,
395    /// In case divergence is detected based on the `LastFetchedEpoch` and `FetchOffset` in the
396    /// request, this field indicates the largest epoch and its end offset such that subsequent
397    /// records are known to diverge.
398    pub diverging_epoch: EpochEndOffset,
399    /// The current leader of the partition.
400    pub current_leader: LeaderIdAndEpoch,
401    /// In the case of fetching an offset less than the LogStartOffset, this is the end offset and
402    /// epoch that should be used in the FetchSnapshot request.
403    pub snapshot_id: SnapshotId,
404    /// The aborted transactions.
405    pub aborted_transactions: Option<Vec<AbortedTransaction>>,
406    /// The preferred read replica for the consumer to use on its next fetch request.
407    pub preferred_read_replica: i32,
408    /// The record data.
409    pub records: Option<Bytes>,
410    pub _unknown_tagged_fields: Vec<RawTaggedField>,
411}
412impl Default for PartitionData {
413    fn default() -> Self {
414        Self {
415            partition_index: 0_i32,
416            error_code: 0_i16,
417            high_watermark: 0_i64,
418            last_stable_offset: -1i64,
419            log_start_offset: -1i64,
420            diverging_epoch: EpochEndOffset::default(),
421            current_leader: LeaderIdAndEpoch::default(),
422            snapshot_id: SnapshotId::default(),
423            aborted_transactions: None,
424            preferred_read_replica: -1i32,
425            records: None,
426            _unknown_tagged_fields: Vec::new(),
427        }
428    }
429}
430impl PartitionData {
431    pub fn with_partition_index(mut self, value: i32) -> Self {
432        self.partition_index = value;
433        self
434    }
435    pub fn with_error_code(mut self, value: i16) -> Self {
436        self.error_code = value;
437        self
438    }
439    pub fn with_high_watermark(mut self, value: i64) -> Self {
440        self.high_watermark = value;
441        self
442    }
443    pub fn with_last_stable_offset(mut self, value: i64) -> Self {
444        self.last_stable_offset = value;
445        self
446    }
447    pub fn with_log_start_offset(mut self, value: i64) -> Self {
448        self.log_start_offset = value;
449        self
450    }
451    pub fn with_diverging_epoch(mut self, value: EpochEndOffset) -> Self {
452        self.diverging_epoch = value;
453        self
454    }
455    pub fn with_current_leader(mut self, value: LeaderIdAndEpoch) -> Self {
456        self.current_leader = value;
457        self
458    }
459    pub fn with_snapshot_id(mut self, value: SnapshotId) -> Self {
460        self.snapshot_id = value;
461        self
462    }
463    pub fn with_aborted_transactions(mut self, value: Option<Vec<AbortedTransaction>>) -> Self {
464        self.aborted_transactions = value;
465        self
466    }
467    pub fn with_preferred_read_replica(mut self, value: i32) -> Self {
468        self.preferred_read_replica = value;
469        self
470    }
471    pub fn with_records(mut self, value: Option<Bytes>) -> Self {
472        self.records = value;
473        self
474    }
475    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
476        let partition_index;
477        let error_code;
478        let high_watermark;
479        let last_stable_offset;
480        let mut log_start_offset = -1i64;
481        let mut diverging_epoch = EpochEndOffset::default();
482        let mut current_leader = LeaderIdAndEpoch::default();
483        let mut snapshot_id = SnapshotId::default();
484        let aborted_transactions;
485        let mut preferred_read_replica = -1i32;
486        let records;
487        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
488        partition_index = read_i32(buf)?;
489        error_code = read_i16(buf)?;
490        high_watermark = read_i64(buf)?;
491        last_stable_offset = read_i64(buf)?;
492        if version >= 5 {
493            log_start_offset = read_i64(buf)?;
494        }
495        if version >= 12 {
496            aborted_transactions = {
497                let len = read_compact_array_length(buf)?;
498                if len < 0 {
499                    None
500                } else {
501                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
502                    for _ in 0..len {
503                        arr.push(AbortedTransaction::read(buf, version)?);
504                    }
505                    Some(arr)
506                }
507            };
508        } else {
509            aborted_transactions = {
510                let len = read_array_length(buf)?;
511                if len < 0 {
512                    None
513                } else {
514                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
515                    for _ in 0..len {
516                        arr.push(AbortedTransaction::read(buf, version)?);
517                    }
518                    Some(arr)
519                }
520            };
521        }
522        if version >= 11 {
523            preferred_read_replica = read_i32(buf)?;
524        }
525        if version >= 12 {
526            records = read_compact_nullable_bytes(buf)?;
527        } else {
528            records = read_nullable_bytes(buf)?;
529        }
530        if version >= 12 {
531            let tagged_fields = read_tagged_fields(buf)?;
532            for field in &tagged_fields {
533                match field.tag {
534                    0 => {
535                        let mut tag_buf = field.data.clone();
536                        diverging_epoch = EpochEndOffset::read(&mut tag_buf, version)?;
537                    },
538                    1 => {
539                        let mut tag_buf = field.data.clone();
540                        current_leader = LeaderIdAndEpoch::read(&mut tag_buf, version)?;
541                    },
542                    2 => {
543                        let mut tag_buf = field.data.clone();
544                        snapshot_id = SnapshotId::read(&mut tag_buf, version)?;
545                    },
546                    _ => {
547                        _unknown_tagged_fields.push(field.clone());
548                    },
549                }
550            }
551        }
552        Ok(Self {
553            partition_index,
554            error_code,
555            high_watermark,
556            last_stable_offset,
557            log_start_offset,
558            diverging_epoch,
559            current_leader,
560            snapshot_id,
561            aborted_transactions,
562            preferred_read_replica,
563            records,
564            _unknown_tagged_fields,
565        })
566    }
567    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
568        write_i32(buf, self.partition_index);
569        write_i16(buf, self.error_code);
570        write_i64(buf, self.high_watermark);
571        write_i64(buf, self.last_stable_offset);
572        if version >= 5 {
573            write_i64(buf, self.log_start_offset);
574        } else if self.log_start_offset != -1i64 {
575            return Err(UnsupportedFieldVersion::new(1, "log_start_offset", version).into());
576        }
577        if version >= 12 {
578            match &self.aborted_transactions {
579                None => {
580                    write_compact_array_length(buf, -1);
581                },
582                Some(arr) => {
583                    write_compact_array_length(buf, arr.len() as i32);
584                    for el in arr {
585                        el.write(buf, version)?;
586                    }
587                },
588            }
589        } else {
590            match &self.aborted_transactions {
591                None => {
592                    write_array_length(buf, -1);
593                },
594                Some(arr) => {
595                    write_array_length(buf, arr.len() as i32);
596                    for el in arr {
597                        el.write(buf, version)?;
598                    }
599                },
600            }
601        }
602        if version >= 11 {
603            write_i32(buf, self.preferred_read_replica);
604        } else if self.preferred_read_replica != -1i32 {
605            return Err(UnsupportedFieldVersion::new(1, "preferred_read_replica", version).into());
606        }
607        if version >= 12 {
608            write_compact_nullable_bytes(buf, self.records.as_ref().map(|b| b.as_ref()))?;
609        } else {
610            write_nullable_bytes(buf, self.records.as_ref().map(|b| b.as_ref()))?;
611        }
612        if version >= 12 {
613            let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
614            if self.diverging_epoch != EpochEndOffset::default() {
615                let mut tag_buf = BytesMut::new();
616                self.diverging_epoch.write(&mut tag_buf, version)?;
617                known_tagged_fields.push(RawTaggedField {
618                    tag: 0,
619                    data: tag_buf.freeze(),
620                });
621            }
622            if self.current_leader != LeaderIdAndEpoch::default() {
623                let mut tag_buf = BytesMut::new();
624                self.current_leader.write(&mut tag_buf, version)?;
625                known_tagged_fields.push(RawTaggedField {
626                    tag: 1,
627                    data: tag_buf.freeze(),
628                });
629            }
630            if self.snapshot_id != SnapshotId::default() {
631                let mut tag_buf = BytesMut::new();
632                self.snapshot_id.write(&mut tag_buf, version)?;
633                known_tagged_fields.push(RawTaggedField {
634                    tag: 2,
635                    data: tag_buf.freeze(),
636                });
637            }
638            let mut all_tags = known_tagged_fields;
639            all_tags.extend(self._unknown_tagged_fields.iter().cloned());
640            all_tags.sort_by_key(|f| f.tag);
641            write_tagged_fields(buf, &all_tags)?;
642        }
643        Ok(())
644    }
645    pub fn encoded_len(&self, version: i16) -> Result<usize> {
646        let mut len: usize = 0;
647        len += 4;
648        len += 2;
649        len += 8;
650        len += 8;
651        if version >= 5 {
652            len += 8;
653        } else if self.log_start_offset != -1i64 {
654            return Err(UnsupportedFieldVersion::new(1, "log_start_offset", version).into());
655        }
656        if version >= 12 {
657            match &self.aborted_transactions {
658                None => {
659                    len += compact_array_length_len(-1);
660                },
661                Some(arr) => {
662                    len += compact_array_length_len(arr.len() as i32);
663                    for el in arr {
664                        len += el.encoded_len(version)?;
665                    }
666                },
667            }
668        } else {
669            match &self.aborted_transactions {
670                None => {
671                    len += array_length_len();
672                },
673                Some(arr) => {
674                    len += array_length_len();
675                    for el in arr {
676                        len += el.encoded_len(version)?;
677                    }
678                },
679            }
680        }
681        if version >= 11 {
682            len += 4;
683        } else if self.preferred_read_replica != -1i32 {
684            return Err(UnsupportedFieldVersion::new(1, "preferred_read_replica", version).into());
685        }
686        if version >= 12 {
687            len += compact_nullable_bytes_len(self.records.as_ref().map(|b| b.as_ref()))?;
688        } else {
689            len += nullable_bytes_len(self.records.as_ref().map(|b| b.as_ref()))?;
690        }
691        if version >= 12 {
692            let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
693            if self.diverging_epoch != EpochEndOffset::default() {
694                let mut tag_buf = BytesMut::new();
695                self.diverging_epoch.write(&mut tag_buf, version)?;
696                known_tagged_fields.push(RawTaggedField {
697                    tag: 0,
698                    data: tag_buf.freeze(),
699                });
700            }
701            if self.current_leader != LeaderIdAndEpoch::default() {
702                let mut tag_buf = BytesMut::new();
703                self.current_leader.write(&mut tag_buf, version)?;
704                known_tagged_fields.push(RawTaggedField {
705                    tag: 1,
706                    data: tag_buf.freeze(),
707                });
708            }
709            if self.snapshot_id != SnapshotId::default() {
710                let mut tag_buf = BytesMut::new();
711                self.snapshot_id.write(&mut tag_buf, version)?;
712                known_tagged_fields.push(RawTaggedField {
713                    tag: 2,
714                    data: tag_buf.freeze(),
715                });
716            }
717            let mut all_tags = known_tagged_fields;
718            all_tags.extend(self._unknown_tagged_fields.iter().cloned());
719            all_tags.sort_by_key(|f| f.tag);
720            len += tagged_fields_len(&all_tags)?;
721        }
722        Ok(len)
723    }
724}
725#[derive(Debug, Clone, PartialEq)]
726pub struct EpochEndOffset {
727    /// The largest epoch.
728    pub epoch: i32,
729    /// The end offset of the epoch.
730    pub end_offset: i64,
731    pub _unknown_tagged_fields: Vec<RawTaggedField>,
732}
733impl Default for EpochEndOffset {
734    fn default() -> Self {
735        Self {
736            epoch: -1i32,
737            end_offset: -1i64,
738            _unknown_tagged_fields: Vec::new(),
739        }
740    }
741}
742impl EpochEndOffset {
743    pub fn with_epoch(mut self, value: i32) -> Self {
744        self.epoch = value;
745        self
746    }
747    pub fn with_end_offset(mut self, value: i64) -> Self {
748        self.end_offset = value;
749        self
750    }
751    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
752        let epoch;
753        let end_offset;
754        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
755        epoch = read_i32(buf)?;
756        end_offset = read_i64(buf)?;
757        let tagged_fields = read_tagged_fields(buf)?;
758        for field in &tagged_fields {
759            match field.tag {
760                _ => {
761                    _unknown_tagged_fields.push(field.clone());
762                },
763            }
764        }
765        Ok(Self {
766            epoch,
767            end_offset,
768            _unknown_tagged_fields,
769        })
770    }
771    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
772        write_i32(buf, self.epoch);
773        write_i64(buf, self.end_offset);
774        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
775        all_tags.sort_by_key(|f| f.tag);
776        write_tagged_fields(buf, &all_tags)?;
777        Ok(())
778    }
779    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
780        let mut len: usize = 0;
781        len += 4;
782        len += 8;
783        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
784        all_tags.sort_by_key(|f| f.tag);
785        len += tagged_fields_len(&all_tags)?;
786        Ok(len)
787    }
788}
789#[derive(Debug, Clone, PartialEq)]
790pub struct LeaderIdAndEpoch {
791    /// The ID of the current leader or -1 if the leader is unknown.
792    pub leader_id: i32,
793    /// The latest known leader epoch.
794    pub leader_epoch: i32,
795    pub _unknown_tagged_fields: Vec<RawTaggedField>,
796}
797impl Default for LeaderIdAndEpoch {
798    fn default() -> Self {
799        Self {
800            leader_id: -1i32,
801            leader_epoch: -1i32,
802            _unknown_tagged_fields: Vec::new(),
803        }
804    }
805}
806impl LeaderIdAndEpoch {
807    pub fn with_leader_id(mut self, value: i32) -> Self {
808        self.leader_id = value;
809        self
810    }
811    pub fn with_leader_epoch(mut self, value: i32) -> Self {
812        self.leader_epoch = value;
813        self
814    }
815    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
816        let leader_id;
817        let leader_epoch;
818        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
819        leader_id = read_i32(buf)?;
820        leader_epoch = read_i32(buf)?;
821        let tagged_fields = read_tagged_fields(buf)?;
822        for field in &tagged_fields {
823            match field.tag {
824                _ => {
825                    _unknown_tagged_fields.push(field.clone());
826                },
827            }
828        }
829        Ok(Self {
830            leader_id,
831            leader_epoch,
832            _unknown_tagged_fields,
833        })
834    }
835    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
836        write_i32(buf, self.leader_id);
837        write_i32(buf, self.leader_epoch);
838        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
839        all_tags.sort_by_key(|f| f.tag);
840        write_tagged_fields(buf, &all_tags)?;
841        Ok(())
842    }
843    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
844        let mut len: usize = 0;
845        len += 4;
846        len += 4;
847        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
848        all_tags.sort_by_key(|f| f.tag);
849        len += tagged_fields_len(&all_tags)?;
850        Ok(len)
851    }
852}
853#[derive(Debug, Clone, PartialEq)]
854pub struct SnapshotId {
855    /// The end offset of the epoch.
856    pub end_offset: i64,
857    /// The largest epoch.
858    pub epoch: i32,
859    pub _unknown_tagged_fields: Vec<RawTaggedField>,
860}
861impl Default for SnapshotId {
862    fn default() -> Self {
863        Self {
864            end_offset: -1i64,
865            epoch: -1i32,
866            _unknown_tagged_fields: Vec::new(),
867        }
868    }
869}
870impl SnapshotId {
871    pub fn with_end_offset(mut self, value: i64) -> Self {
872        self.end_offset = value;
873        self
874    }
875    pub fn with_epoch(mut self, value: i32) -> Self {
876        self.epoch = value;
877        self
878    }
879    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
880        let end_offset;
881        let epoch;
882        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
883        end_offset = read_i64(buf)?;
884        epoch = read_i32(buf)?;
885        let tagged_fields = read_tagged_fields(buf)?;
886        for field in &tagged_fields {
887            match field.tag {
888                _ => {
889                    _unknown_tagged_fields.push(field.clone());
890                },
891            }
892        }
893        Ok(Self {
894            end_offset,
895            epoch,
896            _unknown_tagged_fields,
897        })
898    }
899    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
900        write_i64(buf, self.end_offset);
901        write_i32(buf, self.epoch);
902        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
903        all_tags.sort_by_key(|f| f.tag);
904        write_tagged_fields(buf, &all_tags)?;
905        Ok(())
906    }
907    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
908        let mut len: usize = 0;
909        len += 8;
910        len += 4;
911        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
912        all_tags.sort_by_key(|f| f.tag);
913        len += tagged_fields_len(&all_tags)?;
914        Ok(len)
915    }
916}
917#[derive(Debug, Clone, PartialEq)]
918pub struct AbortedTransaction {
919    /// The producer id associated with the aborted transaction.
920    pub producer_id: i64,
921    /// The first offset in the aborted transaction.
922    pub first_offset: i64,
923    pub _unknown_tagged_fields: Vec<RawTaggedField>,
924}
925impl Default for AbortedTransaction {
926    fn default() -> Self {
927        Self {
928            producer_id: 0_i64,
929            first_offset: 0_i64,
930            _unknown_tagged_fields: Vec::new(),
931        }
932    }
933}
934impl AbortedTransaction {
935    pub fn with_producer_id(mut self, value: i64) -> Self {
936        self.producer_id = value;
937        self
938    }
939    pub fn with_first_offset(mut self, value: i64) -> Self {
940        self.first_offset = value;
941        self
942    }
943    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
944        let producer_id;
945        let first_offset;
946        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
947        producer_id = read_i64(buf)?;
948        first_offset = read_i64(buf)?;
949        if version >= 12 {
950            let tagged_fields = read_tagged_fields(buf)?;
951            for field in &tagged_fields {
952                match field.tag {
953                    _ => {
954                        _unknown_tagged_fields.push(field.clone());
955                    },
956                }
957            }
958        }
959        Ok(Self {
960            producer_id,
961            first_offset,
962            _unknown_tagged_fields,
963        })
964    }
965    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
966        write_i64(buf, self.producer_id);
967        write_i64(buf, self.first_offset);
968        if version >= 12 {
969            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
970            all_tags.sort_by_key(|f| f.tag);
971            write_tagged_fields(buf, &all_tags)?;
972        }
973        Ok(())
974    }
975    pub fn encoded_len(&self, version: i16) -> Result<usize> {
976        let mut len: usize = 0;
977        len += 8;
978        len += 8;
979        if version >= 12 {
980            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
981            all_tags.sort_by_key(|f| f.tag);
982            len += tagged_fields_len(&all_tags)?;
983        }
984        Ok(len)
985    }
986}
987#[derive(Debug, Clone, PartialEq)]
988pub struct NodeEndpoint {
989    /// The ID of the associated node.
990    pub node_id: i32,
991    /// The node's hostname.
992    pub host: KafkaString,
993    /// The node's port.
994    pub port: i32,
995    /// The rack of the node, or null if it has not been assigned to a rack.
996    pub rack: Option<KafkaString>,
997    pub _unknown_tagged_fields: Vec<RawTaggedField>,
998}
999impl Default for NodeEndpoint {
1000    fn default() -> Self {
1001        Self {
1002            node_id: 0_i32,
1003            host: KafkaString::default(),
1004            port: 0_i32,
1005            rack: None,
1006            _unknown_tagged_fields: Vec::new(),
1007        }
1008    }
1009}
1010impl NodeEndpoint {
1011    pub fn with_node_id(mut self, value: i32) -> Self {
1012        self.node_id = value;
1013        self
1014    }
1015    pub fn with_host(mut self, value: KafkaString) -> Self {
1016        self.host = value;
1017        self
1018    }
1019    pub fn with_port(mut self, value: i32) -> Self {
1020        self.port = value;
1021        self
1022    }
1023    pub fn with_rack(mut self, value: Option<KafkaString>) -> Self {
1024        self.rack = value;
1025        self
1026    }
1027    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
1028        let node_id;
1029        let host;
1030        let port;
1031        let rack;
1032        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
1033        node_id = read_i32(buf)?;
1034        host = read_compact_string(buf)?;
1035        port = read_i32(buf)?;
1036        rack = read_compact_nullable_string(buf)?;
1037        let tagged_fields = read_tagged_fields(buf)?;
1038        for field in &tagged_fields {
1039            match field.tag {
1040                _ => {
1041                    _unknown_tagged_fields.push(field.clone());
1042                },
1043            }
1044        }
1045        Ok(Self {
1046            node_id,
1047            host,
1048            port,
1049            rack,
1050            _unknown_tagged_fields,
1051        })
1052    }
1053    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
1054        write_i32(buf, self.node_id);
1055        write_compact_string(buf, &self.host)?;
1056        write_i32(buf, self.port);
1057        write_compact_nullable_string(buf, self.rack.as_ref())?;
1058        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
1059        all_tags.sort_by_key(|f| f.tag);
1060        write_tagged_fields(buf, &all_tags)?;
1061        Ok(())
1062    }
1063    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
1064        let mut len: usize = 0;
1065        len += 4;
1066        len += compact_string_len(&self.host)?;
1067        len += 4;
1068        len += compact_nullable_string_len(self.rack.as_ref())?;
1069        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
1070        all_tags.sort_by_key(|f| f.tag);
1071        len += tagged_fields_len(&all_tags)?;
1072        Ok(len)
1073    }
1074}