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: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct WritableTxnMarkerPartitionResult {
24    /// The partition index.
25    ///
26    /// Supported API versions: 0-1
27    pub partition_index: i32,
28
29    /// The error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0-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: 0-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: 0-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 < 0 || 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        if version >= 1 {
78            let num_tagged_fields = self.unknown_tagged_fields.len();
79            if num_tagged_fields > std::u32::MAX as usize {
80                bail!(
81                    "Too many tagged fields to encode ({} fields)",
82                    num_tagged_fields
83                );
84            }
85            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
86
87            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
88        }
89        Ok(())
90    }
91    fn compute_size(&self, version: i16) -> Result<usize> {
92        let mut total_size = 0;
93        total_size += types::Int32.compute_size(&self.partition_index)?;
94        total_size += types::Int16.compute_size(&self.error_code)?;
95        if version >= 1 {
96            let num_tagged_fields = self.unknown_tagged_fields.len();
97            if num_tagged_fields > std::u32::MAX as usize {
98                bail!(
99                    "Too many tagged fields to encode ({} fields)",
100                    num_tagged_fields
101                );
102            }
103            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
104
105            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
106        }
107        Ok(total_size)
108    }
109}
110
111#[cfg(feature = "client")]
112impl Decodable for WritableTxnMarkerPartitionResult {
113    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
114        if version < 0 || version > 1 {
115            bail!("specified version not supported by this message type");
116        }
117        let partition_index = types::Int32.decode(buf)?;
118        let error_code = types::Int16.decode(buf)?;
119        let mut unknown_tagged_fields = BTreeMap::new();
120        if version >= 1 {
121            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
122            for _ in 0..num_tagged_fields {
123                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
124                let size: u32 = types::UnsignedVarInt.decode(buf)?;
125                let unknown_value = buf.try_get_bytes(size as usize)?;
126                unknown_tagged_fields.insert(tag as i32, unknown_value);
127            }
128        }
129        Ok(Self {
130            partition_index,
131            error_code,
132            unknown_tagged_fields,
133        })
134    }
135}
136
137impl Default for WritableTxnMarkerPartitionResult {
138    fn default() -> Self {
139        Self {
140            partition_index: 0,
141            error_code: 0,
142            unknown_tagged_fields: BTreeMap::new(),
143        }
144    }
145}
146
147impl Message for WritableTxnMarkerPartitionResult {
148    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
149    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
150}
151
152/// Valid versions: 0-1
153#[non_exhaustive]
154#[derive(Debug, Clone, PartialEq)]
155pub struct WritableTxnMarkerResult {
156    /// The current producer ID in use by the transactional ID.
157    ///
158    /// Supported API versions: 0-1
159    pub producer_id: super::ProducerId,
160
161    /// The results by topic.
162    ///
163    /// Supported API versions: 0-1
164    pub topics: Vec<WritableTxnMarkerTopicResult>,
165
166    /// Other tagged fields
167    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
168}
169
170impl WritableTxnMarkerResult {
171    /// Sets `producer_id` to the passed value.
172    ///
173    /// The current producer ID in use by the transactional ID.
174    ///
175    /// Supported API versions: 0-1
176    pub fn with_producer_id(mut self, value: super::ProducerId) -> Self {
177        self.producer_id = value;
178        self
179    }
180    /// Sets `topics` to the passed value.
181    ///
182    /// The results by topic.
183    ///
184    /// Supported API versions: 0-1
185    pub fn with_topics(mut self, value: Vec<WritableTxnMarkerTopicResult>) -> Self {
186        self.topics = value;
187        self
188    }
189    /// Sets unknown_tagged_fields to the passed value.
190    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
191        self.unknown_tagged_fields = value;
192        self
193    }
194    /// Inserts an entry into unknown_tagged_fields.
195    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
196        self.unknown_tagged_fields.insert(key, value);
197        self
198    }
199}
200
201#[cfg(feature = "broker")]
202impl Encodable for WritableTxnMarkerResult {
203    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
204        if version < 0 || version > 1 {
205            bail!("specified version not supported by this message type");
206        }
207        types::Int64.encode(buf, &self.producer_id)?;
208        if version >= 1 {
209            types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
210        } else {
211            types::Array(types::Struct { version }).encode(buf, &self.topics)?;
212        }
213        if version >= 1 {
214            let num_tagged_fields = self.unknown_tagged_fields.len();
215            if num_tagged_fields > std::u32::MAX as usize {
216                bail!(
217                    "Too many tagged fields to encode ({} fields)",
218                    num_tagged_fields
219                );
220            }
221            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
222
223            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
224        }
225        Ok(())
226    }
227    fn compute_size(&self, version: i16) -> Result<usize> {
228        let mut total_size = 0;
229        total_size += types::Int64.compute_size(&self.producer_id)?;
230        if version >= 1 {
231            total_size +=
232                types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
233        } else {
234            total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
235        }
236        if version >= 1 {
237            let num_tagged_fields = self.unknown_tagged_fields.len();
238            if num_tagged_fields > std::u32::MAX as usize {
239                bail!(
240                    "Too many tagged fields to encode ({} fields)",
241                    num_tagged_fields
242                );
243            }
244            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
245
246            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
247        }
248        Ok(total_size)
249    }
250}
251
252#[cfg(feature = "client")]
253impl Decodable for WritableTxnMarkerResult {
254    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
255        if version < 0 || version > 1 {
256            bail!("specified version not supported by this message type");
257        }
258        let producer_id = types::Int64.decode(buf)?;
259        let topics = if version >= 1 {
260            types::CompactArray(types::Struct { version }).decode(buf)?
261        } else {
262            types::Array(types::Struct { version }).decode(buf)?
263        };
264        let mut unknown_tagged_fields = BTreeMap::new();
265        if version >= 1 {
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            producer_id,
276            topics,
277            unknown_tagged_fields,
278        })
279    }
280}
281
282impl Default for WritableTxnMarkerResult {
283    fn default() -> Self {
284        Self {
285            producer_id: (0).into(),
286            topics: Default::default(),
287            unknown_tagged_fields: BTreeMap::new(),
288        }
289    }
290}
291
292impl Message for WritableTxnMarkerResult {
293    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
294    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
295}
296
297/// Valid versions: 0-1
298#[non_exhaustive]
299#[derive(Debug, Clone, PartialEq)]
300pub struct WritableTxnMarkerTopicResult {
301    /// The topic name.
302    ///
303    /// Supported API versions: 0-1
304    pub name: super::TopicName,
305
306    /// The results by partition.
307    ///
308    /// Supported API versions: 0-1
309    pub partitions: Vec<WritableTxnMarkerPartitionResult>,
310
311    /// Other tagged fields
312    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
313}
314
315impl WritableTxnMarkerTopicResult {
316    /// Sets `name` to the passed value.
317    ///
318    /// The topic name.
319    ///
320    /// Supported API versions: 0-1
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 results by partition.
328    ///
329    /// Supported API versions: 0-1
330    pub fn with_partitions(mut self, value: Vec<WritableTxnMarkerPartitionResult>) -> 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 WritableTxnMarkerTopicResult {
348    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
349        if version < 0 || version > 1 {
350            bail!("specified version not supported by this message type");
351        }
352        if version >= 1 {
353            types::CompactString.encode(buf, &self.name)?;
354        } else {
355            types::String.encode(buf, &self.name)?;
356        }
357        if version >= 1 {
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 >= 1 {
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 >= 1 {
379            total_size += types::CompactString.compute_size(&self.name)?;
380        } else {
381            total_size += types::String.compute_size(&self.name)?;
382        }
383        if version >= 1 {
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 >= 1 {
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 WritableTxnMarkerTopicResult {
407    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
408        if version < 0 || version > 1 {
409            bail!("specified version not supported by this message type");
410        }
411        let name = if version >= 1 {
412            types::CompactString.decode(buf)?
413        } else {
414            types::String.decode(buf)?
415        };
416        let partitions = if version >= 1 {
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 >= 1 {
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 WritableTxnMarkerTopicResult {
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 WritableTxnMarkerTopicResult {
450    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
451    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
452}
453
454/// Valid versions: 0-1
455#[non_exhaustive]
456#[derive(Debug, Clone, PartialEq)]
457pub struct WriteTxnMarkersResponse {
458    /// The results for writing makers.
459    ///
460    /// Supported API versions: 0-1
461    pub markers: Vec<WritableTxnMarkerResult>,
462
463    /// Other tagged fields
464    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
465}
466
467impl WriteTxnMarkersResponse {
468    /// Sets `markers` to the passed value.
469    ///
470    /// The results for writing makers.
471    ///
472    /// Supported API versions: 0-1
473    pub fn with_markers(mut self, value: Vec<WritableTxnMarkerResult>) -> Self {
474        self.markers = value;
475        self
476    }
477    /// Sets unknown_tagged_fields to the passed value.
478    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
479        self.unknown_tagged_fields = value;
480        self
481    }
482    /// Inserts an entry into unknown_tagged_fields.
483    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
484        self.unknown_tagged_fields.insert(key, value);
485        self
486    }
487}
488
489#[cfg(feature = "broker")]
490impl Encodable for WriteTxnMarkersResponse {
491    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
492        if version < 0 || version > 1 {
493            bail!("specified version not supported by this message type");
494        }
495        if version >= 1 {
496            types::CompactArray(types::Struct { version }).encode(buf, &self.markers)?;
497        } else {
498            types::Array(types::Struct { version }).encode(buf, &self.markers)?;
499        }
500        if version >= 1 {
501            let num_tagged_fields = self.unknown_tagged_fields.len();
502            if num_tagged_fields > std::u32::MAX as usize {
503                bail!(
504                    "Too many tagged fields to encode ({} fields)",
505                    num_tagged_fields
506                );
507            }
508            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
509
510            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
511        }
512        Ok(())
513    }
514    fn compute_size(&self, version: i16) -> Result<usize> {
515        let mut total_size = 0;
516        if version >= 1 {
517            total_size +=
518                types::CompactArray(types::Struct { version }).compute_size(&self.markers)?;
519        } else {
520            total_size += types::Array(types::Struct { version }).compute_size(&self.markers)?;
521        }
522        if version >= 1 {
523            let num_tagged_fields = self.unknown_tagged_fields.len();
524            if num_tagged_fields > std::u32::MAX as usize {
525                bail!(
526                    "Too many tagged fields to encode ({} fields)",
527                    num_tagged_fields
528                );
529            }
530            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
531
532            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
533        }
534        Ok(total_size)
535    }
536}
537
538#[cfg(feature = "client")]
539impl Decodable for WriteTxnMarkersResponse {
540    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
541        if version < 0 || version > 1 {
542            bail!("specified version not supported by this message type");
543        }
544        let markers = if version >= 1 {
545            types::CompactArray(types::Struct { version }).decode(buf)?
546        } else {
547            types::Array(types::Struct { version }).decode(buf)?
548        };
549        let mut unknown_tagged_fields = BTreeMap::new();
550        if version >= 1 {
551            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
552            for _ in 0..num_tagged_fields {
553                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
554                let size: u32 = types::UnsignedVarInt.decode(buf)?;
555                let unknown_value = buf.try_get_bytes(size as usize)?;
556                unknown_tagged_fields.insert(tag as i32, unknown_value);
557            }
558        }
559        Ok(Self {
560            markers,
561            unknown_tagged_fields,
562        })
563    }
564}
565
566impl Default for WriteTxnMarkersResponse {
567    fn default() -> Self {
568        Self {
569            markers: Default::default(),
570            unknown_tagged_fields: BTreeMap::new(),
571        }
572    }
573}
574
575impl Message for WriteTxnMarkersResponse {
576    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
577    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
578}
579
580impl HeaderVersion for WriteTxnMarkersResponse {
581    fn header_version(version: i16) -> i16 {
582        if version >= 1 {
583            1
584        } else {
585            0
586        }
587    }
588}