Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
TxnOffsetCommitResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i16, get_i32, put_i16, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 28;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 6;
16pub const FLEXIBLE_MIN: i16 = 3;
17#[inline]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct TxnOffsetCommitResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub topics: Vec<TxnOffsetCommitResponseTopic<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl TxnOffsetCommitResponse<'_> {
29    /// # Panics
30    ///
31    /// Panics if a records field contains an invalid encoded record batch.
32    #[must_use]
33    pub fn to_owned(&self) -> crate::owned::txn_offset_commit_response::TxnOffsetCommitResponse {
34        crate::owned::txn_offset_commit_response::TxnOffsetCommitResponse {
35            throttle_time_ms: (self.throttle_time_ms),
36            topics: (self.topics)
37                .iter()
38                .map(TxnOffsetCommitResponseTopic::to_owned)
39                .collect(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for TxnOffsetCommitResponse<'_> {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            put_i32(buf, self.throttle_time_ms);
55        }
56        if version >= 0 {
57            {
58                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
59                for it in &self.topics {
60                    it.encode(buf, version)?;
61                }
62            };
63        }
64        if flex {
65            let tagged = WriteTaggedFields::new();
66            tagged.write(buf, &self.unknown_tagged_fields);
67        }
68        Ok(())
69    }
70    fn encoded_len(&self, version: i16) -> usize {
71        let flex = is_flexible(version);
72        let mut n: usize = 0;
73        if version >= 0 {
74            n += 4;
75        }
76        if version >= 0 {
77            n += {
78                let prefix =
79                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
80                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
81                prefix + body
82            };
83        }
84        if flex {
85            let known_pairs: Vec<(u32, usize)> = Vec::new();
86            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87        }
88        n
89    }
90}
91impl<'de> DecodeBorrow<'de> for TxnOffsetCommitResponse<'de> {
92    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94            return Err(ProtocolError::UnsupportedVersion {
95                api_key: API_KEY,
96                version,
97            });
98        }
99        let flex = is_flexible(version);
100        let mut out = Self::default();
101        if version >= 0 {
102            out.throttle_time_ms = get_i32(buf)?;
103        }
104        if version >= 0 {
105            out.topics = {
106                let n = crate::primitives::array::get_array_len(buf, flex)?;
107                let mut v = Vec::with_capacity(n);
108                for _ in 0..n {
109                    v.push(TxnOffsetCommitResponseTopic::decode_borrow(buf, version)?);
110                }
111                v
112            };
113        }
114        if flex {
115            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116        }
117        Ok(out)
118    }
119}
120#[cfg(test)]
121impl TxnOffsetCommitResponse<'_> {
122    #[must_use]
123    pub fn populated(version: i16) -> Self {
124        let mut m = Self::default();
125        if version >= 0 {
126            m.throttle_time_ms = 1i32;
127        }
128        if version >= 0 {
129            m.topics = vec![TxnOffsetCommitResponseTopic::populated(version)];
130        }
131        m
132    }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct TxnOffsetCommitResponseTopic<'a> {
136    pub name: &'a str,
137    pub topic_id: crate::primitives::uuid::Uuid,
138    pub partitions: Vec<TxnOffsetCommitResponsePartition>,
139    pub unknown_tagged_fields: UnknownTaggedFields,
140}
141impl TxnOffsetCommitResponseTopic<'_> {
142    /// # Panics
143    ///
144    /// Panics if a records field contains an invalid encoded record batch.
145    #[must_use]
146    pub fn to_owned(
147        &self,
148    ) -> crate::owned::txn_offset_commit_response::TxnOffsetCommitResponseTopic {
149        crate::owned::txn_offset_commit_response::TxnOffsetCommitResponseTopic {
150            name: (self.name).to_string(),
151            topic_id: (self.topic_id),
152            partitions: (self.partitions)
153                .iter()
154                .map(TxnOffsetCommitResponsePartition::to_owned)
155                .collect(),
156            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
157        }
158    }
159}
160impl Encode for TxnOffsetCommitResponseTopic<'_> {
161    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
162        let flex = version >= 3;
163        if (0..=5).contains(&version) {
164            if flex {
165                let () = put_compact_string(buf, self.name);
166            } else {
167                let () = put_string(buf, self.name);
168            }
169        }
170        if version >= 6 {
171            crate::primitives::uuid::put_uuid(buf, self.topic_id);
172        }
173        if version >= 0 {
174            {
175                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
176                for it in &self.partitions {
177                    it.encode(buf, version)?;
178                }
179            };
180        }
181        if flex {
182            let tagged = WriteTaggedFields::new();
183            tagged.write(buf, &self.unknown_tagged_fields);
184        }
185        Ok(())
186    }
187    fn encoded_len(&self, version: i16) -> usize {
188        let flex = version >= 3;
189        let mut n: usize = 0;
190        if (0..=5).contains(&version) {
191            n += if flex {
192                compact_string_len(self.name)
193            } else {
194                string_len(self.name)
195            };
196        }
197        if version >= 6 {
198            n += 16;
199        }
200        if version >= 0 {
201            n += {
202                let prefix =
203                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
204                let body: usize = (self.partitions)
205                    .iter()
206                    .map(|it| it.encoded_len(version))
207                    .sum();
208                prefix + body
209            };
210        }
211        if flex {
212            let known_pairs: Vec<(u32, usize)> = Vec::new();
213            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
214        }
215        n
216    }
217}
218impl<'de> DecodeBorrow<'de> for TxnOffsetCommitResponseTopic<'de> {
219    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220        let flex = version >= 3;
221        let mut out = Self::default();
222        if (0..=5).contains(&version) {
223            out.name = if flex {
224                get_compact_string_borrowed(buf)?
225            } else {
226                get_string_borrowed(buf)?
227            };
228        }
229        if version >= 6 {
230            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
231        }
232        if version >= 0 {
233            out.partitions = {
234                let n = crate::primitives::array::get_array_len(buf, flex)?;
235                let mut v = Vec::with_capacity(n);
236                for _ in 0..n {
237                    v.push(TxnOffsetCommitResponsePartition::decode_borrow(
238                        buf, version,
239                    )?);
240                }
241                v
242            };
243        }
244        if flex {
245            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
246        }
247        Ok(out)
248    }
249}
250#[cfg(test)]
251impl TxnOffsetCommitResponseTopic<'_> {
252    #[must_use]
253    pub fn populated(version: i16) -> Self {
254        let mut m = Self::default();
255        if (0..=5).contains(&version) {
256            m.name = "x";
257        }
258        if version >= 6 {
259            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
260        }
261        if version >= 0 {
262            m.partitions = vec![TxnOffsetCommitResponsePartition::populated(version)];
263        }
264        m
265    }
266}
267#[derive(Debug, Clone, PartialEq, Eq, Default)]
268pub struct TxnOffsetCommitResponsePartition {
269    pub partition_index: i32,
270    pub error_code: i16,
271    pub unknown_tagged_fields: UnknownTaggedFields,
272}
273impl TxnOffsetCommitResponsePartition {
274    /// # Panics
275    ///
276    /// Panics if a records field contains an invalid encoded record batch.
277    #[must_use]
278    pub fn to_owned(
279        &self,
280    ) -> crate::owned::txn_offset_commit_response::TxnOffsetCommitResponsePartition {
281        crate::owned::txn_offset_commit_response::TxnOffsetCommitResponsePartition {
282            partition_index: (self.partition_index),
283            error_code: (self.error_code),
284            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
285        }
286    }
287}
288impl Encode for TxnOffsetCommitResponsePartition {
289    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
290        let flex = version >= 3;
291        if version >= 0 {
292            put_i32(buf, self.partition_index);
293        }
294        if version >= 0 {
295            put_i16(buf, self.error_code);
296        }
297        if flex {
298            let tagged = WriteTaggedFields::new();
299            tagged.write(buf, &self.unknown_tagged_fields);
300        }
301        Ok(())
302    }
303    fn encoded_len(&self, version: i16) -> usize {
304        let flex = version >= 3;
305        let mut n: usize = 0;
306        if version >= 0 {
307            n += 4;
308        }
309        if version >= 0 {
310            n += 2;
311        }
312        if flex {
313            let known_pairs: Vec<(u32, usize)> = Vec::new();
314            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
315        }
316        n
317    }
318}
319impl<'de> DecodeBorrow<'de> for TxnOffsetCommitResponsePartition {
320    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
321        let flex = version >= 3;
322        let mut out = Self::default();
323        if version >= 0 {
324            out.partition_index = get_i32(buf)?;
325        }
326        if version >= 0 {
327            out.error_code = get_i16(buf)?;
328        }
329        if flex {
330            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
331        }
332        Ok(out)
333    }
334}
335#[cfg(test)]
336impl TxnOffsetCommitResponsePartition {
337    #[must_use]
338    pub fn populated(version: i16) -> Self {
339        let mut m = Self::default();
340        if version >= 0 {
341            m.partition_index = 1i32;
342        }
343        if version >= 0 {
344            m.error_code = 1i16;
345        }
346        m
347    }
348}