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