Skip to main content

kacrab_protocol/generated/
add_partitions_to_txn_response.rs

1//! Generated from AddPartitionsToTxnResponse.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 AddPartitionsToTxnResponseData {
17    /// Duration in milliseconds for which the request was throttled due to a quota violation, or
18    /// zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The response top level error code.
21    pub error_code: i16,
22    /// Results categorized by transactional ID.
23    pub results_by_transaction: Vec<AddPartitionsToTxnResult>,
24    /// The results for each topic.
25    pub results_by_topic_v3_and_below: Vec<AddPartitionsToTxnTopicResult>,
26    pub _unknown_tagged_fields: Vec<RawTaggedField>,
27}
28impl Default for AddPartitionsToTxnResponseData {
29    fn default() -> Self {
30        Self {
31            throttle_time_ms: 0_i32,
32            error_code: 0_i16,
33            results_by_transaction: Vec::new(),
34            results_by_topic_v3_and_below: Vec::new(),
35            _unknown_tagged_fields: Vec::new(),
36        }
37    }
38}
39impl AddPartitionsToTxnResponseData {
40    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
41        self.throttle_time_ms = value;
42        self
43    }
44    pub fn with_error_code(mut self, value: i16) -> Self {
45        self.error_code = value;
46        self
47    }
48    pub fn with_results_by_transaction(mut self, value: Vec<AddPartitionsToTxnResult>) -> Self {
49        self.results_by_transaction = value;
50        self
51    }
52    pub fn with_results_by_topic_v3_and_below(
53        mut self,
54        value: Vec<AddPartitionsToTxnTopicResult>,
55    ) -> Self {
56        self.results_by_topic_v3_and_below = value;
57        self
58    }
59    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
60        if version < 0 || version > 5 {
61            return Err(UnsupportedVersion::new(24, version).into());
62        }
63        let throttle_time_ms;
64        let mut error_code = 0_i16;
65        let mut results_by_transaction = Vec::new();
66        let mut results_by_topic_v3_and_below = Vec::new();
67        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
68        throttle_time_ms = read_i32(buf)?;
69        if version >= 4 {
70            error_code = read_i16(buf)?;
71        }
72        if version >= 4 {
73            results_by_transaction = {
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(AddPartitionsToTxnResult::read(buf, version)?);
78                }
79                arr
80            };
81        }
82        if version <= 3 {
83            if version >= 3 {
84                results_by_topic_v3_and_below = {
85                    let len = read_compact_array_length(buf)?;
86                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
87                    for _ in 0..len {
88                        arr.push(AddPartitionsToTxnTopicResult::read(buf, version)?);
89                    }
90                    arr
91                };
92            } else {
93                results_by_topic_v3_and_below = {
94                    let len = read_array_length(buf)?;
95                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
96                    for _ in 0..len {
97                        arr.push(AddPartitionsToTxnTopicResult::read(buf, version)?);
98                    }
99                    arr
100                };
101            }
102        }
103        if version >= 3 {
104            let tagged_fields = read_tagged_fields(buf)?;
105            for field in &tagged_fields {
106                match field.tag {
107                    _ => {
108                        _unknown_tagged_fields.push(field.clone());
109                    },
110                }
111            }
112        }
113        Ok(Self {
114            throttle_time_ms,
115            error_code,
116            results_by_transaction,
117            results_by_topic_v3_and_below,
118            _unknown_tagged_fields,
119        })
120    }
121    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
122        if version < 0 || version > 5 {
123            return Err(UnsupportedVersion::new(24, version).into());
124        }
125        write_i32(buf, self.throttle_time_ms);
126        if version >= 4 {
127            write_i16(buf, self.error_code);
128        } else if self.error_code != 0_i16 {
129            return Err(UnsupportedFieldVersion::new(24, "error_code", version).into());
130        }
131        if version >= 4 {
132            write_compact_array_length(buf, self.results_by_transaction.len() as i32);
133            for el in &self.results_by_transaction {
134                el.write(buf, version)?;
135            }
136        } else if self.results_by_transaction != Vec::new() {
137            return Err(UnsupportedFieldVersion::new(24, "results_by_transaction", version).into());
138        }
139        if version <= 3 {
140            if version >= 3 {
141                write_compact_array_length(buf, self.results_by_topic_v3_and_below.len() as i32);
142                for el in &self.results_by_topic_v3_and_below {
143                    el.write(buf, version)?;
144                }
145            } else {
146                write_array_length(buf, self.results_by_topic_v3_and_below.len() as i32);
147                for el in &self.results_by_topic_v3_and_below {
148                    el.write(buf, version)?;
149                }
150            }
151        } else if self.results_by_topic_v3_and_below != Vec::new() {
152            return Err(
153                UnsupportedFieldVersion::new(24, "results_by_topic_v3_and_below", version).into(),
154            );
155        }
156        if version >= 3 {
157            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
158            all_tags.sort_by_key(|f| f.tag);
159            write_tagged_fields(buf, &all_tags)?;
160        }
161        Ok(())
162    }
163    pub fn encoded_len(&self, version: i16) -> Result<usize> {
164        if version < 0 || version > 5 {
165            return Err(UnsupportedVersion::new(24, version).into());
166        }
167        let mut len: usize = 0;
168        len += 4;
169        if version >= 4 {
170            len += 2;
171        } else if self.error_code != 0_i16 {
172            return Err(UnsupportedFieldVersion::new(24, "error_code", version).into());
173        }
174        if version >= 4 {
175            len += compact_array_length_len(self.results_by_transaction.len() as i32);
176            for el in &self.results_by_transaction {
177                len += el.encoded_len(version)?;
178            }
179        } else if self.results_by_transaction != Vec::new() {
180            return Err(UnsupportedFieldVersion::new(24, "results_by_transaction", version).into());
181        }
182        if version <= 3 {
183            if version >= 3 {
184                len += compact_array_length_len(self.results_by_topic_v3_and_below.len() as i32);
185                for el in &self.results_by_topic_v3_and_below {
186                    len += el.encoded_len(version)?;
187                }
188            } else {
189                len += array_length_len();
190                for el in &self.results_by_topic_v3_and_below {
191                    len += el.encoded_len(version)?;
192                }
193            }
194        } else if self.results_by_topic_v3_and_below != Vec::new() {
195            return Err(
196                UnsupportedFieldVersion::new(24, "results_by_topic_v3_and_below", version).into(),
197            );
198        }
199        if version >= 3 {
200            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
201            all_tags.sort_by_key(|f| f.tag);
202            len += tagged_fields_len(&all_tags)?;
203        }
204        Ok(len)
205    }
206}
207#[derive(Debug, Clone, PartialEq)]
208pub struct AddPartitionsToTxnResult {
209    /// The transactional id corresponding to the transaction.
210    pub transactional_id: KafkaString,
211    /// The results for each topic.
212    pub topic_results: Vec<AddPartitionsToTxnTopicResult>,
213    pub _unknown_tagged_fields: Vec<RawTaggedField>,
214}
215impl Default for AddPartitionsToTxnResult {
216    fn default() -> Self {
217        Self {
218            transactional_id: KafkaString::default(),
219            topic_results: Vec::new(),
220            _unknown_tagged_fields: Vec::new(),
221        }
222    }
223}
224impl AddPartitionsToTxnResult {
225    pub fn with_transactional_id(mut self, value: KafkaString) -> Self {
226        self.transactional_id = value;
227        self
228    }
229    pub fn with_topic_results(mut self, value: Vec<AddPartitionsToTxnTopicResult>) -> Self {
230        self.topic_results = value;
231        self
232    }
233    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
234        let transactional_id;
235        let topic_results;
236        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
237        transactional_id = read_compact_string(buf)?;
238        topic_results = {
239            let len = read_compact_array_length(buf)?;
240            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
241            for _ in 0..len {
242                arr.push(AddPartitionsToTxnTopicResult::read(buf, version)?);
243            }
244            arr
245        };
246        let tagged_fields = read_tagged_fields(buf)?;
247        for field in &tagged_fields {
248            match field.tag {
249                _ => {
250                    _unknown_tagged_fields.push(field.clone());
251                },
252            }
253        }
254        Ok(Self {
255            transactional_id,
256            topic_results,
257            _unknown_tagged_fields,
258        })
259    }
260    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
261        write_compact_string(buf, &self.transactional_id)?;
262        write_compact_array_length(buf, self.topic_results.len() as i32);
263        for el in &self.topic_results {
264            el.write(buf, version)?;
265        }
266        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
267        all_tags.sort_by_key(|f| f.tag);
268        write_tagged_fields(buf, &all_tags)?;
269        Ok(())
270    }
271    pub fn encoded_len(&self, version: i16) -> Result<usize> {
272        let mut len: usize = 0;
273        len += compact_string_len(&self.transactional_id)?;
274        len += compact_array_length_len(self.topic_results.len() as i32);
275        for el in &self.topic_results {
276            len += el.encoded_len(version)?;
277        }
278        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
279        all_tags.sort_by_key(|f| f.tag);
280        len += tagged_fields_len(&all_tags)?;
281        Ok(len)
282    }
283}
284#[derive(Debug, Clone, PartialEq)]
285pub struct AddPartitionsToTxnTopicResult {
286    /// The topic name.
287    pub name: KafkaString,
288    /// The results for each partition.
289    pub results_by_partition: Vec<AddPartitionsToTxnPartitionResult>,
290    pub _unknown_tagged_fields: Vec<RawTaggedField>,
291}
292impl Default for AddPartitionsToTxnTopicResult {
293    fn default() -> Self {
294        Self {
295            name: KafkaString::default(),
296            results_by_partition: Vec::new(),
297            _unknown_tagged_fields: Vec::new(),
298        }
299    }
300}
301impl AddPartitionsToTxnTopicResult {
302    pub fn with_name(mut self, value: KafkaString) -> Self {
303        self.name = value;
304        self
305    }
306    pub fn with_results_by_partition(
307        mut self,
308        value: Vec<AddPartitionsToTxnPartitionResult>,
309    ) -> Self {
310        self.results_by_partition = value;
311        self
312    }
313    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
314        let name;
315        let results_by_partition;
316        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
317        if version >= 3 {
318            name = read_compact_string(buf)?;
319        } else {
320            name = read_string(buf)?;
321        }
322        if version >= 3 {
323            results_by_partition = {
324                let len = read_compact_array_length(buf)?;
325                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
326                for _ in 0..len {
327                    arr.push(AddPartitionsToTxnPartitionResult::read(buf, version)?);
328                }
329                arr
330            };
331        } else {
332            results_by_partition = {
333                let len = read_array_length(buf)?;
334                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
335                for _ in 0..len {
336                    arr.push(AddPartitionsToTxnPartitionResult::read(buf, version)?);
337                }
338                arr
339            };
340        }
341        if version >= 3 {
342            let tagged_fields = read_tagged_fields(buf)?;
343            for field in &tagged_fields {
344                match field.tag {
345                    _ => {
346                        _unknown_tagged_fields.push(field.clone());
347                    },
348                }
349            }
350        }
351        Ok(Self {
352            name,
353            results_by_partition,
354            _unknown_tagged_fields,
355        })
356    }
357    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
358        if version >= 3 {
359            write_compact_string(buf, &self.name)?;
360        } else {
361            write_string(buf, &self.name)?;
362        }
363        if version >= 3 {
364            write_compact_array_length(buf, self.results_by_partition.len() as i32);
365            for el in &self.results_by_partition {
366                el.write(buf, version)?;
367            }
368        } else {
369            write_array_length(buf, self.results_by_partition.len() as i32);
370            for el in &self.results_by_partition {
371                el.write(buf, version)?;
372            }
373        }
374        if version >= 3 {
375            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
376            all_tags.sort_by_key(|f| f.tag);
377            write_tagged_fields(buf, &all_tags)?;
378        }
379        Ok(())
380    }
381    pub fn encoded_len(&self, version: i16) -> Result<usize> {
382        let mut len: usize = 0;
383        if version >= 3 {
384            len += compact_string_len(&self.name)?;
385        } else {
386            len += string_len(&self.name)?;
387        }
388        if version >= 3 {
389            len += compact_array_length_len(self.results_by_partition.len() as i32);
390            for el in &self.results_by_partition {
391                len += el.encoded_len(version)?;
392            }
393        } else {
394            len += array_length_len();
395            for el in &self.results_by_partition {
396                len += el.encoded_len(version)?;
397            }
398        }
399        if version >= 3 {
400            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
401            all_tags.sort_by_key(|f| f.tag);
402            len += tagged_fields_len(&all_tags)?;
403        }
404        Ok(len)
405    }
406}
407#[derive(Debug, Clone, PartialEq)]
408pub struct AddPartitionsToTxnPartitionResult {
409    /// The partition indexes.
410    pub partition_index: i32,
411    /// The response error code.
412    pub partition_error_code: i16,
413    pub _unknown_tagged_fields: Vec<RawTaggedField>,
414}
415impl Default for AddPartitionsToTxnPartitionResult {
416    fn default() -> Self {
417        Self {
418            partition_index: 0_i32,
419            partition_error_code: 0_i16,
420            _unknown_tagged_fields: Vec::new(),
421        }
422    }
423}
424impl AddPartitionsToTxnPartitionResult {
425    pub fn with_partition_index(mut self, value: i32) -> Self {
426        self.partition_index = value;
427        self
428    }
429    pub fn with_partition_error_code(mut self, value: i16) -> Self {
430        self.partition_error_code = value;
431        self
432    }
433    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
434        let partition_index;
435        let partition_error_code;
436        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
437        partition_index = read_i32(buf)?;
438        partition_error_code = read_i16(buf)?;
439        if version >= 3 {
440            let tagged_fields = read_tagged_fields(buf)?;
441            for field in &tagged_fields {
442                match field.tag {
443                    _ => {
444                        _unknown_tagged_fields.push(field.clone());
445                    },
446                }
447            }
448        }
449        Ok(Self {
450            partition_index,
451            partition_error_code,
452            _unknown_tagged_fields,
453        })
454    }
455    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
456        write_i32(buf, self.partition_index);
457        write_i16(buf, self.partition_error_code);
458        if version >= 3 {
459            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
460            all_tags.sort_by_key(|f| f.tag);
461            write_tagged_fields(buf, &all_tags)?;
462        }
463        Ok(())
464    }
465    pub fn encoded_len(&self, version: i16) -> Result<usize> {
466        let mut len: usize = 0;
467        len += 4;
468        len += 2;
469        if version >= 3 {
470            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
471            all_tags.sort_by_key(|f| f.tag);
472            len += tagged_fields_len(&all_tags)?;
473        }
474        Ok(len)
475    }
476}