Skip to main content

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

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