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