Skip to main content

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

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::add_partitions_to_txn_response,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i16, get_i32, put_i16, put_i32},
10        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
11        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
12    },
13    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
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#[inline]
20#[must_use]
21pub fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct AddPartitionsToTxnResponse<'a> {
26    pub throttle_time_ms: i32,
27    pub error_code: i16,
28    pub results_by_transaction: Vec<AddPartitionsToTxnResult<'a>>,
29    pub results_by_topic_v3_and_below: Vec<super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl AddPartitionsToTxnResponse<'_> {
33    #[must_use]
34    pub fn to_owned(&self) -> add_partitions_to_txn_response::AddPartitionsToTxnResponse {
35        add_partitions_to_txn_response::AddPartitionsToTxnResponse {
36            throttle_time_ms: (self.throttle_time_ms),
37            error_code: (self.error_code),
38            results_by_transaction: (self.results_by_transaction).iter().map(AddPartitionsToTxnResult::to_owned).collect(),
39            results_by_topic_v3_and_below: (self.results_by_topic_v3_and_below)
40                .iter()
41                .map(super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::to_owned)
42                .collect(),
43            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
44        }
45    }
46}
47impl Encode for AddPartitionsToTxnResponse<'_> {
48    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion {
51                api_key: API_KEY,
52                version,
53            });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 {
57            put_i32(buf, self.throttle_time_ms);
58        }
59        if version >= 4 {
60            put_i16(buf, self.error_code);
61        }
62        if version >= 4 {
63            {
64                put_array_len(buf, (self.results_by_transaction).len(), flex)?;
65                for it in &self.results_by_transaction {
66                    it.encode(buf, version)?;
67                }
68            }
69        }
70        if (0..=3).contains(&version) {
71            {
72                put_array_len(buf, (self.results_by_topic_v3_and_below).len(), flex)?;
73                for it in &self.results_by_topic_v3_and_below {
74                    it.encode(buf, version)?;
75                }
76            }
77        }
78        if flex {
79            let tagged = WriteTaggedFields::new();
80            tagged.write(buf, &self.unknown_tagged_fields)?;
81        }
82        Ok(())
83    }
84    fn encoded_len(&self, version: i16) -> usize {
85        let flex = is_flexible(version);
86        let mut n: usize = 0;
87        if version >= 0 {
88            n += 4;
89        }
90        if version >= 4 {
91            n += 2;
92        }
93        if version >= 4 {
94            n += {
95                let prefix = array_len_prefix_len((self.results_by_transaction).len(), flex);
96                let body: usize = (self.results_by_transaction)
97                    .iter()
98                    .map(|it| it.encoded_len(version))
99                    .sum();
100                prefix + body
101            };
102        }
103        if (0..=3).contains(&version) {
104            n += {
105                let prefix = array_len_prefix_len((self.results_by_topic_v3_and_below).len(), flex);
106                let body: usize = (self.results_by_topic_v3_and_below)
107                    .iter()
108                    .map(|it| it.encoded_len(version))
109                    .sum();
110                prefix + body
111            };
112        }
113        if flex {
114            let known_pairs: Vec<(u32, usize)> = Vec::new();
115            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
116        }
117        n
118    }
119}
120impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnResponse<'de> {
121    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
122        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
123            return Err(ProtocolError::UnsupportedVersion {
124                api_key: API_KEY,
125                version,
126            });
127        }
128        let flex = is_flexible(version);
129        let mut out = Self::default();
130        if version >= 0 {
131            out.throttle_time_ms = get_i32(buf)?;
132        }
133        if version >= 4 {
134            out.error_code = get_i16(buf)?;
135        }
136        if version >= 4 {
137            out.results_by_transaction = {
138                let n = get_array_len(buf, flex)?;
139                let mut v = Vec::with_capacity(n);
140                for _ in 0..n {
141                    v.push(AddPartitionsToTxnResult::decode_borrow(buf, version)?);
142                }
143                v
144            };
145        }
146        if (0..=3).contains(&version) {
147            out.results_by_topic_v3_and_below = {
148                let n = get_array_len(buf, flex)?;
149                let mut v = Vec::with_capacity(n);
150                for _ in 0..n {
151                    v.push(super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode_borrow(buf, version)?);
152                }
153                v
154            };
155        }
156        if flex {
157            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
158        }
159        Ok(out)
160    }
161}
162#[cfg(test)]
163impl AddPartitionsToTxnResponse<'_> {
164    #[must_use]
165    pub fn populated(version: i16) -> Self {
166        let mut m = Self::default();
167        if version >= 0 {
168            m.throttle_time_ms = 1i32;
169        }
170        if version >= 4 {
171            m.error_code = 1i16;
172        }
173        if version >= 4 {
174            m.results_by_transaction = vec![AddPartitionsToTxnResult::populated(version)];
175        }
176        if (0..=3).contains(&version) {
177            m.results_by_topic_v3_and_below = vec![super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::populated(version)];
178        }
179        m
180    }
181}
182#[derive(Debug, Clone, PartialEq, Eq, Default)]
183pub struct AddPartitionsToTxnResult<'a> {
184    pub transactional_id: &'a str,
185    pub topic_results: Vec<super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult<'a>>,
186    pub unknown_tagged_fields: UnknownTaggedFields,
187}
188impl AddPartitionsToTxnResult<'_> {
189    #[must_use]
190    pub fn to_owned(&self) -> add_partitions_to_txn_response::AddPartitionsToTxnResult {
191        add_partitions_to_txn_response::AddPartitionsToTxnResult {
192            transactional_id: (self.transactional_id).to_owned(),
193            topic_results: (self.topic_results)
194                .iter()
195                .map(super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::to_owned)
196                .collect(),
197            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
198        }
199    }
200}
201impl Encode for AddPartitionsToTxnResult<'_> {
202    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
203        let flex = version >= 3;
204        if version >= 4 {
205            if flex {
206                put_compact_string(buf, self.transactional_id)?;
207            } else {
208                put_string(buf, self.transactional_id)?;
209            }
210        }
211        if version >= 4 {
212            {
213                put_array_len(buf, (self.topic_results).len(), flex)?;
214                for it in &self.topic_results {
215                    it.encode(buf, version)?;
216                }
217            }
218        }
219        if flex {
220            let tagged = WriteTaggedFields::new();
221            tagged.write(buf, &self.unknown_tagged_fields)?;
222        }
223        Ok(())
224    }
225    fn encoded_len(&self, version: i16) -> usize {
226        let flex = version >= 3;
227        let mut n: usize = 0;
228        if version >= 4 {
229            n += if flex {
230                compact_string_len(self.transactional_id)
231            } else {
232                string_len(self.transactional_id)
233            };
234        }
235        if version >= 4 {
236            n += {
237                let prefix = array_len_prefix_len((self.topic_results).len(), flex);
238                let body: usize = (self.topic_results)
239                    .iter()
240                    .map(|it| it.encoded_len(version))
241                    .sum();
242                prefix + body
243            };
244        }
245        if flex {
246            let known_pairs: Vec<(u32, usize)> = Vec::new();
247            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
248        }
249        n
250    }
251}
252impl<'de> DecodeBorrow<'de> for AddPartitionsToTxnResult<'de> {
253    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
254        let flex = version >= 3;
255        let mut out = Self::default();
256        if version >= 4 {
257            out.transactional_id = if flex {
258                get_compact_string_borrowed(buf)?
259            } else {
260                get_string_borrowed(buf)?
261            };
262        }
263        if version >= 4 {
264            out.topic_results = {
265                let n = get_array_len(buf, flex)?;
266                let mut v = Vec::with_capacity(n);
267                for _ in 0..n {
268                    v.push(super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode_borrow(buf, version)?);
269                }
270                v
271            };
272        }
273        if flex {
274            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
275        }
276        Ok(out)
277    }
278}
279#[cfg(test)]
280impl AddPartitionsToTxnResult<'_> {
281    #[must_use]
282    pub fn populated(version: i16) -> Self {
283        let mut m = Self::default();
284        if version >= 4 {
285            m.transactional_id = "x";
286        }
287        if version >= 4 {
288            m.topic_results = vec![super::common::add_partitions_to_txn_response::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::populated(version)];
289        }
290        m
291    }
292}