Skip to main content

odradek_protocol/messages/
offset_fetch_response.rs

1//! `OffsetFetchResponse` — generated from `schemas/OffsetFetchResponse.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 6
25}
26
27/// `OffsetFetchResponse`, versions 1-10.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct OffsetFetchResponse {
31    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
32    pub throttle_time_ms: i32,
33    /// The responses per topic.
34    pub topics: Vec<OffsetFetchResponseTopic>,
35    /// The top-level error code, or 0 if there was no error.
36    pub error_code: i16,
37    /// The responses per group id.
38    pub groups: Vec<OffsetFetchResponseGroup>,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for OffsetFetchResponse {
44    fn default() -> Self {
45        Self {
46            throttle_time_ms: 0,
47            topics: Vec::new(),
48            error_code: 0,
49            groups: Vec::new(),
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl OffsetFetchResponse {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 9;
58    /// The lowest schema version this snapshot can speak.
59    pub const MIN_VERSION: i16 = 1;
60    /// The highest schema version this snapshot can speak.
61    pub const MAX_VERSION: i16 = 10;
62
63    /// Encode this `OffsetFetchResponse` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        if version >= 3 {
66            buf.put_i32(self.throttle_time_ms);
67        }
68        if version <= 7 {
69            if is_flexible(version) {
70                wire::put_compact_array_len(buf, Some(self.topics.len()));
71            } else {
72                wire::put_array_len(buf, Some(self.topics.len()))?;
73            }
74            for item in &self.topics {
75                item.encode(buf, version)?;
76            }
77        }
78        if (2..=7).contains(&version) {
79            buf.put_i16(self.error_code);
80        }
81        if version >= 8 {
82            if is_flexible(version) {
83                wire::put_compact_array_len(buf, Some(self.groups.len()));
84            } else {
85                wire::put_array_len(buf, Some(self.groups.len()))?;
86            }
87            for item in &self.groups {
88                item.encode(buf, version)?;
89            }
90        }
91        if is_flexible(version) {
92            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
93        }
94        Ok(())
95    }
96
97    /// Decode one `OffsetFetchResponse`, bounding allocation by the default
98    /// [`Limits`] derived from `buf`'s remaining length.
99    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
100        Self::decode_with_limits(buf, version, Limits::default())
101    }
102
103    /// Decode one `OffsetFetchResponse` under `limits`.
104    pub fn decode_with_limits(
105        buf: &mut impl Buf,
106        version: i16,
107        limits: Limits,
108    ) -> Result<Self, DecodeError> {
109        let mut budget = limits.budget(buf.remaining());
110        Self::decode_with_budget(buf, version, &mut budget)
111    }
112
113    /// Decode one `OffsetFetchResponse` against an existing `budget`.
114    pub fn decode_with_budget(
115        buf: &mut impl Buf,
116        version: i16,
117        budget: &mut Budget,
118    ) -> Result<Self, DecodeError> {
119        let mut this = Self::default();
120        if version >= 3 {
121            this.throttle_time_ms = wire::get_i32(buf)?;
122        }
123        if version <= 7 {
124            this.topics = {
125                let len = if is_flexible(version) {
126                    wire::get_compact_array_len(buf)?
127                } else {
128                    wire::get_array_len(buf)?
129                };
130                match len {
131                    None => return Err(DecodeError::InvalidLength(-1)),
132                    Some(n) => {
133                        let mut items = Vec::new();
134                        for _ in 0..n {
135                            let mark = buf.remaining();
136                            let item =
137                                OffsetFetchResponseTopic::decode_with_budget(buf, version, budget)?;
138                            budget.progress(mark, buf.remaining())?;
139                            budget.push(&mut items, item)?;
140                        }
141                        items
142                    }
143                }
144            };
145        }
146        if (2..=7).contains(&version) {
147            this.error_code = wire::get_i16(buf)?;
148        }
149        if version >= 8 {
150            this.groups = {
151                let len = if is_flexible(version) {
152                    wire::get_compact_array_len(buf)?
153                } else {
154                    wire::get_array_len(buf)?
155                };
156                match len {
157                    None => return Err(DecodeError::InvalidLength(-1)),
158                    Some(n) => {
159                        let mut items = Vec::new();
160                        for _ in 0..n {
161                            let mark = buf.remaining();
162                            let item =
163                                OffsetFetchResponseGroup::decode_with_budget(buf, version, budget)?;
164                            budget.progress(mark, buf.remaining())?;
165                            budget.push(&mut items, item)?;
166                        }
167                        items
168                    }
169                }
170            };
171        }
172        if is_flexible(version) {
173            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
174        }
175        Ok(this)
176    }
177}
178
179impl crate::Message for OffsetFetchResponse {
180    const API_KEY: i16 = 9;
181    const MIN_VERSION: i16 = 1;
182    const MAX_VERSION: i16 = 10;
183
184    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
185        OffsetFetchResponse::encode(self, buf, version)
186    }
187    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
188        OffsetFetchResponse::decode(buf, version)
189    }
190    fn decode_with_limits(
191        buf: &mut impl Buf,
192        version: i16,
193        limits: Limits,
194    ) -> Result<Self, DecodeError> {
195        OffsetFetchResponse::decode_with_limits(buf, version, limits)
196    }
197    fn throttle_time_ms(&self) -> Option<i32> {
198        Some(self.throttle_time_ms)
199    }
200}
201
202/// `OffsetFetchResponseTopic` (nested in [`OffsetFetchResponse`]).
203#[derive(Debug, Clone, PartialEq)]
204#[non_exhaustive]
205pub struct OffsetFetchResponseTopic {
206    /// The topic name.
207    pub name: String,
208    /// The responses per partition.
209    pub partitions: Vec<OffsetFetchResponsePartition>,
210    /// Tagged fields not (yet) known to this crate, kept raw.
211    pub unknown_tagged_fields: Vec<RawTaggedField>,
212}
213
214impl Default for OffsetFetchResponseTopic {
215    fn default() -> Self {
216        Self {
217            name: String::new(),
218            partitions: Vec::new(),
219            unknown_tagged_fields: Vec::new(),
220        }
221    }
222}
223
224impl OffsetFetchResponseTopic {
225    /// Encode this `OffsetFetchResponseTopic` at `version`.
226    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
227        if version <= 7 {
228            if is_flexible(version) {
229                wire::put_compact_string(buf, &self.name);
230            } else {
231                wire::put_string(buf, &self.name)?;
232            }
233        }
234        if version <= 7 {
235            if is_flexible(version) {
236                wire::put_compact_array_len(buf, Some(self.partitions.len()));
237            } else {
238                wire::put_array_len(buf, Some(self.partitions.len()))?;
239            }
240            for item in &self.partitions {
241                item.encode(buf, version)?;
242            }
243        }
244        if is_flexible(version) {
245            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
246        }
247        Ok(())
248    }
249
250    /// Decode one `OffsetFetchResponseTopic`, bounding allocation by the default
251    /// [`Limits`] derived from `buf`'s remaining length.
252    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
253        Self::decode_with_limits(buf, version, Limits::default())
254    }
255
256    /// Decode one `OffsetFetchResponseTopic` under `limits`.
257    pub fn decode_with_limits(
258        buf: &mut impl Buf,
259        version: i16,
260        limits: Limits,
261    ) -> Result<Self, DecodeError> {
262        let mut budget = limits.budget(buf.remaining());
263        Self::decode_with_budget(buf, version, &mut budget)
264    }
265
266    /// Decode one `OffsetFetchResponseTopic` against an existing `budget`.
267    pub fn decode_with_budget(
268        buf: &mut impl Buf,
269        version: i16,
270        budget: &mut Budget,
271    ) -> Result<Self, DecodeError> {
272        let mut this = Self::default();
273        if version <= 7 {
274            this.name = if is_flexible(version) {
275                wire::get_compact_string(buf)?
276            } else {
277                wire::get_string(buf)?
278            };
279        }
280        if version <= 7 {
281            this.partitions = {
282                let len = if is_flexible(version) {
283                    wire::get_compact_array_len(buf)?
284                } else {
285                    wire::get_array_len(buf)?
286                };
287                match len {
288                    None => return Err(DecodeError::InvalidLength(-1)),
289                    Some(n) => {
290                        let mut items = Vec::new();
291                        for _ in 0..n {
292                            let mark = buf.remaining();
293                            let item = OffsetFetchResponsePartition::decode_with_budget(
294                                buf, version, budget,
295                            )?;
296                            budget.progress(mark, buf.remaining())?;
297                            budget.push(&mut items, item)?;
298                        }
299                        items
300                    }
301                }
302            };
303        }
304        if is_flexible(version) {
305            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
306        }
307        Ok(this)
308    }
309}
310
311/// `OffsetFetchResponsePartition` (nested in [`OffsetFetchResponse`]).
312#[derive(Debug, Clone, PartialEq)]
313#[non_exhaustive]
314pub struct OffsetFetchResponsePartition {
315    /// The partition index.
316    pub partition_index: i32,
317    /// The committed message offset.
318    pub committed_offset: i64,
319    /// The leader epoch.
320    pub committed_leader_epoch: i32,
321    /// The partition metadata.
322    pub metadata: Option<String>,
323    /// The error code, or 0 if there was no error.
324    pub error_code: i16,
325    /// Tagged fields not (yet) known to this crate, kept raw.
326    pub unknown_tagged_fields: Vec<RawTaggedField>,
327}
328
329impl Default for OffsetFetchResponsePartition {
330    fn default() -> Self {
331        Self {
332            partition_index: 0,
333            committed_offset: 0,
334            committed_leader_epoch: -1,
335            metadata: Some(String::new()),
336            error_code: 0,
337            unknown_tagged_fields: Vec::new(),
338        }
339    }
340}
341
342impl OffsetFetchResponsePartition {
343    /// Encode this `OffsetFetchResponsePartition` at `version`.
344    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
345        if version <= 7 {
346            buf.put_i32(self.partition_index);
347        }
348        if version <= 7 {
349            buf.put_i64(self.committed_offset);
350        }
351        if (5..=7).contains(&version) {
352            buf.put_i32(self.committed_leader_epoch);
353        }
354        if version <= 7 {
355            if is_flexible(version) {
356                wire::put_compact_nullable_string(buf, self.metadata.as_deref());
357            } else {
358                wire::put_nullable_string(buf, self.metadata.as_deref())?;
359            }
360        }
361        if version <= 7 {
362            buf.put_i16(self.error_code);
363        }
364        if is_flexible(version) {
365            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
366        }
367        Ok(())
368    }
369
370    /// Decode one `OffsetFetchResponsePartition`, bounding allocation by the default
371    /// [`Limits`] derived from `buf`'s remaining length.
372    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
373        Self::decode_with_limits(buf, version, Limits::default())
374    }
375
376    /// Decode one `OffsetFetchResponsePartition` under `limits`.
377    pub fn decode_with_limits(
378        buf: &mut impl Buf,
379        version: i16,
380        limits: Limits,
381    ) -> Result<Self, DecodeError> {
382        let mut budget = limits.budget(buf.remaining());
383        Self::decode_with_budget(buf, version, &mut budget)
384    }
385
386    /// Decode one `OffsetFetchResponsePartition` against an existing `budget`.
387    pub fn decode_with_budget(
388        buf: &mut impl Buf,
389        version: i16,
390        budget: &mut Budget,
391    ) -> Result<Self, DecodeError> {
392        let mut this = Self::default();
393        if version <= 7 {
394            this.partition_index = wire::get_i32(buf)?;
395        }
396        if version <= 7 {
397            this.committed_offset = wire::get_i64(buf)?;
398        }
399        if (5..=7).contains(&version) {
400            this.committed_leader_epoch = wire::get_i32(buf)?;
401        }
402        if version <= 7 {
403            this.metadata = if is_flexible(version) {
404                wire::get_compact_nullable_string(buf)?
405            } else {
406                wire::get_nullable_string(buf)?
407            };
408        }
409        if version <= 7 {
410            this.error_code = wire::get_i16(buf)?;
411        }
412        if is_flexible(version) {
413            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
414        }
415        Ok(this)
416    }
417}
418
419/// `OffsetFetchResponseGroup` (nested in [`OffsetFetchResponse`]).
420#[derive(Debug, Clone, PartialEq)]
421#[non_exhaustive]
422pub struct OffsetFetchResponseGroup {
423    /// The group ID.
424    pub group_id: String,
425    /// The responses per topic.
426    pub topics: Vec<OffsetFetchResponseTopics>,
427    /// The group-level error code, or 0 if there was no error.
428    pub error_code: i16,
429    /// Tagged fields not (yet) known to this crate, kept raw.
430    pub unknown_tagged_fields: Vec<RawTaggedField>,
431}
432
433impl Default for OffsetFetchResponseGroup {
434    fn default() -> Self {
435        Self {
436            group_id: String::new(),
437            topics: Vec::new(),
438            error_code: 0,
439            unknown_tagged_fields: Vec::new(),
440        }
441    }
442}
443
444impl OffsetFetchResponseGroup {
445    /// Encode this `OffsetFetchResponseGroup` at `version`.
446    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
447        if version >= 8 {
448            if is_flexible(version) {
449                wire::put_compact_string(buf, &self.group_id);
450            } else {
451                wire::put_string(buf, &self.group_id)?;
452            }
453        }
454        if version >= 8 {
455            if is_flexible(version) {
456                wire::put_compact_array_len(buf, Some(self.topics.len()));
457            } else {
458                wire::put_array_len(buf, Some(self.topics.len()))?;
459            }
460            for item in &self.topics {
461                item.encode(buf, version)?;
462            }
463        }
464        if version >= 8 {
465            buf.put_i16(self.error_code);
466        }
467        if is_flexible(version) {
468            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
469        }
470        Ok(())
471    }
472
473    /// Decode one `OffsetFetchResponseGroup`, bounding allocation by the default
474    /// [`Limits`] derived from `buf`'s remaining length.
475    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
476        Self::decode_with_limits(buf, version, Limits::default())
477    }
478
479    /// Decode one `OffsetFetchResponseGroup` under `limits`.
480    pub fn decode_with_limits(
481        buf: &mut impl Buf,
482        version: i16,
483        limits: Limits,
484    ) -> Result<Self, DecodeError> {
485        let mut budget = limits.budget(buf.remaining());
486        Self::decode_with_budget(buf, version, &mut budget)
487    }
488
489    /// Decode one `OffsetFetchResponseGroup` against an existing `budget`.
490    pub fn decode_with_budget(
491        buf: &mut impl Buf,
492        version: i16,
493        budget: &mut Budget,
494    ) -> Result<Self, DecodeError> {
495        let mut this = Self::default();
496        if version >= 8 {
497            this.group_id = if is_flexible(version) {
498                wire::get_compact_string(buf)?
499            } else {
500                wire::get_string(buf)?
501            };
502        }
503        if version >= 8 {
504            this.topics = {
505                let len = if is_flexible(version) {
506                    wire::get_compact_array_len(buf)?
507                } else {
508                    wire::get_array_len(buf)?
509                };
510                match len {
511                    None => return Err(DecodeError::InvalidLength(-1)),
512                    Some(n) => {
513                        let mut items = Vec::new();
514                        for _ in 0..n {
515                            let mark = buf.remaining();
516                            let item = OffsetFetchResponseTopics::decode_with_budget(
517                                buf, version, budget,
518                            )?;
519                            budget.progress(mark, buf.remaining())?;
520                            budget.push(&mut items, item)?;
521                        }
522                        items
523                    }
524                }
525            };
526        }
527        if version >= 8 {
528            this.error_code = wire::get_i16(buf)?;
529        }
530        if is_flexible(version) {
531            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
532        }
533        Ok(this)
534    }
535}
536
537/// `OffsetFetchResponseTopics` (nested in [`OffsetFetchResponse`]).
538#[derive(Debug, Clone, PartialEq)]
539#[non_exhaustive]
540pub struct OffsetFetchResponseTopics {
541    /// The topic name.
542    pub name: String,
543    /// The topic ID.
544    pub topic_id: [u8; 16],
545    /// The responses per partition.
546    pub partitions: Vec<OffsetFetchResponsePartitions>,
547    /// Tagged fields not (yet) known to this crate, kept raw.
548    pub unknown_tagged_fields: Vec<RawTaggedField>,
549}
550
551impl Default for OffsetFetchResponseTopics {
552    fn default() -> Self {
553        Self {
554            name: String::new(),
555            topic_id: [0u8; 16],
556            partitions: Vec::new(),
557            unknown_tagged_fields: Vec::new(),
558        }
559    }
560}
561
562impl OffsetFetchResponseTopics {
563    /// Encode this `OffsetFetchResponseTopics` at `version`.
564    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
565        if (8..=9).contains(&version) {
566            if is_flexible(version) {
567                wire::put_compact_string(buf, &self.name);
568            } else {
569                wire::put_string(buf, &self.name)?;
570            }
571        }
572        if version >= 10 {
573            wire::put_uuid(buf, self.topic_id);
574        }
575        if version >= 8 {
576            if is_flexible(version) {
577                wire::put_compact_array_len(buf, Some(self.partitions.len()));
578            } else {
579                wire::put_array_len(buf, Some(self.partitions.len()))?;
580            }
581            for item in &self.partitions {
582                item.encode(buf, version)?;
583            }
584        }
585        if is_flexible(version) {
586            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
587        }
588        Ok(())
589    }
590
591    /// Decode one `OffsetFetchResponseTopics`, bounding allocation by the default
592    /// [`Limits`] derived from `buf`'s remaining length.
593    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
594        Self::decode_with_limits(buf, version, Limits::default())
595    }
596
597    /// Decode one `OffsetFetchResponseTopics` under `limits`.
598    pub fn decode_with_limits(
599        buf: &mut impl Buf,
600        version: i16,
601        limits: Limits,
602    ) -> Result<Self, DecodeError> {
603        let mut budget = limits.budget(buf.remaining());
604        Self::decode_with_budget(buf, version, &mut budget)
605    }
606
607    /// Decode one `OffsetFetchResponseTopics` against an existing `budget`.
608    pub fn decode_with_budget(
609        buf: &mut impl Buf,
610        version: i16,
611        budget: &mut Budget,
612    ) -> Result<Self, DecodeError> {
613        let mut this = Self::default();
614        if (8..=9).contains(&version) {
615            this.name = if is_flexible(version) {
616                wire::get_compact_string(buf)?
617            } else {
618                wire::get_string(buf)?
619            };
620        }
621        if version >= 10 {
622            this.topic_id = wire::get_uuid(buf)?;
623        }
624        if version >= 8 {
625            this.partitions = {
626                let len = if is_flexible(version) {
627                    wire::get_compact_array_len(buf)?
628                } else {
629                    wire::get_array_len(buf)?
630                };
631                match len {
632                    None => return Err(DecodeError::InvalidLength(-1)),
633                    Some(n) => {
634                        let mut items = Vec::new();
635                        for _ in 0..n {
636                            let mark = buf.remaining();
637                            let item = OffsetFetchResponsePartitions::decode_with_budget(
638                                buf, version, budget,
639                            )?;
640                            budget.progress(mark, buf.remaining())?;
641                            budget.push(&mut items, item)?;
642                        }
643                        items
644                    }
645                }
646            };
647        }
648        if is_flexible(version) {
649            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
650        }
651        Ok(this)
652    }
653}
654
655/// `OffsetFetchResponsePartitions` (nested in [`OffsetFetchResponse`]).
656#[derive(Debug, Clone, PartialEq)]
657#[non_exhaustive]
658pub struct OffsetFetchResponsePartitions {
659    /// The partition index.
660    pub partition_index: i32,
661    /// The committed message offset.
662    pub committed_offset: i64,
663    /// The leader epoch.
664    pub committed_leader_epoch: i32,
665    /// The partition metadata.
666    pub metadata: Option<String>,
667    /// The partition-level error code, or 0 if there was no error.
668    pub error_code: i16,
669    /// Tagged fields not (yet) known to this crate, kept raw.
670    pub unknown_tagged_fields: Vec<RawTaggedField>,
671}
672
673impl Default for OffsetFetchResponsePartitions {
674    fn default() -> Self {
675        Self {
676            partition_index: 0,
677            committed_offset: 0,
678            committed_leader_epoch: -1,
679            metadata: Some(String::new()),
680            error_code: 0,
681            unknown_tagged_fields: Vec::new(),
682        }
683    }
684}
685
686impl OffsetFetchResponsePartitions {
687    /// Encode this `OffsetFetchResponsePartitions` at `version`.
688    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
689        if version >= 8 {
690            buf.put_i32(self.partition_index);
691        }
692        if version >= 8 {
693            buf.put_i64(self.committed_offset);
694        }
695        if version >= 8 {
696            buf.put_i32(self.committed_leader_epoch);
697        }
698        if version >= 8 {
699            if is_flexible(version) {
700                wire::put_compact_nullable_string(buf, self.metadata.as_deref());
701            } else {
702                wire::put_nullable_string(buf, self.metadata.as_deref())?;
703            }
704        }
705        if version >= 8 {
706            buf.put_i16(self.error_code);
707        }
708        if is_flexible(version) {
709            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
710        }
711        Ok(())
712    }
713
714    /// Decode one `OffsetFetchResponsePartitions`, bounding allocation by the default
715    /// [`Limits`] derived from `buf`'s remaining length.
716    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
717        Self::decode_with_limits(buf, version, Limits::default())
718    }
719
720    /// Decode one `OffsetFetchResponsePartitions` under `limits`.
721    pub fn decode_with_limits(
722        buf: &mut impl Buf,
723        version: i16,
724        limits: Limits,
725    ) -> Result<Self, DecodeError> {
726        let mut budget = limits.budget(buf.remaining());
727        Self::decode_with_budget(buf, version, &mut budget)
728    }
729
730    /// Decode one `OffsetFetchResponsePartitions` against an existing `budget`.
731    pub fn decode_with_budget(
732        buf: &mut impl Buf,
733        version: i16,
734        budget: &mut Budget,
735    ) -> Result<Self, DecodeError> {
736        let mut this = Self::default();
737        if version >= 8 {
738            this.partition_index = wire::get_i32(buf)?;
739        }
740        if version >= 8 {
741            this.committed_offset = wire::get_i64(buf)?;
742        }
743        if version >= 8 {
744            this.committed_leader_epoch = wire::get_i32(buf)?;
745        }
746        if version >= 8 {
747            this.metadata = if is_flexible(version) {
748                wire::get_compact_nullable_string(buf)?
749            } else {
750                wire::get_nullable_string(buf)?
751            };
752        }
753        if version >= 8 {
754            this.error_code = wire::get_i16(buf)?;
755        }
756        if is_flexible(version) {
757            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
758        }
759        Ok(this)
760    }
761}