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