Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteRequest.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::offset_delete_request,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i32, 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    },
13};
14pub const API_KEY: i16 = 47;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const LATEST_STABLE_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 32767;
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 OffsetDeleteRequest<'a> {
26    pub group_id: &'a str,
27    pub topics: Vec<OffsetDeleteRequestTopic<'a>>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl OffsetDeleteRequest<'_> {
31    #[must_use]
32    pub fn to_owned(&self) -> offset_delete_request::OffsetDeleteRequest {
33        offset_delete_request::OffsetDeleteRequest {
34            group_id: (self.group_id).to_owned(),
35            topics: (self.topics)
36                .iter()
37                .map(OffsetDeleteRequestTopic::to_owned)
38                .collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for OffsetDeleteRequest<'_> {
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 >= 0 {
53            if flex {
54                put_compact_string(buf, self.group_id)?;
55            } else {
56                put_string(buf, self.group_id)?;
57            }
58        }
59        if version >= 0 {
60            {
61                put_array_len(buf, (self.topics).len(), flex)?;
62                for it in &self.topics {
63                    it.encode(buf, version)?;
64                }
65            }
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 >= 0 {
73            n += if flex {
74                compact_string_len(self.group_id)
75            } else {
76                string_len(self.group_id)
77            };
78        }
79        if version >= 0 {
80            n += {
81                let prefix = array_len_prefix_len((self.topics).len(), flex);
82                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
83                prefix + body
84            };
85        }
86        n
87    }
88}
89impl<'de> DecodeBorrow<'de> for OffsetDeleteRequest<'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 >= 0 {
100            out.group_id = if flex {
101                get_compact_string_borrowed(buf)?
102            } else {
103                get_string_borrowed(buf)?
104            };
105        }
106        if version >= 0 {
107            out.topics = {
108                let n = get_array_len(buf, flex)?;
109                let mut v = Vec::with_capacity(n);
110                for _ in 0..n {
111                    v.push(OffsetDeleteRequestTopic::decode_borrow(buf, version)?);
112                }
113                v
114            };
115        }
116        Ok(out)
117    }
118}
119#[cfg(test)]
120impl OffsetDeleteRequest<'_> {
121    #[must_use]
122    pub fn populated(version: i16) -> Self {
123        let mut m = Self::default();
124        if version >= 0 {
125            m.group_id = "x";
126        }
127        if version >= 0 {
128            m.topics = vec![OffsetDeleteRequestTopic::populated(version)];
129        }
130        m
131    }
132}
133#[derive(Debug, Clone, PartialEq, Eq, Default)]
134pub struct OffsetDeleteRequestTopic<'a> {
135    pub name: &'a str,
136    pub partitions: Vec<OffsetDeleteRequestPartition>,
137    pub unknown_tagged_fields: UnknownTaggedFields,
138}
139impl OffsetDeleteRequestTopic<'_> {
140    #[must_use]
141    pub fn to_owned(&self) -> offset_delete_request::OffsetDeleteRequestTopic {
142        offset_delete_request::OffsetDeleteRequestTopic {
143            name: (self.name).to_owned(),
144            partitions: (self.partitions)
145                .iter()
146                .map(OffsetDeleteRequestPartition::to_owned)
147                .collect(),
148            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
149        }
150    }
151}
152impl Encode for OffsetDeleteRequestTopic<'_> {
153    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
154        let flex = version == i16::MAX;
155        if version >= 0 {
156            if flex {
157                put_compact_string(buf, self.name)?;
158            } else {
159                put_string(buf, self.name)?;
160            }
161        }
162        if version >= 0 {
163            {
164                put_array_len(buf, (self.partitions).len(), flex)?;
165                for it in &self.partitions {
166                    it.encode(buf, version)?;
167                }
168            }
169        }
170        Ok(())
171    }
172    fn encoded_len(&self, version: i16) -> usize {
173        let flex = version == i16::MAX;
174        let mut n: usize = 0;
175        if version >= 0 {
176            n += if flex {
177                compact_string_len(self.name)
178            } else {
179                string_len(self.name)
180            };
181        }
182        if version >= 0 {
183            n += {
184                let prefix = array_len_prefix_len((self.partitions).len(), flex);
185                let body: usize = (self.partitions)
186                    .iter()
187                    .map(|it| it.encoded_len(version))
188                    .sum();
189                prefix + body
190            };
191        }
192        n
193    }
194}
195impl<'de> DecodeBorrow<'de> for OffsetDeleteRequestTopic<'de> {
196    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
197        let flex = version == i16::MAX;
198        let mut out = Self::default();
199        if version >= 0 {
200            out.name = if flex {
201                get_compact_string_borrowed(buf)?
202            } else {
203                get_string_borrowed(buf)?
204            };
205        }
206        if version >= 0 {
207            out.partitions = {
208                let n = get_array_len(buf, flex)?;
209                let mut v = Vec::with_capacity(n);
210                for _ in 0..n {
211                    v.push(OffsetDeleteRequestPartition::decode_borrow(buf, version)?);
212                }
213                v
214            };
215        }
216        Ok(out)
217    }
218}
219#[cfg(test)]
220impl OffsetDeleteRequestTopic<'_> {
221    #[must_use]
222    pub fn populated(version: i16) -> Self {
223        let mut m = Self::default();
224        if version >= 0 {
225            m.name = "x";
226        }
227        if version >= 0 {
228            m.partitions = vec![OffsetDeleteRequestPartition::populated(version)];
229        }
230        m
231    }
232}
233#[derive(Debug, Clone, PartialEq, Eq, Default)]
234pub struct OffsetDeleteRequestPartition {
235    pub partition_index: i32,
236    pub unknown_tagged_fields: UnknownTaggedFields,
237}
238impl OffsetDeleteRequestPartition {
239    #[must_use]
240    pub fn to_owned(&self) -> offset_delete_request::OffsetDeleteRequestPartition {
241        offset_delete_request::OffsetDeleteRequestPartition {
242            partition_index: (self.partition_index),
243            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
244        }
245    }
246}
247impl Encode for OffsetDeleteRequestPartition {
248    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
249        if version >= 0 {
250            put_i32(buf, self.partition_index);
251        }
252        Ok(())
253    }
254    fn encoded_len(&self, version: i16) -> usize {
255        let mut n: usize = 0;
256        if version >= 0 {
257            n += 4;
258        }
259        n
260    }
261}
262impl<'de> DecodeBorrow<'de> for OffsetDeleteRequestPartition {
263    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
264        let mut out = Self::default();
265        if version >= 0 {
266            out.partition_index = get_i32(buf)?;
267        }
268        Ok(out)
269    }
270}
271#[cfg(test)]
272impl OffsetDeleteRequestPartition {
273    #[must_use]
274    pub fn populated(version: i16) -> Self {
275        let mut m = Self::default();
276        if version >= 0 {
277            m.partition_index = 1i32;
278        }
279        m
280    }
281}