crabka_protocol/opt/rustwide/workdir/generated/
AddPartitionsToTxnRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i64, put_bool, put_i16, put_i64};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8 string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, 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 AddPartitionsToTxnRequest { pub transactions : Vec < AddPartitionsToTxnTransaction > , pub v3_and_below_transactional_id : String , pub v3_and_below_producer_id : i64 , pub v3_and_below_producer_epoch : i16 , pub v3_and_below_topics : Vec < super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic > , pub unknown_tagged_fields : UnknownTaggedFields , }
25impl Encode for AddPartitionsToTxnRequest {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion {
29 api_key: API_KEY,
30 version,
31 });
32 }
33 let flex = is_flexible(version);
34 if version >= 4 {
35 {
36 crate::primitives::array::put_array_len(buf, (self.transactions).len(), flex);
37 for it in &self.transactions {
38 it.encode(buf, version)?;
39 }
40 }
41 }
42 if (0..=3).contains(&version) {
43 if flex {
44 put_compact_string(buf, &self.v3_and_below_transactional_id);
45 } else {
46 put_string(buf, &self.v3_and_below_transactional_id);
47 }
48 }
49 if (0..=3).contains(&version) {
50 put_i64(buf, self.v3_and_below_producer_id);
51 }
52 if (0..=3).contains(&version) {
53 put_i16(buf, self.v3_and_below_producer_epoch);
54 }
55 if (0..=3).contains(&version) {
56 {
57 crate::primitives::array::put_array_len(
58 buf,
59 (self.v3_and_below_topics).len(),
60 flex,
61 );
62 for it in &self.v3_and_below_topics {
63 it.encode(buf, version)?;
64 }
65 }
66 }
67 if flex {
68 let tagged = WriteTaggedFields::new();
69 tagged.write(buf, &self.unknown_tagged_fields);
70 }
71 Ok(())
72 }
73 fn encoded_len(&self, version: i16) -> usize {
74 let flex = is_flexible(version);
75 let mut n: usize = 0;
76 if version >= 4 {
77 n += {
78 let prefix =
79 crate::primitives::array::array_len_prefix_len((self.transactions).len(), flex);
80 let body: usize = (self.transactions)
81 .iter()
82 .map(|it| it.encoded_len(version))
83 .sum();
84 prefix + body
85 };
86 }
87 if (0..=3).contains(&version) {
88 n += if flex {
89 compact_string_len(&self.v3_and_below_transactional_id)
90 } else {
91 string_len(&self.v3_and_below_transactional_id)
92 };
93 }
94 if (0..=3).contains(&version) {
95 n += 8;
96 }
97 if (0..=3).contains(&version) {
98 n += 2;
99 }
100 if (0..=3).contains(&version) {
101 n += {
102 let prefix = crate::primitives::array::array_len_prefix_len(
103 (self.v3_and_below_topics).len(),
104 flex,
105 );
106 let body: usize = (self.v3_and_below_topics)
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 Decode<'_> for AddPartitionsToTxnRequest {
121 fn decode<B: Buf>(buf: &mut B, 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 >= 4 {
131 out.transactions = {
132 let n = crate::primitives::array::get_array_len(buf, flex)?;
133 let mut v = Vec::with_capacity(n);
134 for _ in 0..n {
135 v.push(AddPartitionsToTxnTransaction::decode(buf, version)?);
136 }
137 v
138 };
139 }
140 if (0..=3).contains(&version) {
141 out.v3_and_below_transactional_id = if flex {
142 get_compact_string_owned(buf)?
143 } else {
144 get_string_owned(buf)?
145 };
146 }
147 if (0..=3).contains(&version) {
148 out.v3_and_below_producer_id = get_i64(buf)?;
149 }
150 if (0..=3).contains(&version) {
151 out.v3_and_below_producer_epoch = get_i16(buf)?;
152 }
153 if (0..=3).contains(&version) {
154 out.v3_and_below_topics = {
155 let n = crate::primitives::array::get_array_len(buf, flex)?;
156 let mut v = Vec::with_capacity(n);
157 for _ in 0..n {
158 v . push (super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: decode (buf , version) ?) ;
159 }
160 v
161 };
162 }
163 if flex {
164 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
165 }
166 Ok(out)
167 }
168}
169#[cfg(test)]
170impl AddPartitionsToTxnRequest {
171 #[must_use]
172 pub fn populated(version: i16) -> Self {
173 let mut m = Self::default();
174 if version >= 4 {
175 m.transactions = vec![AddPartitionsToTxnTransaction::populated(version)];
176 }
177 if (0..=3).contains(&version) {
178 m.v3_and_below_transactional_id = "x".to_string();
179 }
180 if (0..=3).contains(&version) {
181 m.v3_and_below_producer_id = 1i64;
182 }
183 if (0..=3).contains(&version) {
184 m.v3_and_below_producer_epoch = 1i16;
185 }
186 if (0..=3).contains(&version) {
187 m . v3_and_below_topics = vec ! [super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: populated (version)] ;
188 }
189 m
190 }
191}
192#[derive(Debug, Clone, PartialEq, Eq, Default)]
193pub struct AddPartitionsToTxnTransaction { pub transactional_id : String , pub producer_id : i64 , pub producer_epoch : i16 , pub verify_only : bool , pub topics : Vec < super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic > , pub unknown_tagged_fields : UnknownTaggedFields , }
194impl Encode for AddPartitionsToTxnTransaction {
195 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
196 let flex = version >= 3;
197 if version >= 4 {
198 if flex {
199 put_compact_string(buf, &self.transactional_id);
200 } else {
201 put_string(buf, &self.transactional_id);
202 }
203 }
204 if version >= 4 {
205 put_i64(buf, self.producer_id);
206 }
207 if version >= 4 {
208 put_i16(buf, self.producer_epoch);
209 }
210 if version >= 4 {
211 put_bool(buf, self.verify_only);
212 }
213 if version >= 4 {
214 {
215 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
216 for it in &self.topics {
217 it.encode(buf, version)?;
218 }
219 }
220 }
221 if flex {
222 let tagged = WriteTaggedFields::new();
223 tagged.write(buf, &self.unknown_tagged_fields);
224 }
225 Ok(())
226 }
227 fn encoded_len(&self, version: i16) -> usize {
228 let flex = version >= 3;
229 let mut n: usize = 0;
230 if version >= 4 {
231 n += if flex {
232 compact_string_len(&self.transactional_id)
233 } else {
234 string_len(&self.transactional_id)
235 };
236 }
237 if version >= 4 {
238 n += 8;
239 }
240 if version >= 4 {
241 n += 2;
242 }
243 if version >= 4 {
244 n += 1;
245 }
246 if version >= 4 {
247 n += {
248 let prefix =
249 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
250 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
251 prefix + body
252 };
253 }
254 if flex {
255 let known_pairs: Vec<(u32, usize)> = Vec::new();
256 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
257 }
258 n
259 }
260}
261impl Decode<'_> for AddPartitionsToTxnTransaction {
262 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
263 let flex = version >= 3;
264 let mut out = Self::default();
265 if version >= 4 {
266 out.transactional_id = if flex {
267 get_compact_string_owned(buf)?
268 } else {
269 get_string_owned(buf)?
270 };
271 }
272 if version >= 4 {
273 out.producer_id = get_i64(buf)?;
274 }
275 if version >= 4 {
276 out.producer_epoch = get_i16(buf)?;
277 }
278 if version >= 4 {
279 out.verify_only = get_bool(buf)?;
280 }
281 if version >= 4 {
282 out.topics = {
283 let n = crate::primitives::array::get_array_len(buf, flex)?;
284 let mut v = Vec::with_capacity(n);
285 for _ in 0..n {
286 v . push (super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: decode (buf , version) ?) ;
287 }
288 v
289 };
290 }
291 if flex {
292 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
293 }
294 Ok(out)
295 }
296}
297#[cfg(test)]
298impl AddPartitionsToTxnTransaction {
299 #[must_use]
300 pub fn populated(version: i16) -> Self {
301 let mut m = Self::default();
302 if version >= 4 {
303 m.transactional_id = "x".to_string();
304 }
305 if version >= 4 {
306 m.producer_id = 1i64;
307 }
308 if version >= 4 {
309 m.producer_epoch = 1i16;
310 }
311 if version >= 4 {
312 m.verify_only = true;
313 }
314 if version >= 4 {
315 m . topics = vec ! [super :: common :: add_partitions_to_txn_request :: add_partitions_to_txn_topic :: AddPartitionsToTxnTopic :: populated (version)] ;
316 }
317 m
318 }
319}
320
321#[must_use]
324#[allow(unused_comparisons)]
325pub fn default_json(version: i16) -> ::serde_json::Value {
326 let mut obj = ::serde_json::Map::new();
327 if version >= 4 {
328 obj.insert(
329 "transactions".to_string(),
330 ::serde_json::Value::Array(vec![]),
331 );
332 }
333 if version <= 3 {
334 obj.insert(
335 "v3AndBelowTransactionalId".to_string(),
336 ::serde_json::Value::String(String::new()),
337 );
338 }
339 if version <= 3 {
340 obj.insert("v3AndBelowProducerId".to_string(), ::serde_json::json!(0));
341 }
342 if version <= 3 {
343 obj.insert(
344 "v3AndBelowProducerEpoch".to_string(),
345 ::serde_json::json!(0),
346 );
347 }
348 if version <= 3 {
349 obj.insert(
350 "v3AndBelowTopics".to_string(),
351 ::serde_json::Value::Array(vec![]),
352 );
353 }
354 ::serde_json::Value::Object(obj)
355}
356
357impl crate::ProtocolRequest for AddPartitionsToTxnRequest {
358 const API_KEY: i16 = API_KEY;
359 const MIN_VERSION: i16 = MIN_VERSION;
360 const MAX_VERSION: i16 = MAX_VERSION;
361 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
362 type Response = super::add_partitions_to_txn_response::AddPartitionsToTxnResponse;
363}