Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 91;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AlterShareGroupOffsetsRequest<'a> {
25    pub group_id: &'a str,
26    pub topics: Vec<AlterShareGroupOffsetsRequestTopic<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl AlterShareGroupOffsetsRequest<'_> {
30    pub fn to_owned(
31        &self,
32    ) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequest {
33        crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequest {
34            group_id: (self.group_id).to_string(),
35            topics: (self.topics)
36                .iter()
37                .map(AlterShareGroupOffsetsRequestTopic::to_owned)
38                .collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for AlterShareGroupOffsetsRequest<'_> {
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                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
62                for it in &self.topics {
63                    it.encode(buf, version)?;
64                }
65            }
66        }
67        if flex {
68            let tagged = WriteTaggedFields::new();
69            tagged.write(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73    fn encoded_len(&self, version: i16) -> usize {
74        let flex = is_flexible(version);
75        let mut n: usize = 0;
76        if version >= 0 {
77            n += if flex {
78                compact_string_len(self.group_id)
79            } else {
80                string_len(self.group_id)
81            };
82        }
83        if version >= 0 {
84            n += {
85                let prefix =
86                    crate::primitives::array::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 = crate::primitives::array::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    pub fn to_owned(
155        &self,
156    ) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestTopic {
157        crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestTopic {
158            topic_name: (self.topic_name).to_string(),
159            partitions: (self.partitions)
160                .iter()
161                .map(AlterShareGroupOffsetsRequestPartition::to_owned)
162                .collect(),
163            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
164        }
165    }
166}
167impl Encode for AlterShareGroupOffsetsRequestTopic<'_> {
168    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
169        let flex = version >= 0;
170        if version >= 0 {
171            if flex {
172                put_compact_string(buf, self.topic_name);
173            } else {
174                put_string(buf, self.topic_name);
175            }
176        }
177        if version >= 0 {
178            {
179                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
180                for it in &self.partitions {
181                    it.encode(buf, version)?;
182                }
183            }
184        }
185        if flex {
186            let tagged = WriteTaggedFields::new();
187            tagged.write(buf, &self.unknown_tagged_fields);
188        }
189        Ok(())
190    }
191    fn encoded_len(&self, version: i16) -> usize {
192        let flex = version >= 0;
193        let mut n: usize = 0;
194        if version >= 0 {
195            n += if flex {
196                compact_string_len(self.topic_name)
197            } else {
198                string_len(self.topic_name)
199            };
200        }
201        if version >= 0 {
202            n += {
203                let prefix =
204                    crate::primitives::array::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 = crate::primitives::array::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    pub fn to_owned(
270        &self,
271    ) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestPartition
272    {
273        crate::owned::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}