Skip to main content

odradek_protocol/messages/
list_offsets_request.rs

1//! `ListOffsetsRequest` — generated from `schemas/ListOffsetsRequest.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/// `ListOffsetsRequest`, versions 1-10.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ListOffsetsRequest {
31    /// The broker ID of the requester, or -1 if this request is being made by a normal consumer.
32    pub replica_id: i32,
33    /// This setting controls the visibility of transactional records. Using READ_UNCOMMITTED (isolation_level = 0) makes all records visible. With READ_COMMITTED (isolation_level = 1), non-transactional and COMMITTED transactional records are visible. To be more concrete, READ_COMMITTED returns all data from offsets smaller than the current LSO (last stable offset), and enables the inclusion of the list of aborted transactions in the result, which allows consumers to discard ABORTED transactional records.
34    pub isolation_level: i8,
35    /// Each topic in the request.
36    pub topics: Vec<ListOffsetsTopic>,
37    /// The timeout to await a response in milliseconds for requests that require reading from remote storage for topics enabled with tiered storage.
38    pub timeout_ms: i32,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for ListOffsetsRequest {
44    fn default() -> Self {
45        Self {
46            replica_id: 0,
47            isolation_level: 0,
48            topics: Vec::new(),
49            timeout_ms: 0,
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl ListOffsetsRequest {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 2;
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 `ListOffsetsRequest` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        buf.put_i32(self.replica_id);
66        if version >= 2 {
67            buf.put_i8(self.isolation_level);
68        }
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        if version >= 10 {
78            buf.put_i32(self.timeout_ms);
79        }
80        if is_flexible(version) {
81            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
82        }
83        Ok(())
84    }
85
86    /// Decode one `ListOffsetsRequest`, bounding allocation by the default
87    /// [`Limits`] derived from `buf`'s remaining length.
88    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
89        Self::decode_with_limits(buf, version, Limits::default())
90    }
91
92    /// Decode one `ListOffsetsRequest` under `limits`.
93    pub fn decode_with_limits(
94        buf: &mut impl Buf,
95        version: i16,
96        limits: Limits,
97    ) -> Result<Self, DecodeError> {
98        let mut budget = limits.budget(buf.remaining());
99        Self::decode_with_budget(buf, version, &mut budget)
100    }
101
102    /// Decode one `ListOffsetsRequest` against an existing `budget`.
103    pub fn decode_with_budget(
104        buf: &mut impl Buf,
105        version: i16,
106        budget: &mut Budget,
107    ) -> Result<Self, DecodeError> {
108        let mut this = Self::default();
109        this.replica_id = wire::get_i32(buf)?;
110        if version >= 2 {
111            this.isolation_level = wire::get_i8(buf)?;
112        }
113        this.topics = {
114            let len = if is_flexible(version) {
115                wire::get_compact_array_len(buf)?
116            } else {
117                wire::get_array_len(buf)?
118            };
119            match len {
120                None => return Err(DecodeError::InvalidLength(-1)),
121                Some(n) => {
122                    let mut items = Vec::new();
123                    for _ in 0..n {
124                        let mark = buf.remaining();
125                        let item = ListOffsetsTopic::decode_with_budget(buf, version, budget)?;
126                        budget.progress(mark, buf.remaining())?;
127                        budget.push(&mut items, item)?;
128                    }
129                    items
130                }
131            }
132        };
133        if version >= 10 {
134            this.timeout_ms = wire::get_i32(buf)?;
135        }
136        if is_flexible(version) {
137            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
138        }
139        Ok(this)
140    }
141}
142
143impl crate::Message for ListOffsetsRequest {
144    const API_KEY: i16 = 2;
145    const MIN_VERSION: i16 = 1;
146    const MAX_VERSION: i16 = 10;
147
148    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
149        ListOffsetsRequest::encode(self, buf, version)
150    }
151    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
152        ListOffsetsRequest::decode(buf, version)
153    }
154    fn decode_with_limits(
155        buf: &mut impl Buf,
156        version: i16,
157        limits: Limits,
158    ) -> Result<Self, DecodeError> {
159        ListOffsetsRequest::decode_with_limits(buf, version, limits)
160    }
161}
162
163/// `ListOffsetsTopic` (nested in [`ListOffsetsRequest`]).
164#[derive(Debug, Clone, PartialEq)]
165#[non_exhaustive]
166pub struct ListOffsetsTopic {
167    /// The topic name.
168    pub name: String,
169    /// Each partition in the request.
170    pub partitions: Vec<ListOffsetsPartition>,
171    /// Tagged fields not (yet) known to this crate, kept raw.
172    pub unknown_tagged_fields: Vec<RawTaggedField>,
173}
174
175impl Default for ListOffsetsTopic {
176    fn default() -> Self {
177        Self {
178            name: String::new(),
179            partitions: Vec::new(),
180            unknown_tagged_fields: Vec::new(),
181        }
182    }
183}
184
185impl ListOffsetsTopic {
186    /// Encode this `ListOffsetsTopic` at `version`.
187    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
188        if is_flexible(version) {
189            wire::put_compact_string(buf, &self.name);
190        } else {
191            wire::put_string(buf, &self.name)?;
192        }
193        if is_flexible(version) {
194            wire::put_compact_array_len(buf, Some(self.partitions.len()));
195        } else {
196            wire::put_array_len(buf, Some(self.partitions.len()))?;
197        }
198        for item in &self.partitions {
199            item.encode(buf, version)?;
200        }
201        if is_flexible(version) {
202            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
203        }
204        Ok(())
205    }
206
207    /// Decode one `ListOffsetsTopic`, bounding allocation by the default
208    /// [`Limits`] derived from `buf`'s remaining length.
209    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
210        Self::decode_with_limits(buf, version, Limits::default())
211    }
212
213    /// Decode one `ListOffsetsTopic` under `limits`.
214    pub fn decode_with_limits(
215        buf: &mut impl Buf,
216        version: i16,
217        limits: Limits,
218    ) -> Result<Self, DecodeError> {
219        let mut budget = limits.budget(buf.remaining());
220        Self::decode_with_budget(buf, version, &mut budget)
221    }
222
223    /// Decode one `ListOffsetsTopic` against an existing `budget`.
224    pub fn decode_with_budget(
225        buf: &mut impl Buf,
226        version: i16,
227        budget: &mut Budget,
228    ) -> Result<Self, DecodeError> {
229        let mut this = Self::default();
230        this.name = if is_flexible(version) {
231            wire::get_compact_string(buf)?
232        } else {
233            wire::get_string(buf)?
234        };
235        this.partitions = {
236            let len = if is_flexible(version) {
237                wire::get_compact_array_len(buf)?
238            } else {
239                wire::get_array_len(buf)?
240            };
241            match len {
242                None => return Err(DecodeError::InvalidLength(-1)),
243                Some(n) => {
244                    let mut items = Vec::new();
245                    for _ in 0..n {
246                        let mark = buf.remaining();
247                        let item = ListOffsetsPartition::decode_with_budget(buf, version, budget)?;
248                        budget.progress(mark, buf.remaining())?;
249                        budget.push(&mut items, item)?;
250                    }
251                    items
252                }
253            }
254        };
255        if is_flexible(version) {
256            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
257        }
258        Ok(this)
259    }
260}
261
262/// `ListOffsetsPartition` (nested in [`ListOffsetsRequest`]).
263#[derive(Debug, Clone, PartialEq)]
264#[non_exhaustive]
265pub struct ListOffsetsPartition {
266    /// The partition index.
267    pub partition_index: i32,
268    /// The current leader epoch.
269    pub current_leader_epoch: i32,
270    /// The current timestamp.
271    pub timestamp: i64,
272    /// Tagged fields not (yet) known to this crate, kept raw.
273    pub unknown_tagged_fields: Vec<RawTaggedField>,
274}
275
276impl Default for ListOffsetsPartition {
277    fn default() -> Self {
278        Self {
279            partition_index: 0,
280            current_leader_epoch: -1,
281            timestamp: 0,
282            unknown_tagged_fields: Vec::new(),
283        }
284    }
285}
286
287impl ListOffsetsPartition {
288    /// Encode this `ListOffsetsPartition` at `version`.
289    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
290        buf.put_i32(self.partition_index);
291        if version >= 4 {
292            buf.put_i32(self.current_leader_epoch);
293        }
294        buf.put_i64(self.timestamp);
295        if is_flexible(version) {
296            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
297        }
298        Ok(())
299    }
300
301    /// Decode one `ListOffsetsPartition`, bounding allocation by the default
302    /// [`Limits`] derived from `buf`'s remaining length.
303    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
304        Self::decode_with_limits(buf, version, Limits::default())
305    }
306
307    /// Decode one `ListOffsetsPartition` under `limits`.
308    pub fn decode_with_limits(
309        buf: &mut impl Buf,
310        version: i16,
311        limits: Limits,
312    ) -> Result<Self, DecodeError> {
313        let mut budget = limits.budget(buf.remaining());
314        Self::decode_with_budget(buf, version, &mut budget)
315    }
316
317    /// Decode one `ListOffsetsPartition` against an existing `budget`.
318    pub fn decode_with_budget(
319        buf: &mut impl Buf,
320        version: i16,
321        budget: &mut Budget,
322    ) -> Result<Self, DecodeError> {
323        let mut this = Self::default();
324        this.partition_index = wire::get_i32(buf)?;
325        if version >= 4 {
326            this.current_leader_epoch = wire::get_i32(buf)?;
327        }
328        this.timestamp = wire::get_i64(buf)?;
329        if is_flexible(version) {
330            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
331        }
332        Ok(this)
333    }
334}