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