Skip to main content

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