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