Skip to main content

kacrab_protocol/generated/
end_txn_response.rs

1//! Generated from EndTxnResponse.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 EndTxnResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The error code, or 0 if there was no error.
21    pub error_code: i16,
22    /// The producer ID.
23    pub producer_id: i64,
24    /// The current epoch associated with the producer.
25    pub producer_epoch: i16,
26    pub _unknown_tagged_fields: Vec<RawTaggedField>,
27}
28impl Default for EndTxnResponseData {
29    fn default() -> Self {
30        Self {
31            throttle_time_ms: 0_i32,
32            error_code: 0_i16,
33            producer_id: -1i64,
34            producer_epoch: -1i16,
35            _unknown_tagged_fields: Vec::new(),
36        }
37    }
38}
39impl EndTxnResponseData {
40    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
41        self.throttle_time_ms = value;
42        self
43    }
44    pub fn with_error_code(mut self, value: i16) -> Self {
45        self.error_code = value;
46        self
47    }
48    pub fn with_producer_id(mut self, value: i64) -> Self {
49        self.producer_id = value;
50        self
51    }
52    pub fn with_producer_epoch(mut self, value: i16) -> Self {
53        self.producer_epoch = value;
54        self
55    }
56    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
57        if version < 0 || version > 5 {
58            return Err(UnsupportedVersion::new(26, version).into());
59        }
60        let throttle_time_ms;
61        let error_code;
62        let mut producer_id = -1i64;
63        let mut producer_epoch = -1i16;
64        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
65        throttle_time_ms = read_i32(buf)?;
66        error_code = read_i16(buf)?;
67        if version >= 5 {
68            producer_id = read_i64(buf)?;
69        }
70        if version >= 5 {
71            producer_epoch = read_i16(buf)?;
72        }
73        if version >= 3 {
74            let tagged_fields = read_tagged_fields(buf)?;
75            for field in &tagged_fields {
76                match field.tag {
77                    _ => {
78                        _unknown_tagged_fields.push(field.clone());
79                    },
80                }
81            }
82        }
83        Ok(Self {
84            throttle_time_ms,
85            error_code,
86            producer_id,
87            producer_epoch,
88            _unknown_tagged_fields,
89        })
90    }
91    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
92        if version < 0 || version > 5 {
93            return Err(UnsupportedVersion::new(26, version).into());
94        }
95        write_i32(buf, self.throttle_time_ms);
96        write_i16(buf, self.error_code);
97        if version >= 5 {
98            write_i64(buf, self.producer_id);
99        } else if self.producer_id != -1i64 {
100            return Err(UnsupportedFieldVersion::new(26, "producer_id", version).into());
101        }
102        if version >= 5 {
103            write_i16(buf, self.producer_epoch);
104        } else if self.producer_epoch != -1i16 {
105            return Err(UnsupportedFieldVersion::new(26, "producer_epoch", version).into());
106        }
107        if version >= 3 {
108            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
109            all_tags.sort_by_key(|f| f.tag);
110            write_tagged_fields(buf, &all_tags)?;
111        }
112        Ok(())
113    }
114    pub fn encoded_len(&self, version: i16) -> Result<usize> {
115        if version < 0 || version > 5 {
116            return Err(UnsupportedVersion::new(26, version).into());
117        }
118        let mut len: usize = 0;
119        len += 4;
120        len += 2;
121        if version >= 5 {
122            len += 8;
123        } else if self.producer_id != -1i64 {
124            return Err(UnsupportedFieldVersion::new(26, "producer_id", version).into());
125        }
126        if version >= 5 {
127            len += 2;
128        } else if self.producer_epoch != -1i16 {
129            return Err(UnsupportedFieldVersion::new(26, "producer_epoch", version).into());
130        }
131        if version >= 3 {
132            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
133            all_tags.sort_by_key(|f| f.tag);
134            len += tagged_fields_len(&all_tags)?;
135        }
136        Ok(len)
137    }
138}