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