Skip to main content

kacrab_protocol/generated/
txn_offset_commit_response.rs

1//! Generated from TxnOffsetCommitResponse.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 TxnOffsetCommitResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The responses for each topic.
21    pub topics: Vec<TxnOffsetCommitResponseTopic>,
22    pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for TxnOffsetCommitResponseData {
25    fn default() -> Self {
26        Self {
27            throttle_time_ms: 0_i32,
28            topics: Vec::new(),
29            _unknown_tagged_fields: Vec::new(),
30        }
31    }
32}
33impl TxnOffsetCommitResponseData {
34    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35        self.throttle_time_ms = value;
36        self
37    }
38    pub fn with_topics(mut self, value: Vec<TxnOffsetCommitResponseTopic>) -> Self {
39        self.topics = value;
40        self
41    }
42    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43        if version < 0 || version > 5 {
44            return Err(UnsupportedVersion::new(28, version).into());
45        }
46        let throttle_time_ms;
47        let topics;
48        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49        throttle_time_ms = read_i32(buf)?;
50        if version >= 3 {
51            topics = {
52                let len = read_compact_array_length(buf)?;
53                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
54                for _ in 0..len {
55                    arr.push(TxnOffsetCommitResponseTopic::read(buf, version)?);
56                }
57                arr
58            };
59        } else {
60            topics = {
61                let len = read_array_length(buf)?;
62                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
63                for _ in 0..len {
64                    arr.push(TxnOffsetCommitResponseTopic::read(buf, version)?);
65                }
66                arr
67            };
68        }
69        if version >= 3 {
70            let tagged_fields = read_tagged_fields(buf)?;
71            for field in &tagged_fields {
72                match field.tag {
73                    _ => {
74                        _unknown_tagged_fields.push(field.clone());
75                    },
76                }
77            }
78        }
79        Ok(Self {
80            throttle_time_ms,
81            topics,
82            _unknown_tagged_fields,
83        })
84    }
85    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
86        if version < 0 || version > 5 {
87            return Err(UnsupportedVersion::new(28, version).into());
88        }
89        write_i32(buf, self.throttle_time_ms);
90        if version >= 3 {
91            write_compact_array_length(buf, self.topics.len() as i32);
92            for el in &self.topics {
93                el.write(buf, version)?;
94            }
95        } else {
96            write_array_length(buf, self.topics.len() as i32);
97            for el in &self.topics {
98                el.write(buf, version)?;
99            }
100        }
101        if version >= 3 {
102            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
103            all_tags.sort_by_key(|f| f.tag);
104            write_tagged_fields(buf, &all_tags)?;
105        }
106        Ok(())
107    }
108    pub fn encoded_len(&self, version: i16) -> Result<usize> {
109        if version < 0 || version > 5 {
110            return Err(UnsupportedVersion::new(28, version).into());
111        }
112        let mut len: usize = 0;
113        len += 4;
114        if version >= 3 {
115            len += compact_array_length_len(self.topics.len() as i32);
116            for el in &self.topics {
117                len += el.encoded_len(version)?;
118            }
119        } else {
120            len += array_length_len();
121            for el in &self.topics {
122                len += el.encoded_len(version)?;
123            }
124        }
125        if version >= 3 {
126            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
127            all_tags.sort_by_key(|f| f.tag);
128            len += tagged_fields_len(&all_tags)?;
129        }
130        Ok(len)
131    }
132}
133#[derive(Debug, Clone, PartialEq)]
134pub struct TxnOffsetCommitResponseTopic {
135    /// The topic name.
136    pub name: KafkaString,
137    /// The responses for each partition in the topic.
138    pub partitions: Vec<TxnOffsetCommitResponsePartition>,
139    pub _unknown_tagged_fields: Vec<RawTaggedField>,
140}
141impl Default for TxnOffsetCommitResponseTopic {
142    fn default() -> Self {
143        Self {
144            name: KafkaString::default(),
145            partitions: Vec::new(),
146            _unknown_tagged_fields: Vec::new(),
147        }
148    }
149}
150impl TxnOffsetCommitResponseTopic {
151    pub fn with_name(mut self, value: KafkaString) -> Self {
152        self.name = value;
153        self
154    }
155    pub fn with_partitions(mut self, value: Vec<TxnOffsetCommitResponsePartition>) -> Self {
156        self.partitions = value;
157        self
158    }
159    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
160        let name;
161        let partitions;
162        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
163        if version >= 3 {
164            name = read_compact_string(buf)?;
165        } else {
166            name = read_string(buf)?;
167        }
168        if version >= 3 {
169            partitions = {
170                let len = read_compact_array_length(buf)?;
171                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
172                for _ in 0..len {
173                    arr.push(TxnOffsetCommitResponsePartition::read(buf, version)?);
174                }
175                arr
176            };
177        } else {
178            partitions = {
179                let len = read_array_length(buf)?;
180                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
181                for _ in 0..len {
182                    arr.push(TxnOffsetCommitResponsePartition::read(buf, version)?);
183                }
184                arr
185            };
186        }
187        if version >= 3 {
188            let tagged_fields = read_tagged_fields(buf)?;
189            for field in &tagged_fields {
190                match field.tag {
191                    _ => {
192                        _unknown_tagged_fields.push(field.clone());
193                    },
194                }
195            }
196        }
197        Ok(Self {
198            name,
199            partitions,
200            _unknown_tagged_fields,
201        })
202    }
203    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
204        if version >= 3 {
205            write_compact_string(buf, &self.name)?;
206        } else {
207            write_string(buf, &self.name)?;
208        }
209        if version >= 3 {
210            write_compact_array_length(buf, self.partitions.len() as i32);
211            for el in &self.partitions {
212                el.write(buf, version)?;
213            }
214        } else {
215            write_array_length(buf, self.partitions.len() as i32);
216            for el in &self.partitions {
217                el.write(buf, version)?;
218            }
219        }
220        if version >= 3 {
221            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
222            all_tags.sort_by_key(|f| f.tag);
223            write_tagged_fields(buf, &all_tags)?;
224        }
225        Ok(())
226    }
227    pub fn encoded_len(&self, version: i16) -> Result<usize> {
228        let mut len: usize = 0;
229        if version >= 3 {
230            len += compact_string_len(&self.name)?;
231        } else {
232            len += string_len(&self.name)?;
233        }
234        if version >= 3 {
235            len += compact_array_length_len(self.partitions.len() as i32);
236            for el in &self.partitions {
237                len += el.encoded_len(version)?;
238            }
239        } else {
240            len += array_length_len();
241            for el in &self.partitions {
242                len += el.encoded_len(version)?;
243            }
244        }
245        if version >= 3 {
246            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
247            all_tags.sort_by_key(|f| f.tag);
248            len += tagged_fields_len(&all_tags)?;
249        }
250        Ok(len)
251    }
252}
253#[derive(Debug, Clone, PartialEq)]
254pub struct TxnOffsetCommitResponsePartition {
255    /// The partition index.
256    pub partition_index: i32,
257    /// The error code, or 0 if there was no error.
258    pub error_code: i16,
259    pub _unknown_tagged_fields: Vec<RawTaggedField>,
260}
261impl Default for TxnOffsetCommitResponsePartition {
262    fn default() -> Self {
263        Self {
264            partition_index: 0_i32,
265            error_code: 0_i16,
266            _unknown_tagged_fields: Vec::new(),
267        }
268    }
269}
270impl TxnOffsetCommitResponsePartition {
271    pub fn with_partition_index(mut self, value: i32) -> Self {
272        self.partition_index = value;
273        self
274    }
275    pub fn with_error_code(mut self, value: i16) -> Self {
276        self.error_code = value;
277        self
278    }
279    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
280        let partition_index;
281        let error_code;
282        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
283        partition_index = read_i32(buf)?;
284        error_code = read_i16(buf)?;
285        if version >= 3 {
286            let tagged_fields = read_tagged_fields(buf)?;
287            for field in &tagged_fields {
288                match field.tag {
289                    _ => {
290                        _unknown_tagged_fields.push(field.clone());
291                    },
292                }
293            }
294        }
295        Ok(Self {
296            partition_index,
297            error_code,
298            _unknown_tagged_fields,
299        })
300    }
301    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
302        write_i32(buf, self.partition_index);
303        write_i16(buf, self.error_code);
304        if version >= 3 {
305            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
306            all_tags.sort_by_key(|f| f.tag);
307            write_tagged_fields(buf, &all_tags)?;
308        }
309        Ok(())
310    }
311    pub fn encoded_len(&self, version: i16) -> Result<usize> {
312        let mut len: usize = 0;
313        len += 4;
314        len += 2;
315        if version >= 3 {
316            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
317            all_tags.sort_by_key(|f| f.tag);
318            len += tagged_fields_len(&all_tags)?;
319        }
320        Ok(len)
321    }
322}