Skip to main content

odradek_protocol/messages/
add_partitions_to_txn_response.rs

1//! `AddPartitionsToTxnResponse` — generated from `schemas/AddPartitionsToTxnResponse.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 3
25}
26
27/// `AddPartitionsToTxnResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct AddPartitionsToTxnResponse {
31    /// Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
32    pub throttle_time_ms: i32,
33    /// The response top level error code.
34    pub error_code: i16,
35    /// Results categorized by transactional ID.
36    pub results_by_transaction: Vec<AddPartitionsToTxnResult>,
37    /// The results for each topic.
38    pub results_by_topic_v3_and_below: Vec<AddPartitionsToTxnTopicResult>,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for AddPartitionsToTxnResponse {
44    fn default() -> Self {
45        Self {
46            throttle_time_ms: 0,
47            error_code: 0,
48            results_by_transaction: Vec::new(),
49            results_by_topic_v3_and_below: Vec::new(),
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl AddPartitionsToTxnResponse {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 24;
58    /// The lowest schema version this snapshot can speak.
59    pub const MIN_VERSION: i16 = 0;
60    /// The highest schema version this snapshot can speak.
61    pub const MAX_VERSION: i16 = 5;
62
63    /// Encode this `AddPartitionsToTxnResponse` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        buf.put_i32(self.throttle_time_ms);
66        if version >= 4 {
67            buf.put_i16(self.error_code);
68        }
69        if version >= 4 {
70            if is_flexible(version) {
71                wire::put_compact_array_len(buf, Some(self.results_by_transaction.len()));
72            } else {
73                wire::put_array_len(buf, Some(self.results_by_transaction.len()))?;
74            }
75            for item in &self.results_by_transaction {
76                item.encode(buf, version)?;
77            }
78        }
79        if version <= 3 {
80            if is_flexible(version) {
81                wire::put_compact_array_len(buf, Some(self.results_by_topic_v3_and_below.len()));
82            } else {
83                wire::put_array_len(buf, Some(self.results_by_topic_v3_and_below.len()))?;
84            }
85            for item in &self.results_by_topic_v3_and_below {
86                item.encode(buf, version)?;
87            }
88        }
89        if is_flexible(version) {
90            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
91        }
92        Ok(())
93    }
94
95    /// Decode one `AddPartitionsToTxnResponse`, bounding allocation by the default
96    /// [`Limits`] derived from `buf`'s remaining length.
97    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
98        Self::decode_with_limits(buf, version, Limits::default())
99    }
100
101    /// Decode one `AddPartitionsToTxnResponse` under `limits`.
102    pub fn decode_with_limits(
103        buf: &mut impl Buf,
104        version: i16,
105        limits: Limits,
106    ) -> Result<Self, DecodeError> {
107        let mut budget = limits.budget(buf.remaining());
108        Self::decode_with_budget(buf, version, &mut budget)
109    }
110
111    /// Decode one `AddPartitionsToTxnResponse` against an existing `budget`.
112    pub fn decode_with_budget(
113        buf: &mut impl Buf,
114        version: i16,
115        budget: &mut Budget,
116    ) -> Result<Self, DecodeError> {
117        let mut this = Self::default();
118        this.throttle_time_ms = wire::get_i32(buf)?;
119        if version >= 4 {
120            this.error_code = wire::get_i16(buf)?;
121        }
122        if version >= 4 {
123            this.results_by_transaction = {
124                let len = if is_flexible(version) {
125                    wire::get_compact_array_len(buf)?
126                } else {
127                    wire::get_array_len(buf)?
128                };
129                match len {
130                    None => return Err(DecodeError::InvalidLength(-1)),
131                    Some(n) => {
132                        let mut items = Vec::new();
133                        for _ in 0..n {
134                            let mark = buf.remaining();
135                            let item =
136                                AddPartitionsToTxnResult::decode_with_budget(buf, version, budget)?;
137                            budget.progress(mark, buf.remaining())?;
138                            budget.push(&mut items, item)?;
139                        }
140                        items
141                    }
142                }
143            };
144        }
145        if version <= 3 {
146            this.results_by_topic_v3_and_below = {
147                let len = if is_flexible(version) {
148                    wire::get_compact_array_len(buf)?
149                } else {
150                    wire::get_array_len(buf)?
151                };
152                match len {
153                    None => return Err(DecodeError::InvalidLength(-1)),
154                    Some(n) => {
155                        let mut items = Vec::new();
156                        for _ in 0..n {
157                            let mark = buf.remaining();
158                            let item = AddPartitionsToTxnTopicResult::decode_with_budget(
159                                buf, version, budget,
160                            )?;
161                            budget.progress(mark, buf.remaining())?;
162                            budget.push(&mut items, item)?;
163                        }
164                        items
165                    }
166                }
167            };
168        }
169        if is_flexible(version) {
170            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
171        }
172        Ok(this)
173    }
174}
175
176impl crate::Message for AddPartitionsToTxnResponse {
177    const API_KEY: i16 = 24;
178    const MIN_VERSION: i16 = 0;
179    const MAX_VERSION: i16 = 5;
180
181    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
182        AddPartitionsToTxnResponse::encode(self, buf, version)
183    }
184    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
185        AddPartitionsToTxnResponse::decode(buf, version)
186    }
187    fn decode_with_limits(
188        buf: &mut impl Buf,
189        version: i16,
190        limits: Limits,
191    ) -> Result<Self, DecodeError> {
192        AddPartitionsToTxnResponse::decode_with_limits(buf, version, limits)
193    }
194    fn throttle_time_ms(&self) -> Option<i32> {
195        Some(self.throttle_time_ms)
196    }
197}
198
199/// `AddPartitionsToTxnResult` (nested in [`AddPartitionsToTxnResponse`]).
200#[derive(Debug, Clone, PartialEq)]
201#[non_exhaustive]
202pub struct AddPartitionsToTxnResult {
203    /// The transactional id corresponding to the transaction.
204    pub transactional_id: String,
205    /// The results for each topic.
206    pub topic_results: Vec<AddPartitionsToTxnTopicResult>,
207    /// Tagged fields not (yet) known to this crate, kept raw.
208    pub unknown_tagged_fields: Vec<RawTaggedField>,
209}
210
211impl Default for AddPartitionsToTxnResult {
212    fn default() -> Self {
213        Self {
214            transactional_id: String::new(),
215            topic_results: Vec::new(),
216            unknown_tagged_fields: Vec::new(),
217        }
218    }
219}
220
221impl AddPartitionsToTxnResult {
222    /// Encode this `AddPartitionsToTxnResult` at `version`.
223    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
224        if version >= 4 {
225            if is_flexible(version) {
226                wire::put_compact_string(buf, &self.transactional_id);
227            } else {
228                wire::put_string(buf, &self.transactional_id)?;
229            }
230        }
231        if version >= 4 {
232            if is_flexible(version) {
233                wire::put_compact_array_len(buf, Some(self.topic_results.len()));
234            } else {
235                wire::put_array_len(buf, Some(self.topic_results.len()))?;
236            }
237            for item in &self.topic_results {
238                item.encode(buf, version)?;
239            }
240        }
241        if is_flexible(version) {
242            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
243        }
244        Ok(())
245    }
246
247    /// Decode one `AddPartitionsToTxnResult`, bounding allocation by the default
248    /// [`Limits`] derived from `buf`'s remaining length.
249    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
250        Self::decode_with_limits(buf, version, Limits::default())
251    }
252
253    /// Decode one `AddPartitionsToTxnResult` under `limits`.
254    pub fn decode_with_limits(
255        buf: &mut impl Buf,
256        version: i16,
257        limits: Limits,
258    ) -> Result<Self, DecodeError> {
259        let mut budget = limits.budget(buf.remaining());
260        Self::decode_with_budget(buf, version, &mut budget)
261    }
262
263    /// Decode one `AddPartitionsToTxnResult` against an existing `budget`.
264    pub fn decode_with_budget(
265        buf: &mut impl Buf,
266        version: i16,
267        budget: &mut Budget,
268    ) -> Result<Self, DecodeError> {
269        let mut this = Self::default();
270        if version >= 4 {
271            this.transactional_id = if is_flexible(version) {
272                wire::get_compact_string(buf)?
273            } else {
274                wire::get_string(buf)?
275            };
276        }
277        if version >= 4 {
278            this.topic_results = {
279                let len = if is_flexible(version) {
280                    wire::get_compact_array_len(buf)?
281                } else {
282                    wire::get_array_len(buf)?
283                };
284                match len {
285                    None => return Err(DecodeError::InvalidLength(-1)),
286                    Some(n) => {
287                        let mut items = Vec::new();
288                        for _ in 0..n {
289                            let mark = buf.remaining();
290                            let item = AddPartitionsToTxnTopicResult::decode_with_budget(
291                                buf, version, budget,
292                            )?;
293                            budget.progress(mark, buf.remaining())?;
294                            budget.push(&mut items, item)?;
295                        }
296                        items
297                    }
298                }
299            };
300        }
301        if is_flexible(version) {
302            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
303        }
304        Ok(this)
305    }
306}
307
308/// `AddPartitionsToTxnTopicResult` (nested in [`AddPartitionsToTxnResponse`]).
309#[derive(Debug, Clone, PartialEq)]
310#[non_exhaustive]
311pub struct AddPartitionsToTxnTopicResult {
312    /// The topic name.
313    pub name: String,
314    /// The results for each partition.
315    pub results_by_partition: Vec<AddPartitionsToTxnPartitionResult>,
316    /// Tagged fields not (yet) known to this crate, kept raw.
317    pub unknown_tagged_fields: Vec<RawTaggedField>,
318}
319
320impl Default for AddPartitionsToTxnTopicResult {
321    fn default() -> Self {
322        Self {
323            name: String::new(),
324            results_by_partition: Vec::new(),
325            unknown_tagged_fields: Vec::new(),
326        }
327    }
328}
329
330impl AddPartitionsToTxnTopicResult {
331    /// Encode this `AddPartitionsToTxnTopicResult` at `version`.
332    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
333        if is_flexible(version) {
334            wire::put_compact_string(buf, &self.name);
335        } else {
336            wire::put_string(buf, &self.name)?;
337        }
338        if is_flexible(version) {
339            wire::put_compact_array_len(buf, Some(self.results_by_partition.len()));
340        } else {
341            wire::put_array_len(buf, Some(self.results_by_partition.len()))?;
342        }
343        for item in &self.results_by_partition {
344            item.encode(buf, version)?;
345        }
346        if is_flexible(version) {
347            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
348        }
349        Ok(())
350    }
351
352    /// Decode one `AddPartitionsToTxnTopicResult`, bounding allocation by the default
353    /// [`Limits`] derived from `buf`'s remaining length.
354    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
355        Self::decode_with_limits(buf, version, Limits::default())
356    }
357
358    /// Decode one `AddPartitionsToTxnTopicResult` under `limits`.
359    pub fn decode_with_limits(
360        buf: &mut impl Buf,
361        version: i16,
362        limits: Limits,
363    ) -> Result<Self, DecodeError> {
364        let mut budget = limits.budget(buf.remaining());
365        Self::decode_with_budget(buf, version, &mut budget)
366    }
367
368    /// Decode one `AddPartitionsToTxnTopicResult` against an existing `budget`.
369    pub fn decode_with_budget(
370        buf: &mut impl Buf,
371        version: i16,
372        budget: &mut Budget,
373    ) -> Result<Self, DecodeError> {
374        let mut this = Self::default();
375        this.name = if is_flexible(version) {
376            wire::get_compact_string(buf)?
377        } else {
378            wire::get_string(buf)?
379        };
380        this.results_by_partition = {
381            let len = if is_flexible(version) {
382                wire::get_compact_array_len(buf)?
383            } else {
384                wire::get_array_len(buf)?
385            };
386            match len {
387                None => return Err(DecodeError::InvalidLength(-1)),
388                Some(n) => {
389                    let mut items = Vec::new();
390                    for _ in 0..n {
391                        let mark = buf.remaining();
392                        let item = AddPartitionsToTxnPartitionResult::decode_with_budget(
393                            buf, version, budget,
394                        )?;
395                        budget.progress(mark, buf.remaining())?;
396                        budget.push(&mut items, item)?;
397                    }
398                    items
399                }
400            }
401        };
402        if is_flexible(version) {
403            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
404        }
405        Ok(this)
406    }
407}
408
409/// `AddPartitionsToTxnPartitionResult` (nested in [`AddPartitionsToTxnResponse`]).
410#[derive(Debug, Clone, PartialEq)]
411#[non_exhaustive]
412pub struct AddPartitionsToTxnPartitionResult {
413    /// The partition indexes.
414    pub partition_index: i32,
415    /// The response error code.
416    pub partition_error_code: i16,
417    /// Tagged fields not (yet) known to this crate, kept raw.
418    pub unknown_tagged_fields: Vec<RawTaggedField>,
419}
420
421impl Default for AddPartitionsToTxnPartitionResult {
422    fn default() -> Self {
423        Self {
424            partition_index: 0,
425            partition_error_code: 0,
426            unknown_tagged_fields: Vec::new(),
427        }
428    }
429}
430
431impl AddPartitionsToTxnPartitionResult {
432    /// Encode this `AddPartitionsToTxnPartitionResult` at `version`.
433    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
434        buf.put_i32(self.partition_index);
435        buf.put_i16(self.partition_error_code);
436        if is_flexible(version) {
437            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
438        }
439        Ok(())
440    }
441
442    /// Decode one `AddPartitionsToTxnPartitionResult`, bounding allocation by the default
443    /// [`Limits`] derived from `buf`'s remaining length.
444    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
445        Self::decode_with_limits(buf, version, Limits::default())
446    }
447
448    /// Decode one `AddPartitionsToTxnPartitionResult` under `limits`.
449    pub fn decode_with_limits(
450        buf: &mut impl Buf,
451        version: i16,
452        limits: Limits,
453    ) -> Result<Self, DecodeError> {
454        let mut budget = limits.budget(buf.remaining());
455        Self::decode_with_budget(buf, version, &mut budget)
456    }
457
458    /// Decode one `AddPartitionsToTxnPartitionResult` against an existing `budget`.
459    pub fn decode_with_budget(
460        buf: &mut impl Buf,
461        version: i16,
462        budget: &mut Budget,
463    ) -> Result<Self, DecodeError> {
464        let mut this = Self::default();
465        this.partition_index = wire::get_i32(buf)?;
466        this.partition_error_code = wire::get_i16(buf)?;
467        if is_flexible(version) {
468            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
469        }
470        Ok(this)
471    }
472}