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