kafka_protocol/messages/
write_txn_markers_response.rs

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