Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterShareGroupOffsetsResponse.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_i16, get_i32, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 91;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 0;
23pub const FLEXIBLE_MIN: i16 = 0;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct AlterShareGroupOffsetsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub error_code: i16,
33    pub error_message: Option<&'a str>,
34    pub responses: Vec<AlterShareGroupOffsetsResponseTopic<'a>>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl AlterShareGroupOffsetsResponse<'_> {
38    /// # Panics
39    ///
40    /// Panics if a records field contains an invalid encoded record batch.
41    #[must_use]
42    pub fn to_owned(
43        &self,
44    ) -> crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponse {
45        crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponse {
46            throttle_time_ms: (self.throttle_time_ms),
47            error_code: (self.error_code),
48            error_message: (self.error_message).map(std::string::ToString::to_string),
49            responses: (self.responses)
50                .iter()
51                .map(AlterShareGroupOffsetsResponseTopic::to_owned)
52                .collect(),
53            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
54        }
55    }
56}
57impl Encode for AlterShareGroupOffsetsResponse<'_> {
58    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion {
61                api_key: API_KEY,
62                version,
63            });
64        }
65        let flex = is_flexible(version);
66        if version >= 0 {
67            put_i32(buf, self.throttle_time_ms);
68        }
69        if version >= 0 {
70            put_i16(buf, self.error_code);
71        }
72        if version >= 0 {
73            if flex {
74                let () = put_compact_nullable_string(buf, self.error_message);
75            } else {
76                let () = put_nullable_string(buf, self.error_message);
77            }
78        }
79        if version >= 0 {
80            {
81                crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
82                for it in &self.responses {
83                    it.encode(buf, version)?;
84                }
85            };
86        }
87        if flex {
88            let tagged = WriteTaggedFields::new();
89            tagged.write(buf, &self.unknown_tagged_fields);
90        }
91        Ok(())
92    }
93    fn encoded_len(&self, version: i16) -> usize {
94        let flex = is_flexible(version);
95        let mut n: usize = 0;
96        if version >= 0 {
97            n += 4;
98        }
99        if version >= 0 {
100            n += 2;
101        }
102        if version >= 0 {
103            n += if flex {
104                compact_nullable_string_len(self.error_message)
105            } else {
106                nullable_string_len(self.error_message)
107            };
108        }
109        if version >= 0 {
110            n += {
111                let prefix =
112                    crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
113                let body: usize = (self.responses)
114                    .iter()
115                    .map(|it| it.encoded_len(version))
116                    .sum();
117                prefix + body
118            };
119        }
120        if flex {
121            let known_pairs: Vec<(u32, usize)> = Vec::new();
122            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
123        }
124        n
125    }
126}
127impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsResponse<'de> {
128    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
129        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
130            return Err(ProtocolError::UnsupportedVersion {
131                api_key: API_KEY,
132                version,
133            });
134        }
135        let flex = is_flexible(version);
136        let mut out = Self::default();
137        if version >= 0 {
138            out.throttle_time_ms = get_i32(buf)?;
139        }
140        if version >= 0 {
141            out.error_code = get_i16(buf)?;
142        }
143        if version >= 0 {
144            out.error_message = if flex {
145                get_compact_nullable_string_borrowed(buf)?
146            } else {
147                get_nullable_string_borrowed(buf)?
148            };
149        }
150        if version >= 0 {
151            out.responses = {
152                let n = crate::primitives::array::get_array_len(buf, flex)?;
153                let mut v = Vec::with_capacity(n);
154                for _ in 0..n {
155                    v.push(AlterShareGroupOffsetsResponseTopic::decode_borrow(
156                        buf, version,
157                    )?);
158                }
159                v
160            };
161        }
162        if flex {
163            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
164        }
165        Ok(out)
166    }
167}
168#[cfg(test)]
169impl AlterShareGroupOffsetsResponse<'_> {
170    #[must_use]
171    pub fn populated(version: i16) -> Self {
172        let mut m = Self::default();
173        if version >= 0 {
174            m.throttle_time_ms = 1i32;
175        }
176        if version >= 0 {
177            m.error_code = 1i16;
178        }
179        if version >= 0 {
180            m.error_message = Some("x");
181        }
182        if version >= 0 {
183            m.responses = vec![AlterShareGroupOffsetsResponseTopic::populated(version)];
184        }
185        m
186    }
187}
188#[derive(Debug, Clone, PartialEq, Eq, Default)]
189pub struct AlterShareGroupOffsetsResponseTopic<'a> {
190    pub topic_name: &'a str,
191    pub topic_id: crate::primitives::uuid::Uuid,
192    pub partitions: Vec<AlterShareGroupOffsetsResponsePartition<'a>>,
193    pub unknown_tagged_fields: UnknownTaggedFields,
194}
195impl AlterShareGroupOffsetsResponseTopic<'_> {
196    /// # Panics
197    ///
198    /// Panics if a records field contains an invalid encoded record batch.
199    #[must_use]
200    pub fn to_owned(
201        &self,
202    ) -> crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponseTopic {
203        crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponseTopic {
204            topic_name: (self.topic_name).to_string(),
205            topic_id: (self.topic_id),
206            partitions: (self.partitions)
207                .iter()
208                .map(AlterShareGroupOffsetsResponsePartition::to_owned)
209                .collect(),
210            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
211        }
212    }
213}
214impl Encode for AlterShareGroupOffsetsResponseTopic<'_> {
215    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
216        let flex = version >= 0;
217        if version >= 0 {
218            if flex {
219                let () = put_compact_string(buf, self.topic_name);
220            } else {
221                let () = put_string(buf, self.topic_name);
222            }
223        }
224        if version >= 0 {
225            crate::primitives::uuid::put_uuid(buf, self.topic_id);
226        }
227        if version >= 0 {
228            {
229                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
230                for it in &self.partitions {
231                    it.encode(buf, version)?;
232                }
233            };
234        }
235        if flex {
236            let tagged = WriteTaggedFields::new();
237            tagged.write(buf, &self.unknown_tagged_fields);
238        }
239        Ok(())
240    }
241    fn encoded_len(&self, version: i16) -> usize {
242        let flex = version >= 0;
243        let mut n: usize = 0;
244        if version >= 0 {
245            n += if flex {
246                compact_string_len(self.topic_name)
247            } else {
248                string_len(self.topic_name)
249            };
250        }
251        if version >= 0 {
252            n += 16;
253        }
254        if version >= 0 {
255            n += {
256                let prefix =
257                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
258                let body: usize = (self.partitions)
259                    .iter()
260                    .map(|it| it.encoded_len(version))
261                    .sum();
262                prefix + body
263            };
264        }
265        if flex {
266            let known_pairs: Vec<(u32, usize)> = Vec::new();
267            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
268        }
269        n
270    }
271}
272impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsResponseTopic<'de> {
273    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
274        let flex = version >= 0;
275        let mut out = Self::default();
276        if version >= 0 {
277            out.topic_name = if flex {
278                get_compact_string_borrowed(buf)?
279            } else {
280                get_string_borrowed(buf)?
281            };
282        }
283        if version >= 0 {
284            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
285        }
286        if version >= 0 {
287            out.partitions = {
288                let n = crate::primitives::array::get_array_len(buf, flex)?;
289                let mut v = Vec::with_capacity(n);
290                for _ in 0..n {
291                    v.push(AlterShareGroupOffsetsResponsePartition::decode_borrow(
292                        buf, version,
293                    )?);
294                }
295                v
296            };
297        }
298        if flex {
299            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
300        }
301        Ok(out)
302    }
303}
304#[cfg(test)]
305impl AlterShareGroupOffsetsResponseTopic<'_> {
306    #[must_use]
307    pub fn populated(version: i16) -> Self {
308        let mut m = Self::default();
309        if version >= 0 {
310            m.topic_name = "x";
311        }
312        if version >= 0 {
313            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
314        }
315        if version >= 0 {
316            m.partitions = vec![AlterShareGroupOffsetsResponsePartition::populated(version)];
317        }
318        m
319    }
320}
321#[derive(Debug, Clone, PartialEq, Eq, Default)]
322pub struct AlterShareGroupOffsetsResponsePartition<'a> {
323    pub partition_index: i32,
324    pub error_code: i16,
325    pub error_message: Option<&'a str>,
326    pub unknown_tagged_fields: UnknownTaggedFields,
327}
328impl AlterShareGroupOffsetsResponsePartition<'_> {
329    /// # Panics
330    ///
331    /// Panics if a records field contains an invalid encoded record batch.
332    #[must_use]
333    pub fn to_owned(
334        &self,
335    ) -> crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponsePartition
336    {
337        crate::owned::alter_share_group_offsets_response::AlterShareGroupOffsetsResponsePartition {
338            partition_index: (self.partition_index),
339            error_code: (self.error_code),
340            error_message: (self.error_message).map(std::string::ToString::to_string),
341            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
342        }
343    }
344}
345impl Encode for AlterShareGroupOffsetsResponsePartition<'_> {
346    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
347        let flex = version >= 0;
348        if version >= 0 {
349            put_i32(buf, self.partition_index);
350        }
351        if version >= 0 {
352            put_i16(buf, self.error_code);
353        }
354        if version >= 0 {
355            if flex {
356                let () = put_compact_nullable_string(buf, self.error_message);
357            } else {
358                let () = put_nullable_string(buf, self.error_message);
359            }
360        }
361        if flex {
362            let tagged = WriteTaggedFields::new();
363            tagged.write(buf, &self.unknown_tagged_fields);
364        }
365        Ok(())
366    }
367    fn encoded_len(&self, version: i16) -> usize {
368        let flex = version >= 0;
369        let mut n: usize = 0;
370        if version >= 0 {
371            n += 4;
372        }
373        if version >= 0 {
374            n += 2;
375        }
376        if version >= 0 {
377            n += if flex {
378                compact_nullable_string_len(self.error_message)
379            } else {
380                nullable_string_len(self.error_message)
381            };
382        }
383        if flex {
384            let known_pairs: Vec<(u32, usize)> = Vec::new();
385            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
386        }
387        n
388    }
389}
390impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsResponsePartition<'de> {
391    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
392        let flex = version >= 0;
393        let mut out = Self::default();
394        if version >= 0 {
395            out.partition_index = get_i32(buf)?;
396        }
397        if version >= 0 {
398            out.error_code = get_i16(buf)?;
399        }
400        if version >= 0 {
401            out.error_message = if flex {
402                get_compact_nullable_string_borrowed(buf)?
403            } else {
404                get_nullable_string_borrowed(buf)?
405            };
406        }
407        if flex {
408            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
409        }
410        Ok(out)
411    }
412}
413#[cfg(test)]
414impl AlterShareGroupOffsetsResponsePartition<'_> {
415    #[must_use]
416    pub fn populated(version: i16) -> Self {
417        let mut m = Self::default();
418        if version >= 0 {
419            m.partition_index = 1i32;
420        }
421        if version >= 0 {
422            m.error_code = 1i16;
423        }
424        if version >= 0 {
425            m.error_message = Some("x");
426        }
427        m
428    }
429}