Skip to main content

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

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