Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AddPartitionsToTxnResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 24;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 3;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct AddPartitionsToTxnResponse<'a> {
25    pub throttle_time_ms: i32,
26    pub error_code: i16,
27    pub results_by_transaction: Vec<AddPartitionsToTxnResult<'a>>,
28    pub results_by_topic_v3_and_below: Vec<super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult<'a>>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl<'a> Default for AddPartitionsToTxnResponse<'a> {
33    fn default() -> Self {
34        Self {
35            throttle_time_ms: 0i32,
36            error_code: 0i16,
37            results_by_transaction: Vec::new(),
38            results_by_topic_v3_and_below: Vec::new(),
39            unknown_tagged_fields: Default::default(),
40        }
41    }
42}
43
44impl<'a> AddPartitionsToTxnResponse<'a> {
45    pub fn to_owned(&self) -> crate::owned::add_partitions_to_txn_response::AddPartitionsToTxnResponse {
46        crate::owned::add_partitions_to_txn_response::AddPartitionsToTxnResponse {
47            throttle_time_ms: (self.throttle_time_ms),
48            error_code: (self.error_code),
49            results_by_transaction: (self.results_by_transaction).iter().map(|it| it.to_owned()).collect(),
50            results_by_topic_v3_and_below: (self.results_by_topic_v3_and_below).iter().map(|it| it.to_owned()).collect(),
51            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52        }
53    }
54}
55
56impl<'a> Encode for AddPartitionsToTxnResponse<'a> {
57    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
63        if version >= 4 { put_i16(buf, self.error_code) }
64        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.results_by_transaction).len(), flex); for it in &self.results_by_transaction { it.encode(buf, version)?; } } }
65        if version >= 0 && version <= 3 { { crate::primitives::array::put_array_len(buf, (self.results_by_topic_v3_and_below).len(), flex); for it in &self.results_by_topic_v3_and_below { it.encode(buf, version)?; } } }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 { n += 4; }
76        if version >= 4 { n += 2; }
77        if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results_by_transaction).len(), flex); let body: usize = (self.results_by_transaction).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
78        if version >= 0 && version <= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results_by_topic_v3_and_below).len(), flex); let body: usize = (self.results_by_topic_v3_and_below).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
79        if flex {
80            let known_pairs: Vec<(u32, usize)> = Vec::new();
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86
87impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnResponse<'de> {
88    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
89        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
95        if version >= 4 { out.error_code = get_i16(buf)?; }
96        if version >= 4 { out.results_by_transaction = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AddPartitionsToTxnResult::decode_borrow(buf, version)?); } v }; }
97        if version >= 0 && version <= 3 { out.results_by_topic_v3_and_below = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode_borrow(buf, version)?); } v }; }
98        if flex {
99            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
100                Ok(false)
101            })?;
102        }
103        Ok(out)
104    }
105}
106
107#[derive(Debug, Clone, PartialEq, Eq)]
108pub struct AddPartitionsToTxnResult<'a> {
109    pub transactional_id: &'a str,
110    pub topic_results: Vec<super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult<'a>>,
111    pub unknown_tagged_fields: UnknownTaggedFields,
112}
113
114impl<'a> Default for AddPartitionsToTxnResult<'a> {
115    fn default() -> Self {
116        Self {
117            transactional_id: "",
118            topic_results: Vec::new(),
119            unknown_tagged_fields: Default::default(),
120        }
121    }
122}
123
124impl<'a> AddPartitionsToTxnResult<'a> {
125    pub fn to_owned(&self) -> crate::owned::add_partitions_to_txn_response::AddPartitionsToTxnResult {
126        crate::owned::add_partitions_to_txn_response::AddPartitionsToTxnResult {
127            transactional_id: (self.transactional_id).to_string(),
128            topic_results: (self.topic_results).iter().map(|it| it.to_owned()).collect(),
129            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
130        }
131    }
132}
133
134impl<'a> Encode for AddPartitionsToTxnResult<'a> {
135    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136        let flex = version >= 3;
137        if version >= 4 { if flex { put_compact_string(buf, self.transactional_id) } else { put_string(buf, self.transactional_id) } }
138        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.topic_results).len(), flex); for it in &self.topic_results { it.encode(buf, version)?; } } }
139        if flex {
140            let tagged = WriteTaggedFields::new();
141            tagged.write(buf, &self.unknown_tagged_fields);
142        }
143        Ok(())
144    }
145    fn encoded_len(&self, version: i16) -> usize {
146        let flex = version >= 3;
147        let mut n: usize = 0;
148        if version >= 4 { n += if flex { compact_string_len(self.transactional_id) } else { string_len(self.transactional_id) }; }
149        if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_results).len(), flex); let body: usize = (self.topic_results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
150        if flex {
151            let known_pairs: Vec<(u32, usize)> = Vec::new();
152            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
153        }
154        n
155    }
156}
157
158impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnResult<'de> {
159    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
160        let flex = version >= 3;
161        let mut out = Self::default();
162        if version >= 4 { out.transactional_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
163        if version >= 4 { out.topic_results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode_borrow(buf, version)?); } v }; }
164        if flex {
165            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
166                Ok(false)
167            })?;
168        }
169        Ok(out)
170    }
171}