Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitResponse.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 = 8;
14pub const MIN_VERSION: i16 = 2;
15pub const MAX_VERSION: i16 = 10;
16pub const FLEXIBLE_MIN: i16 = 8;
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 OffsetCommitResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub topics: Vec<OffsetCommitResponseTopic<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl OffsetCommitResponse<'_> {
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::offset_commit_response::OffsetCommitResponse {
34        crate::owned::offset_commit_response::OffsetCommitResponse {
35            throttle_time_ms: (self.throttle_time_ms),
36            topics: (self.topics)
37                .iter()
38                .map(OffsetCommitResponseTopic::to_owned)
39                .collect(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for OffsetCommitResponse<'_> {
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 >= 3 {
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 >= 3 {
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 OffsetCommitResponse<'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 >= 3 {
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(OffsetCommitResponseTopic::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 OffsetCommitResponse<'_> {
122    #[must_use]
123    pub fn populated(version: i16) -> Self {
124        let mut m = Self::default();
125        if version >= 3 {
126            m.throttle_time_ms = 1i32;
127        }
128        if version >= 0 {
129            m.topics = vec![OffsetCommitResponseTopic::populated(version)];
130        }
131        m
132    }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct OffsetCommitResponseTopic<'a> {
136    pub name: &'a str,
137    pub topic_id: crate::primitives::uuid::Uuid,
138    pub partitions: Vec<OffsetCommitResponsePartition>,
139    pub unknown_tagged_fields: UnknownTaggedFields,
140}
141impl OffsetCommitResponseTopic<'_> {
142    /// # Panics
143    ///
144    /// Panics if a records field contains an invalid encoded record batch.
145    #[must_use]
146    pub fn to_owned(&self) -> crate::owned::offset_commit_response::OffsetCommitResponseTopic {
147        crate::owned::offset_commit_response::OffsetCommitResponseTopic {
148            name: (self.name).to_string(),
149            topic_id: (self.topic_id),
150            partitions: (self.partitions)
151                .iter()
152                .map(OffsetCommitResponsePartition::to_owned)
153                .collect(),
154            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
155        }
156    }
157}
158impl Encode for OffsetCommitResponseTopic<'_> {
159    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
160        let flex = version >= 8;
161        if (0..=9).contains(&version) {
162            if flex {
163                let () = put_compact_string(buf, self.name);
164            } else {
165                let () = put_string(buf, self.name);
166            }
167        }
168        if version >= 10 {
169            crate::primitives::uuid::put_uuid(buf, self.topic_id);
170        }
171        if version >= 0 {
172            {
173                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
174                for it in &self.partitions {
175                    it.encode(buf, version)?;
176                }
177            };
178        }
179        if flex {
180            let tagged = WriteTaggedFields::new();
181            tagged.write(buf, &self.unknown_tagged_fields);
182        }
183        Ok(())
184    }
185    fn encoded_len(&self, version: i16) -> usize {
186        let flex = version >= 8;
187        let mut n: usize = 0;
188        if (0..=9).contains(&version) {
189            n += if flex {
190                compact_string_len(self.name)
191            } else {
192                string_len(self.name)
193            };
194        }
195        if version >= 10 {
196            n += 16;
197        }
198        if version >= 0 {
199            n += {
200                let prefix =
201                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
202                let body: usize = (self.partitions)
203                    .iter()
204                    .map(|it| it.encoded_len(version))
205                    .sum();
206                prefix + body
207            };
208        }
209        if flex {
210            let known_pairs: Vec<(u32, usize)> = Vec::new();
211            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
212        }
213        n
214    }
215}
216impl<'de> DecodeBorrow<'de> for OffsetCommitResponseTopic<'de> {
217    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
218        let flex = version >= 8;
219        let mut out = Self::default();
220        if (0..=9).contains(&version) {
221            out.name = if flex {
222                get_compact_string_borrowed(buf)?
223            } else {
224                get_string_borrowed(buf)?
225            };
226        }
227        if version >= 10 {
228            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
229        }
230        if version >= 0 {
231            out.partitions = {
232                let n = crate::primitives::array::get_array_len(buf, flex)?;
233                let mut v = Vec::with_capacity(n);
234                for _ in 0..n {
235                    v.push(OffsetCommitResponsePartition::decode_borrow(buf, version)?);
236                }
237                v
238            };
239        }
240        if flex {
241            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
242        }
243        Ok(out)
244    }
245}
246#[cfg(test)]
247impl OffsetCommitResponseTopic<'_> {
248    #[must_use]
249    pub fn populated(version: i16) -> Self {
250        let mut m = Self::default();
251        if (0..=9).contains(&version) {
252            m.name = "x";
253        }
254        if version >= 10 {
255            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
256        }
257        if version >= 0 {
258            m.partitions = vec![OffsetCommitResponsePartition::populated(version)];
259        }
260        m
261    }
262}
263#[derive(Debug, Clone, PartialEq, Eq, Default)]
264pub struct OffsetCommitResponsePartition {
265    pub partition_index: i32,
266    pub error_code: i16,
267    pub unknown_tagged_fields: UnknownTaggedFields,
268}
269impl OffsetCommitResponsePartition {
270    /// # Panics
271    ///
272    /// Panics if a records field contains an invalid encoded record batch.
273    #[must_use]
274    pub fn to_owned(&self) -> crate::owned::offset_commit_response::OffsetCommitResponsePartition {
275        crate::owned::offset_commit_response::OffsetCommitResponsePartition {
276            partition_index: (self.partition_index),
277            error_code: (self.error_code),
278            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
279        }
280    }
281}
282impl Encode for OffsetCommitResponsePartition {
283    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
284        let flex = version >= 8;
285        if version >= 0 {
286            put_i32(buf, self.partition_index);
287        }
288        if version >= 0 {
289            put_i16(buf, self.error_code);
290        }
291        if flex {
292            let tagged = WriteTaggedFields::new();
293            tagged.write(buf, &self.unknown_tagged_fields);
294        }
295        Ok(())
296    }
297    fn encoded_len(&self, version: i16) -> usize {
298        let flex = version >= 8;
299        let mut n: usize = 0;
300        if version >= 0 {
301            n += 4;
302        }
303        if version >= 0 {
304            n += 2;
305        }
306        if flex {
307            let known_pairs: Vec<(u32, usize)> = Vec::new();
308            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
309        }
310        n
311    }
312}
313impl<'de> DecodeBorrow<'de> for OffsetCommitResponsePartition {
314    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
315        let flex = version >= 8;
316        let mut out = Self::default();
317        if version >= 0 {
318            out.partition_index = get_i32(buf)?;
319        }
320        if version >= 0 {
321            out.error_code = get_i16(buf)?;
322        }
323        if flex {
324            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
325        }
326        Ok(out)
327    }
328}
329#[cfg(test)]
330impl OffsetCommitResponsePartition {
331    #[must_use]
332    pub fn populated(version: i16) -> Self {
333        let mut m = Self::default();
334        if version >= 0 {
335            m.partition_index = 1i32;
336        }
337        if version >= 0 {
338            m.error_code = 1i16;
339        }
340        m
341    }
342}