Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListOffsetsRequest.borrowed.rs

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