Skip to main content

kacrab_protocol/generated/
add_partitions_to_txn_request.rs

1//! Generated from AddPartitionsToTxnRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct AddPartitionsToTxnRequestData {
17    /// List of transactions to add partitions to.
18    pub transactions: Vec<AddPartitionsToTxnTransaction>,
19    /// The transactional id corresponding to the transaction.
20    pub v3_and_below_transactional_id: KafkaString,
21    /// Current producer id in use by the transactional id.
22    pub v3_and_below_producer_id: i64,
23    /// Current epoch associated with the producer id.
24    pub v3_and_below_producer_epoch: i16,
25    /// The partitions to add to the transaction.
26    pub v3_and_below_topics: Vec<AddPartitionsToTxnTopic>,
27    pub _unknown_tagged_fields: Vec<RawTaggedField>,
28}
29impl Default for AddPartitionsToTxnRequestData {
30    fn default() -> Self {
31        Self {
32            transactions: Vec::new(),
33            v3_and_below_transactional_id: KafkaString::default(),
34            v3_and_below_producer_id: 0_i64,
35            v3_and_below_producer_epoch: 0_i16,
36            v3_and_below_topics: Vec::new(),
37            _unknown_tagged_fields: Vec::new(),
38        }
39    }
40}
41impl AddPartitionsToTxnRequestData {
42    pub fn with_transactions(mut self, value: Vec<AddPartitionsToTxnTransaction>) -> Self {
43        self.transactions = value;
44        self
45    }
46    pub fn with_v3_and_below_transactional_id(mut self, value: KafkaString) -> Self {
47        self.v3_and_below_transactional_id = value;
48        self
49    }
50    pub fn with_v3_and_below_producer_id(mut self, value: i64) -> Self {
51        self.v3_and_below_producer_id = value;
52        self
53    }
54    pub fn with_v3_and_below_producer_epoch(mut self, value: i16) -> Self {
55        self.v3_and_below_producer_epoch = value;
56        self
57    }
58    pub fn with_v3_and_below_topics(mut self, value: Vec<AddPartitionsToTxnTopic>) -> Self {
59        self.v3_and_below_topics = value;
60        self
61    }
62    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
63        if version < 0 || version > 5 {
64            return Err(UnsupportedVersion::new(24, version).into());
65        }
66        let mut transactions = Vec::new();
67        let mut v3_and_below_transactional_id = KafkaString::default();
68        let mut v3_and_below_producer_id = 0_i64;
69        let mut v3_and_below_producer_epoch = 0_i16;
70        let mut v3_and_below_topics = Vec::new();
71        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
72        if version >= 4 {
73            transactions = {
74                let len = read_compact_array_length(buf)?;
75                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
76                for _ in 0..len {
77                    arr.push(AddPartitionsToTxnTransaction::read(buf, version)?);
78                }
79                arr
80            };
81        }
82        if version <= 3 {
83            if version >= 3 {
84                v3_and_below_transactional_id = read_compact_string(buf)?;
85            } else {
86                v3_and_below_transactional_id = read_string(buf)?;
87            }
88        }
89        if version <= 3 {
90            v3_and_below_producer_id = read_i64(buf)?;
91        }
92        if version <= 3 {
93            v3_and_below_producer_epoch = read_i16(buf)?;
94        }
95        if version <= 3 {
96            if version >= 3 {
97                v3_and_below_topics = {
98                    let len = read_compact_array_length(buf)?;
99                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
100                    for _ in 0..len {
101                        arr.push(AddPartitionsToTxnTopic::read(buf, version)?);
102                    }
103                    arr
104                };
105            } else {
106                v3_and_below_topics = {
107                    let len = read_array_length(buf)?;
108                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
109                    for _ in 0..len {
110                        arr.push(AddPartitionsToTxnTopic::read(buf, version)?);
111                    }
112                    arr
113                };
114            }
115        }
116        if version >= 3 {
117            let tagged_fields = read_tagged_fields(buf)?;
118            for field in &tagged_fields {
119                match field.tag {
120                    _ => {
121                        _unknown_tagged_fields.push(field.clone());
122                    },
123                }
124            }
125        }
126        Ok(Self {
127            transactions,
128            v3_and_below_transactional_id,
129            v3_and_below_producer_id,
130            v3_and_below_producer_epoch,
131            v3_and_below_topics,
132            _unknown_tagged_fields,
133        })
134    }
135    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
136        if version < 0 || version > 5 {
137            return Err(UnsupportedVersion::new(24, version).into());
138        }
139        if version >= 4 {
140            write_compact_array_length(buf, self.transactions.len() as i32);
141            for el in &self.transactions {
142                el.write(buf, version)?;
143            }
144        } else if self.transactions != Vec::new() {
145            return Err(UnsupportedFieldVersion::new(24, "transactions", version).into());
146        }
147        if version <= 3 {
148            if version >= 3 {
149                write_compact_string(buf, &self.v3_and_below_transactional_id)?;
150            } else {
151                write_string(buf, &self.v3_and_below_transactional_id)?;
152            }
153        } else if self.v3_and_below_transactional_id != KafkaString::default() {
154            return Err(
155                UnsupportedFieldVersion::new(24, "v3_and_below_transactional_id", version).into(),
156            );
157        }
158        if version <= 3 {
159            write_i64(buf, self.v3_and_below_producer_id);
160        } else if self.v3_and_below_producer_id != 0_i64 {
161            return Err(
162                UnsupportedFieldVersion::new(24, "v3_and_below_producer_id", version).into(),
163            );
164        }
165        if version <= 3 {
166            write_i16(buf, self.v3_and_below_producer_epoch);
167        } else if self.v3_and_below_producer_epoch != 0_i16 {
168            return Err(
169                UnsupportedFieldVersion::new(24, "v3_and_below_producer_epoch", version).into(),
170            );
171        }
172        if version <= 3 {
173            if version >= 3 {
174                write_compact_array_length(buf, self.v3_and_below_topics.len() as i32);
175                for el in &self.v3_and_below_topics {
176                    el.write(buf, version)?;
177                }
178            } else {
179                write_array_length(buf, self.v3_and_below_topics.len() as i32);
180                for el in &self.v3_and_below_topics {
181                    el.write(buf, version)?;
182                }
183            }
184        } else if self.v3_and_below_topics != Vec::new() {
185            return Err(UnsupportedFieldVersion::new(24, "v3_and_below_topics", version).into());
186        }
187        if version >= 3 {
188            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
189            all_tags.sort_by_key(|f| f.tag);
190            write_tagged_fields(buf, &all_tags)?;
191        }
192        Ok(())
193    }
194    pub fn encoded_len(&self, version: i16) -> Result<usize> {
195        if version < 0 || version > 5 {
196            return Err(UnsupportedVersion::new(24, version).into());
197        }
198        let mut len: usize = 0;
199        if version >= 4 {
200            len += compact_array_length_len(self.transactions.len() as i32);
201            for el in &self.transactions {
202                len += el.encoded_len(version)?;
203            }
204        } else if self.transactions != Vec::new() {
205            return Err(UnsupportedFieldVersion::new(24, "transactions", version).into());
206        }
207        if version <= 3 {
208            if version >= 3 {
209                len += compact_string_len(&self.v3_and_below_transactional_id)?;
210            } else {
211                len += string_len(&self.v3_and_below_transactional_id)?;
212            }
213        } else if self.v3_and_below_transactional_id != KafkaString::default() {
214            return Err(
215                UnsupportedFieldVersion::new(24, "v3_and_below_transactional_id", version).into(),
216            );
217        }
218        if version <= 3 {
219            len += 8;
220        } else if self.v3_and_below_producer_id != 0_i64 {
221            return Err(
222                UnsupportedFieldVersion::new(24, "v3_and_below_producer_id", version).into(),
223            );
224        }
225        if version <= 3 {
226            len += 2;
227        } else if self.v3_and_below_producer_epoch != 0_i16 {
228            return Err(
229                UnsupportedFieldVersion::new(24, "v3_and_below_producer_epoch", version).into(),
230            );
231        }
232        if version <= 3 {
233            if version >= 3 {
234                len += compact_array_length_len(self.v3_and_below_topics.len() as i32);
235                for el in &self.v3_and_below_topics {
236                    len += el.encoded_len(version)?;
237                }
238            } else {
239                len += array_length_len();
240                for el in &self.v3_and_below_topics {
241                    len += el.encoded_len(version)?;
242                }
243            }
244        } else if self.v3_and_below_topics != Vec::new() {
245            return Err(UnsupportedFieldVersion::new(24, "v3_and_below_topics", version).into());
246        }
247        if version >= 3 {
248            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
249            all_tags.sort_by_key(|f| f.tag);
250            len += tagged_fields_len(&all_tags)?;
251        }
252        Ok(len)
253    }
254}
255#[derive(Debug, Clone, PartialEq)]
256pub struct AddPartitionsToTxnTransaction {
257    /// The transactional id corresponding to the transaction.
258    pub transactional_id: KafkaString,
259    /// Current producer id in use by the transactional id.
260    pub producer_id: i64,
261    /// Current epoch associated with the producer id.
262    pub producer_epoch: i16,
263    /// Boolean to signify if we want to check if the partition is in the transaction rather than
264    /// add it.
265    pub verify_only: bool,
266    /// The partitions to add to the transaction.
267    pub topics: Vec<AddPartitionsToTxnTopic>,
268    pub _unknown_tagged_fields: Vec<RawTaggedField>,
269}
270impl Default for AddPartitionsToTxnTransaction {
271    fn default() -> Self {
272        Self {
273            transactional_id: KafkaString::default(),
274            producer_id: 0_i64,
275            producer_epoch: 0_i16,
276            verify_only: false,
277            topics: Vec::new(),
278            _unknown_tagged_fields: Vec::new(),
279        }
280    }
281}
282impl AddPartitionsToTxnTransaction {
283    pub fn with_transactional_id(mut self, value: KafkaString) -> Self {
284        self.transactional_id = value;
285        self
286    }
287    pub fn with_producer_id(mut self, value: i64) -> Self {
288        self.producer_id = value;
289        self
290    }
291    pub fn with_producer_epoch(mut self, value: i16) -> Self {
292        self.producer_epoch = value;
293        self
294    }
295    pub fn with_verify_only(mut self, value: bool) -> Self {
296        self.verify_only = value;
297        self
298    }
299    pub fn with_topics(mut self, value: Vec<AddPartitionsToTxnTopic>) -> Self {
300        self.topics = value;
301        self
302    }
303    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
304        let transactional_id;
305        let producer_id;
306        let producer_epoch;
307        let verify_only;
308        let topics;
309        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
310        transactional_id = read_compact_string(buf)?;
311        producer_id = read_i64(buf)?;
312        producer_epoch = read_i16(buf)?;
313        verify_only = read_bool(buf)?;
314        topics = {
315            let len = read_compact_array_length(buf)?;
316            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
317            for _ in 0..len {
318                arr.push(AddPartitionsToTxnTopic::read(buf, version)?);
319            }
320            arr
321        };
322        let tagged_fields = read_tagged_fields(buf)?;
323        for field in &tagged_fields {
324            match field.tag {
325                _ => {
326                    _unknown_tagged_fields.push(field.clone());
327                },
328            }
329        }
330        Ok(Self {
331            transactional_id,
332            producer_id,
333            producer_epoch,
334            verify_only,
335            topics,
336            _unknown_tagged_fields,
337        })
338    }
339    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
340        write_compact_string(buf, &self.transactional_id)?;
341        write_i64(buf, self.producer_id);
342        write_i16(buf, self.producer_epoch);
343        write_bool(buf, self.verify_only);
344        write_compact_array_length(buf, self.topics.len() as i32);
345        for el in &self.topics {
346            el.write(buf, version)?;
347        }
348        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
349        all_tags.sort_by_key(|f| f.tag);
350        write_tagged_fields(buf, &all_tags)?;
351        Ok(())
352    }
353    pub fn encoded_len(&self, version: i16) -> Result<usize> {
354        let mut len: usize = 0;
355        len += compact_string_len(&self.transactional_id)?;
356        len += 8;
357        len += 2;
358        len += 1;
359        len += compact_array_length_len(self.topics.len() as i32);
360        for el in &self.topics {
361            len += el.encoded_len(version)?;
362        }
363        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
364        all_tags.sort_by_key(|f| f.tag);
365        len += tagged_fields_len(&all_tags)?;
366        Ok(len)
367    }
368}
369#[derive(Debug, Clone, PartialEq)]
370pub struct AddPartitionsToTxnTopic {
371    /// The name of the topic.
372    pub name: KafkaString,
373    /// The partition indexes to add to the transaction.
374    pub partitions: Vec<i32>,
375    pub _unknown_tagged_fields: Vec<RawTaggedField>,
376}
377impl Default for AddPartitionsToTxnTopic {
378    fn default() -> Self {
379        Self {
380            name: KafkaString::default(),
381            partitions: Vec::new(),
382            _unknown_tagged_fields: Vec::new(),
383        }
384    }
385}
386impl AddPartitionsToTxnTopic {
387    pub fn with_name(mut self, value: KafkaString) -> Self {
388        self.name = value;
389        self
390    }
391    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
392        self.partitions = value;
393        self
394    }
395    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
396        let name;
397        let partitions;
398        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
399        if version >= 3 {
400            name = read_compact_string(buf)?;
401        } else {
402            name = read_string(buf)?;
403        }
404        if version >= 3 {
405            partitions = {
406                let len = read_compact_array_length(buf)?;
407                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
408                for _ in 0..len {
409                    arr.push(read_i32(buf)?);
410                }
411                arr
412            };
413        } else {
414            partitions = {
415                let len = read_array_length(buf)?;
416                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
417                for _ in 0..len {
418                    arr.push(read_i32(buf)?);
419                }
420                arr
421            };
422        }
423        if version >= 3 {
424            let tagged_fields = read_tagged_fields(buf)?;
425            for field in &tagged_fields {
426                match field.tag {
427                    _ => {
428                        _unknown_tagged_fields.push(field.clone());
429                    },
430                }
431            }
432        }
433        Ok(Self {
434            name,
435            partitions,
436            _unknown_tagged_fields,
437        })
438    }
439    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
440        if version >= 3 {
441            write_compact_string(buf, &self.name)?;
442        } else {
443            write_string(buf, &self.name)?;
444        }
445        if version >= 3 {
446            write_compact_array_length(buf, self.partitions.len() as i32);
447            for el in &self.partitions {
448                write_i32(buf, *el);
449            }
450        } else {
451            write_array_length(buf, self.partitions.len() as i32);
452            for el in &self.partitions {
453                write_i32(buf, *el);
454            }
455        }
456        if version >= 3 {
457            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
458            all_tags.sort_by_key(|f| f.tag);
459            write_tagged_fields(buf, &all_tags)?;
460        }
461        Ok(())
462    }
463    pub fn encoded_len(&self, version: i16) -> Result<usize> {
464        let mut len: usize = 0;
465        if version >= 3 {
466            len += compact_string_len(&self.name)?;
467        } else {
468            len += string_len(&self.name)?;
469        }
470        if version >= 3 {
471            len += compact_array_length_len(self.partitions.len() as i32);
472            len += self.partitions.len() * 4usize;
473        } else {
474            len += array_length_len();
475            len += self.partitions.len() * 4usize;
476        }
477        if version >= 3 {
478            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
479            all_tags.sort_by_key(|f| f.tag);
480            len += tagged_fields_len(&all_tags)?;
481        }
482        Ok(len)
483    }
484}