Skip to main content

kacrab_protocol/generated/
end_txn_request.rs

1//! Generated from EndTxnRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct EndTxnRequestData {
17    /// The ID of the transaction to end.
18    pub transactional_id: KafkaString,
19    /// The producer ID.
20    pub producer_id: i64,
21    /// The current epoch associated with the producer.
22    pub producer_epoch: i16,
23    /// True if the transaction was committed, false if it was aborted.
24    pub committed: bool,
25    pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27impl Default for EndTxnRequestData {
28    fn default() -> Self {
29        Self {
30            transactional_id: KafkaString::default(),
31            producer_id: 0_i64,
32            producer_epoch: 0_i16,
33            committed: false,
34            _unknown_tagged_fields: Vec::new(),
35        }
36    }
37}
38impl EndTxnRequestData {
39    pub fn with_transactional_id(mut self, value: KafkaString) -> Self {
40        self.transactional_id = value;
41        self
42    }
43    pub fn with_producer_id(mut self, value: i64) -> Self {
44        self.producer_id = value;
45        self
46    }
47    pub fn with_producer_epoch(mut self, value: i16) -> Self {
48        self.producer_epoch = value;
49        self
50    }
51    pub fn with_committed(mut self, value: bool) -> Self {
52        self.committed = value;
53        self
54    }
55    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
56        if version < 0 || version > 5 {
57            return Err(UnsupportedVersion::new(26, version).into());
58        }
59        let transactional_id;
60        let producer_id;
61        let producer_epoch;
62        let committed;
63        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
64        if version >= 3 {
65            transactional_id = read_compact_string(buf)?;
66        } else {
67            transactional_id = read_string(buf)?;
68        }
69        producer_id = read_i64(buf)?;
70        producer_epoch = read_i16(buf)?;
71        committed = read_bool(buf)?;
72        if version >= 3 {
73            let tagged_fields = read_tagged_fields(buf)?;
74            for field in &tagged_fields {
75                match field.tag {
76                    _ => {
77                        _unknown_tagged_fields.push(field.clone());
78                    },
79                }
80            }
81        }
82        Ok(Self {
83            transactional_id,
84            producer_id,
85            producer_epoch,
86            committed,
87            _unknown_tagged_fields,
88        })
89    }
90    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
91        if version < 0 || version > 5 {
92            return Err(UnsupportedVersion::new(26, version).into());
93        }
94        if version >= 3 {
95            write_compact_string(buf, &self.transactional_id)?;
96        } else {
97            write_string(buf, &self.transactional_id)?;
98        }
99        write_i64(buf, self.producer_id);
100        write_i16(buf, self.producer_epoch);
101        write_bool(buf, self.committed);
102        if version >= 3 {
103            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
104            all_tags.sort_by_key(|f| f.tag);
105            write_tagged_fields(buf, &all_tags)?;
106        }
107        Ok(())
108    }
109    pub fn encoded_len(&self, version: i16) -> Result<usize> {
110        if version < 0 || version > 5 {
111            return Err(UnsupportedVersion::new(26, version).into());
112        }
113        let mut len: usize = 0;
114        if version >= 3 {
115            len += compact_string_len(&self.transactional_id)?;
116        } else {
117            len += string_len(&self.transactional_id)?;
118        }
119        len += 8;
120        len += 2;
121        len += 1;
122        if version >= 3 {
123            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
124            all_tags.sort_by_key(|f| f.tag);
125            len += tagged_fields_len(&all_tags)?;
126        }
127        Ok(len)
128    }
129}