Skip to main content

odradek_protocol/messages/
txn_offset_commit_response.rs

1//! `TxnOffsetCommitResponse` — generated from `schemas/TxnOffsetCommitResponse.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 >= 3
25}
26
27/// `TxnOffsetCommitResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct TxnOffsetCommitResponse {
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 for each topic.
34    pub topics: Vec<TxnOffsetCommitResponseTopic>,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for TxnOffsetCommitResponse {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0,
43            topics: Vec::new(),
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl TxnOffsetCommitResponse {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 28;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 5;
56
57    /// Encode this `TxnOffsetCommitResponse` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        buf.put_i32(self.throttle_time_ms);
60        if is_flexible(version) {
61            wire::put_compact_array_len(buf, Some(self.topics.len()));
62        } else {
63            wire::put_array_len(buf, Some(self.topics.len()))?;
64        }
65        for item in &self.topics {
66            item.encode(buf, version)?;
67        }
68        if is_flexible(version) {
69            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73
74    /// Decode one `TxnOffsetCommitResponse`, bounding allocation by the default
75    /// [`Limits`] derived from `buf`'s remaining length.
76    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
77        Self::decode_with_limits(buf, version, Limits::default())
78    }
79
80    /// Decode one `TxnOffsetCommitResponse` under `limits`.
81    pub fn decode_with_limits(
82        buf: &mut impl Buf,
83        version: i16,
84        limits: Limits,
85    ) -> Result<Self, DecodeError> {
86        let mut budget = limits.budget(buf.remaining());
87        Self::decode_with_budget(buf, version, &mut budget)
88    }
89
90    /// Decode one `TxnOffsetCommitResponse` against an existing `budget`.
91    pub fn decode_with_budget(
92        buf: &mut impl Buf,
93        version: i16,
94        budget: &mut Budget,
95    ) -> Result<Self, DecodeError> {
96        let mut this = Self::default();
97        this.throttle_time_ms = wire::get_i32(buf)?;
98        this.topics = {
99            let len = if is_flexible(version) {
100                wire::get_compact_array_len(buf)?
101            } else {
102                wire::get_array_len(buf)?
103            };
104            match len {
105                None => return Err(DecodeError::InvalidLength(-1)),
106                Some(n) => {
107                    let mut items = Vec::new();
108                    for _ in 0..n {
109                        let mark = buf.remaining();
110                        let item =
111                            TxnOffsetCommitResponseTopic::decode_with_budget(buf, version, budget)?;
112                        budget.progress(mark, buf.remaining())?;
113                        budget.push(&mut items, item)?;
114                    }
115                    items
116                }
117            }
118        };
119        if is_flexible(version) {
120            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
121        }
122        Ok(this)
123    }
124}
125
126impl crate::Message for TxnOffsetCommitResponse {
127    const API_KEY: i16 = 28;
128    const MIN_VERSION: i16 = 0;
129    const MAX_VERSION: i16 = 5;
130
131    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
132        TxnOffsetCommitResponse::encode(self, buf, version)
133    }
134    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
135        TxnOffsetCommitResponse::decode(buf, version)
136    }
137    fn decode_with_limits(
138        buf: &mut impl Buf,
139        version: i16,
140        limits: Limits,
141    ) -> Result<Self, DecodeError> {
142        TxnOffsetCommitResponse::decode_with_limits(buf, version, limits)
143    }
144    fn throttle_time_ms(&self) -> Option<i32> {
145        Some(self.throttle_time_ms)
146    }
147}
148
149/// `TxnOffsetCommitResponseTopic` (nested in [`TxnOffsetCommitResponse`]).
150#[derive(Debug, Clone, PartialEq)]
151#[non_exhaustive]
152pub struct TxnOffsetCommitResponseTopic {
153    /// The topic name.
154    pub name: String,
155    /// The responses for each partition in the topic.
156    pub partitions: Vec<TxnOffsetCommitResponsePartition>,
157    /// Tagged fields not (yet) known to this crate, kept raw.
158    pub unknown_tagged_fields: Vec<RawTaggedField>,
159}
160
161impl Default for TxnOffsetCommitResponseTopic {
162    fn default() -> Self {
163        Self {
164            name: String::new(),
165            partitions: Vec::new(),
166            unknown_tagged_fields: Vec::new(),
167        }
168    }
169}
170
171impl TxnOffsetCommitResponseTopic {
172    /// Encode this `TxnOffsetCommitResponseTopic` at `version`.
173    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
174        if is_flexible(version) {
175            wire::put_compact_string(buf, &self.name);
176        } else {
177            wire::put_string(buf, &self.name)?;
178        }
179        if is_flexible(version) {
180            wire::put_compact_array_len(buf, Some(self.partitions.len()));
181        } else {
182            wire::put_array_len(buf, Some(self.partitions.len()))?;
183        }
184        for item in &self.partitions {
185            item.encode(buf, version)?;
186        }
187        if is_flexible(version) {
188            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
189        }
190        Ok(())
191    }
192
193    /// Decode one `TxnOffsetCommitResponseTopic`, bounding allocation by the default
194    /// [`Limits`] derived from `buf`'s remaining length.
195    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
196        Self::decode_with_limits(buf, version, Limits::default())
197    }
198
199    /// Decode one `TxnOffsetCommitResponseTopic` under `limits`.
200    pub fn decode_with_limits(
201        buf: &mut impl Buf,
202        version: i16,
203        limits: Limits,
204    ) -> Result<Self, DecodeError> {
205        let mut budget = limits.budget(buf.remaining());
206        Self::decode_with_budget(buf, version, &mut budget)
207    }
208
209    /// Decode one `TxnOffsetCommitResponseTopic` against an existing `budget`.
210    pub fn decode_with_budget(
211        buf: &mut impl Buf,
212        version: i16,
213        budget: &mut Budget,
214    ) -> Result<Self, DecodeError> {
215        let mut this = Self::default();
216        this.name = if is_flexible(version) {
217            wire::get_compact_string(buf)?
218        } else {
219            wire::get_string(buf)?
220        };
221        this.partitions = {
222            let len = if is_flexible(version) {
223                wire::get_compact_array_len(buf)?
224            } else {
225                wire::get_array_len(buf)?
226            };
227            match len {
228                None => return Err(DecodeError::InvalidLength(-1)),
229                Some(n) => {
230                    let mut items = Vec::new();
231                    for _ in 0..n {
232                        let mark = buf.remaining();
233                        let item = TxnOffsetCommitResponsePartition::decode_with_budget(
234                            buf, version, budget,
235                        )?;
236                        budget.progress(mark, buf.remaining())?;
237                        budget.push(&mut items, item)?;
238                    }
239                    items
240                }
241            }
242        };
243        if is_flexible(version) {
244            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
245        }
246        Ok(this)
247    }
248}
249
250/// `TxnOffsetCommitResponsePartition` (nested in [`TxnOffsetCommitResponse`]).
251#[derive(Debug, Clone, PartialEq)]
252#[non_exhaustive]
253pub struct TxnOffsetCommitResponsePartition {
254    /// The partition index.
255    pub partition_index: i32,
256    /// The error code, or 0 if there was no error.
257    pub error_code: i16,
258    /// Tagged fields not (yet) known to this crate, kept raw.
259    pub unknown_tagged_fields: Vec<RawTaggedField>,
260}
261
262impl Default for TxnOffsetCommitResponsePartition {
263    fn default() -> Self {
264        Self {
265            partition_index: 0,
266            error_code: 0,
267            unknown_tagged_fields: Vec::new(),
268        }
269    }
270}
271
272impl TxnOffsetCommitResponsePartition {
273    /// Encode this `TxnOffsetCommitResponsePartition` at `version`.
274    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
275        buf.put_i32(self.partition_index);
276        buf.put_i16(self.error_code);
277        if is_flexible(version) {
278            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
279        }
280        Ok(())
281    }
282
283    /// Decode one `TxnOffsetCommitResponsePartition`, bounding allocation by the default
284    /// [`Limits`] derived from `buf`'s remaining length.
285    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
286        Self::decode_with_limits(buf, version, Limits::default())
287    }
288
289    /// Decode one `TxnOffsetCommitResponsePartition` under `limits`.
290    pub fn decode_with_limits(
291        buf: &mut impl Buf,
292        version: i16,
293        limits: Limits,
294    ) -> Result<Self, DecodeError> {
295        let mut budget = limits.budget(buf.remaining());
296        Self::decode_with_budget(buf, version, &mut budget)
297    }
298
299    /// Decode one `TxnOffsetCommitResponsePartition` against an existing `budget`.
300    pub fn decode_with_budget(
301        buf: &mut impl Buf,
302        version: i16,
303        budget: &mut Budget,
304    ) -> Result<Self, DecodeError> {
305        let mut this = Self::default();
306        this.partition_index = wire::get_i32(buf)?;
307        this.error_code = wire::get_i16(buf)?;
308        if is_flexible(version) {
309            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
310        }
311        Ok(this)
312    }
313}