Skip to main content

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