kafka_protocol/messages/
txn_offset_commit_response.rs

1//! TxnOffsetCommitResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/TxnOffsetCommitResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0-5
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct TxnOffsetCommitResponse {
24    /// 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.
25    ///
26    /// Supported API versions: 0-5
27    pub throttle_time_ms: i32,
28
29    /// The responses for each topic.
30    ///
31    /// Supported API versions: 0-5
32    pub topics: Vec<TxnOffsetCommitResponseTopic>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl TxnOffsetCommitResponse {
39    /// Sets `throttle_time_ms` to the passed value.
40    ///
41    /// 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.
42    ///
43    /// Supported API versions: 0-5
44    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45        self.throttle_time_ms = value;
46        self
47    }
48    /// Sets `topics` to the passed value.
49    ///
50    /// The responses for each topic.
51    ///
52    /// Supported API versions: 0-5
53    pub fn with_topics(mut self, value: Vec<TxnOffsetCommitResponseTopic>) -> Self {
54        self.topics = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for TxnOffsetCommitResponse {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version < 0 || version > 5 {
73            bail!("specified version not supported by this message type");
74        }
75        types::Int32.encode(buf, &self.throttle_time_ms)?;
76        if version >= 3 {
77            types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
78        } else {
79            types::Array(types::Struct { version }).encode(buf, &self.topics)?;
80        }
81        if version >= 3 {
82            let num_tagged_fields = self.unknown_tagged_fields.len();
83            if num_tagged_fields > std::u32::MAX as usize {
84                bail!(
85                    "Too many tagged fields to encode ({} fields)",
86                    num_tagged_fields
87                );
88            }
89            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
90
91            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
92        }
93        Ok(())
94    }
95    fn compute_size(&self, version: i16) -> Result<usize> {
96        let mut total_size = 0;
97        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
98        if version >= 3 {
99            total_size +=
100                types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
101        } else {
102            total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
103        }
104        if version >= 3 {
105            let num_tagged_fields = self.unknown_tagged_fields.len();
106            if num_tagged_fields > std::u32::MAX as usize {
107                bail!(
108                    "Too many tagged fields to encode ({} fields)",
109                    num_tagged_fields
110                );
111            }
112            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
113
114            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
115        }
116        Ok(total_size)
117    }
118}
119
120#[cfg(feature = "client")]
121impl Decodable for TxnOffsetCommitResponse {
122    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
123        if version < 0 || version > 5 {
124            bail!("specified version not supported by this message type");
125        }
126        let throttle_time_ms = types::Int32.decode(buf)?;
127        let topics = if version >= 3 {
128            types::CompactArray(types::Struct { version }).decode(buf)?
129        } else {
130            types::Array(types::Struct { version }).decode(buf)?
131        };
132        let mut unknown_tagged_fields = BTreeMap::new();
133        if version >= 3 {
134            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
135            for _ in 0..num_tagged_fields {
136                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
137                let size: u32 = types::UnsignedVarInt.decode(buf)?;
138                let unknown_value = buf.try_get_bytes(size as usize)?;
139                unknown_tagged_fields.insert(tag as i32, unknown_value);
140            }
141        }
142        Ok(Self {
143            throttle_time_ms,
144            topics,
145            unknown_tagged_fields,
146        })
147    }
148}
149
150impl Default for TxnOffsetCommitResponse {
151    fn default() -> Self {
152        Self {
153            throttle_time_ms: 0,
154            topics: Default::default(),
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for TxnOffsetCommitResponse {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 5 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165/// Valid versions: 0-5
166#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct TxnOffsetCommitResponsePartition {
169    /// The partition index.
170    ///
171    /// Supported API versions: 0-5
172    pub partition_index: i32,
173
174    /// The error code, or 0 if there was no error.
175    ///
176    /// Supported API versions: 0-5
177    pub error_code: i16,
178
179    /// Other tagged fields
180    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
181}
182
183impl TxnOffsetCommitResponsePartition {
184    /// Sets `partition_index` to the passed value.
185    ///
186    /// The partition index.
187    ///
188    /// Supported API versions: 0-5
189    pub fn with_partition_index(mut self, value: i32) -> Self {
190        self.partition_index = value;
191        self
192    }
193    /// Sets `error_code` to the passed value.
194    ///
195    /// The error code, or 0 if there was no error.
196    ///
197    /// Supported API versions: 0-5
198    pub fn with_error_code(mut self, value: i16) -> Self {
199        self.error_code = value;
200        self
201    }
202    /// Sets unknown_tagged_fields to the passed value.
203    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
204        self.unknown_tagged_fields = value;
205        self
206    }
207    /// Inserts an entry into unknown_tagged_fields.
208    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
209        self.unknown_tagged_fields.insert(key, value);
210        self
211    }
212}
213
214#[cfg(feature = "broker")]
215impl Encodable for TxnOffsetCommitResponsePartition {
216    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
217        if version < 0 || version > 5 {
218            bail!("specified version not supported by this message type");
219        }
220        types::Int32.encode(buf, &self.partition_index)?;
221        types::Int16.encode(buf, &self.error_code)?;
222        if version >= 3 {
223            let num_tagged_fields = self.unknown_tagged_fields.len();
224            if num_tagged_fields > std::u32::MAX as usize {
225                bail!(
226                    "Too many tagged fields to encode ({} fields)",
227                    num_tagged_fields
228                );
229            }
230            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
231
232            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
233        }
234        Ok(())
235    }
236    fn compute_size(&self, version: i16) -> Result<usize> {
237        let mut total_size = 0;
238        total_size += types::Int32.compute_size(&self.partition_index)?;
239        total_size += types::Int16.compute_size(&self.error_code)?;
240        if version >= 3 {
241            let num_tagged_fields = self.unknown_tagged_fields.len();
242            if num_tagged_fields > std::u32::MAX as usize {
243                bail!(
244                    "Too many tagged fields to encode ({} fields)",
245                    num_tagged_fields
246                );
247            }
248            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
249
250            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
251        }
252        Ok(total_size)
253    }
254}
255
256#[cfg(feature = "client")]
257impl Decodable for TxnOffsetCommitResponsePartition {
258    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
259        if version < 0 || version > 5 {
260            bail!("specified version not supported by this message type");
261        }
262        let partition_index = types::Int32.decode(buf)?;
263        let error_code = types::Int16.decode(buf)?;
264        let mut unknown_tagged_fields = BTreeMap::new();
265        if version >= 3 {
266            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
267            for _ in 0..num_tagged_fields {
268                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
269                let size: u32 = types::UnsignedVarInt.decode(buf)?;
270                let unknown_value = buf.try_get_bytes(size as usize)?;
271                unknown_tagged_fields.insert(tag as i32, unknown_value);
272            }
273        }
274        Ok(Self {
275            partition_index,
276            error_code,
277            unknown_tagged_fields,
278        })
279    }
280}
281
282impl Default for TxnOffsetCommitResponsePartition {
283    fn default() -> Self {
284        Self {
285            partition_index: 0,
286            error_code: 0,
287            unknown_tagged_fields: BTreeMap::new(),
288        }
289    }
290}
291
292impl Message for TxnOffsetCommitResponsePartition {
293    const VERSIONS: VersionRange = VersionRange { min: 0, max: 5 };
294    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
295}
296
297/// Valid versions: 0-5
298#[non_exhaustive]
299#[derive(Debug, Clone, PartialEq)]
300pub struct TxnOffsetCommitResponseTopic {
301    /// The topic name.
302    ///
303    /// Supported API versions: 0-5
304    pub name: super::TopicName,
305
306    /// The responses for each partition in the topic.
307    ///
308    /// Supported API versions: 0-5
309    pub partitions: Vec<TxnOffsetCommitResponsePartition>,
310
311    /// Other tagged fields
312    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
313}
314
315impl TxnOffsetCommitResponseTopic {
316    /// Sets `name` to the passed value.
317    ///
318    /// The topic name.
319    ///
320    /// Supported API versions: 0-5
321    pub fn with_name(mut self, value: super::TopicName) -> Self {
322        self.name = value;
323        self
324    }
325    /// Sets `partitions` to the passed value.
326    ///
327    /// The responses for each partition in the topic.
328    ///
329    /// Supported API versions: 0-5
330    pub fn with_partitions(mut self, value: Vec<TxnOffsetCommitResponsePartition>) -> Self {
331        self.partitions = value;
332        self
333    }
334    /// Sets unknown_tagged_fields to the passed value.
335    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
336        self.unknown_tagged_fields = value;
337        self
338    }
339    /// Inserts an entry into unknown_tagged_fields.
340    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
341        self.unknown_tagged_fields.insert(key, value);
342        self
343    }
344}
345
346#[cfg(feature = "broker")]
347impl Encodable for TxnOffsetCommitResponseTopic {
348    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
349        if version < 0 || version > 5 {
350            bail!("specified version not supported by this message type");
351        }
352        if version >= 3 {
353            types::CompactString.encode(buf, &self.name)?;
354        } else {
355            types::String.encode(buf, &self.name)?;
356        }
357        if version >= 3 {
358            types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
359        } else {
360            types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
361        }
362        if version >= 3 {
363            let num_tagged_fields = self.unknown_tagged_fields.len();
364            if num_tagged_fields > std::u32::MAX as usize {
365                bail!(
366                    "Too many tagged fields to encode ({} fields)",
367                    num_tagged_fields
368                );
369            }
370            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
371
372            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
373        }
374        Ok(())
375    }
376    fn compute_size(&self, version: i16) -> Result<usize> {
377        let mut total_size = 0;
378        if version >= 3 {
379            total_size += types::CompactString.compute_size(&self.name)?;
380        } else {
381            total_size += types::String.compute_size(&self.name)?;
382        }
383        if version >= 3 {
384            total_size +=
385                types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
386        } else {
387            total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
388        }
389        if version >= 3 {
390            let num_tagged_fields = self.unknown_tagged_fields.len();
391            if num_tagged_fields > std::u32::MAX as usize {
392                bail!(
393                    "Too many tagged fields to encode ({} fields)",
394                    num_tagged_fields
395                );
396            }
397            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
398
399            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
400        }
401        Ok(total_size)
402    }
403}
404
405#[cfg(feature = "client")]
406impl Decodable for TxnOffsetCommitResponseTopic {
407    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
408        if version < 0 || version > 5 {
409            bail!("specified version not supported by this message type");
410        }
411        let name = if version >= 3 {
412            types::CompactString.decode(buf)?
413        } else {
414            types::String.decode(buf)?
415        };
416        let partitions = if version >= 3 {
417            types::CompactArray(types::Struct { version }).decode(buf)?
418        } else {
419            types::Array(types::Struct { version }).decode(buf)?
420        };
421        let mut unknown_tagged_fields = BTreeMap::new();
422        if version >= 3 {
423            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
424            for _ in 0..num_tagged_fields {
425                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
426                let size: u32 = types::UnsignedVarInt.decode(buf)?;
427                let unknown_value = buf.try_get_bytes(size as usize)?;
428                unknown_tagged_fields.insert(tag as i32, unknown_value);
429            }
430        }
431        Ok(Self {
432            name,
433            partitions,
434            unknown_tagged_fields,
435        })
436    }
437}
438
439impl Default for TxnOffsetCommitResponseTopic {
440    fn default() -> Self {
441        Self {
442            name: Default::default(),
443            partitions: Default::default(),
444            unknown_tagged_fields: BTreeMap::new(),
445        }
446    }
447}
448
449impl Message for TxnOffsetCommitResponseTopic {
450    const VERSIONS: VersionRange = VersionRange { min: 0, max: 5 };
451    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
452}
453
454impl HeaderVersion for TxnOffsetCommitResponse {
455    fn header_version(version: i16) -> i16 {
456        if version >= 3 {
457            1
458        } else {
459            0
460        }
461    }
462}