Skip to main content

odradek_protocol/messages/
offset_commit_response.rs

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