Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ListGroupsResponse.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::{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 = 16;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const FLEXIBLE_MIN: i16 = 3;
17#[inline]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct ListGroupsResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub error_code: i16,
26    pub groups: Vec<ListedGroup<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl ListGroupsResponse<'_> {
30    /// # Panics
31    ///
32    /// Panics if a records field contains an invalid encoded record batch.
33    #[must_use]
34    pub fn to_owned(&self) -> crate::owned::list_groups_response::ListGroupsResponse {
35        crate::owned::list_groups_response::ListGroupsResponse {
36            throttle_time_ms: (self.throttle_time_ms),
37            error_code: (self.error_code),
38            groups: (self.groups).iter().map(ListedGroup::to_owned).collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for ListGroupsResponse<'_> {
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 >= 1 {
53            put_i32(buf, self.throttle_time_ms);
54        }
55        if version >= 0 {
56            put_i16(buf, self.error_code);
57        }
58        if version >= 0 {
59            {
60                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
61                for it in &self.groups {
62                    it.encode(buf, version)?;
63                }
64            };
65        }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 1 {
76            n += 4;
77        }
78        if version >= 0 {
79            n += 2;
80        }
81        if version >= 0 {
82            n += {
83                let prefix =
84                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
85                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
86                prefix + body
87            };
88        }
89        if flex {
90            let known_pairs: Vec<(u32, usize)> = Vec::new();
91            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
92        }
93        n
94    }
95}
96impl<'de> DecodeBorrow<'de> for ListGroupsResponse<'de> {
97    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
98        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
99            return Err(ProtocolError::UnsupportedVersion {
100                api_key: API_KEY,
101                version,
102            });
103        }
104        let flex = is_flexible(version);
105        let mut out = Self::default();
106        if version >= 1 {
107            out.throttle_time_ms = get_i32(buf)?;
108        }
109        if version >= 0 {
110            out.error_code = get_i16(buf)?;
111        }
112        if version >= 0 {
113            out.groups = {
114                let n = crate::primitives::array::get_array_len(buf, flex)?;
115                let mut v = Vec::with_capacity(n);
116                for _ in 0..n {
117                    v.push(ListedGroup::decode_borrow(buf, version)?);
118                }
119                v
120            };
121        }
122        if flex {
123            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
124        }
125        Ok(out)
126    }
127}
128#[cfg(test)]
129impl ListGroupsResponse<'_> {
130    #[must_use]
131    pub fn populated(version: i16) -> Self {
132        let mut m = Self::default();
133        if version >= 1 {
134            m.throttle_time_ms = 1i32;
135        }
136        if version >= 0 {
137            m.error_code = 1i16;
138        }
139        if version >= 0 {
140            m.groups = vec![ListedGroup::populated(version)];
141        }
142        m
143    }
144}
145#[derive(Debug, Clone, PartialEq, Eq, Default)]
146pub struct ListedGroup<'a> {
147    pub group_id: &'a str,
148    pub protocol_type: &'a str,
149    pub group_state: &'a str,
150    pub group_type: &'a str,
151    pub unknown_tagged_fields: UnknownTaggedFields,
152}
153impl ListedGroup<'_> {
154    /// # Panics
155    ///
156    /// Panics if a records field contains an invalid encoded record batch.
157    #[must_use]
158    pub fn to_owned(&self) -> crate::owned::list_groups_response::ListedGroup {
159        crate::owned::list_groups_response::ListedGroup {
160            group_id: (self.group_id).to_string(),
161            protocol_type: (self.protocol_type).to_string(),
162            group_state: (self.group_state).to_string(),
163            group_type: (self.group_type).to_string(),
164            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
165        }
166    }
167}
168impl Encode for ListedGroup<'_> {
169    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
170        let flex = version >= 3;
171        if version >= 0 {
172            if flex {
173                let () = put_compact_string(buf, self.group_id);
174            } else {
175                let () = put_string(buf, self.group_id);
176            }
177        }
178        if version >= 0 {
179            if flex {
180                let () = put_compact_string(buf, self.protocol_type);
181            } else {
182                let () = put_string(buf, self.protocol_type);
183            }
184        }
185        if version >= 4 {
186            if flex {
187                let () = put_compact_string(buf, self.group_state);
188            } else {
189                let () = put_string(buf, self.group_state);
190            }
191        }
192        if version >= 5 {
193            if flex {
194                let () = put_compact_string(buf, self.group_type);
195            } else {
196                let () = put_string(buf, self.group_type);
197            }
198        }
199        if flex {
200            let tagged = WriteTaggedFields::new();
201            tagged.write(buf, &self.unknown_tagged_fields);
202        }
203        Ok(())
204    }
205    fn encoded_len(&self, version: i16) -> usize {
206        let flex = version >= 3;
207        let mut n: usize = 0;
208        if version >= 0 {
209            n += if flex {
210                compact_string_len(self.group_id)
211            } else {
212                string_len(self.group_id)
213            };
214        }
215        if version >= 0 {
216            n += if flex {
217                compact_string_len(self.protocol_type)
218            } else {
219                string_len(self.protocol_type)
220            };
221        }
222        if version >= 4 {
223            n += if flex {
224                compact_string_len(self.group_state)
225            } else {
226                string_len(self.group_state)
227            };
228        }
229        if version >= 5 {
230            n += if flex {
231                compact_string_len(self.group_type)
232            } else {
233                string_len(self.group_type)
234            };
235        }
236        if flex {
237            let known_pairs: Vec<(u32, usize)> = Vec::new();
238            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
239        }
240        n
241    }
242}
243impl<'de> DecodeBorrow<'de> for ListedGroup<'de> {
244    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
245        let flex = version >= 3;
246        let mut out = Self::default();
247        if version >= 0 {
248            out.group_id = if flex {
249                get_compact_string_borrowed(buf)?
250            } else {
251                get_string_borrowed(buf)?
252            };
253        }
254        if version >= 0 {
255            out.protocol_type = if flex {
256                get_compact_string_borrowed(buf)?
257            } else {
258                get_string_borrowed(buf)?
259            };
260        }
261        if version >= 4 {
262            out.group_state = if flex {
263                get_compact_string_borrowed(buf)?
264            } else {
265                get_string_borrowed(buf)?
266            };
267        }
268        if version >= 5 {
269            out.group_type = if flex {
270                get_compact_string_borrowed(buf)?
271            } else {
272                get_string_borrowed(buf)?
273            };
274        }
275        if flex {
276            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
277        }
278        Ok(out)
279    }
280}
281#[cfg(test)]
282impl ListedGroup<'_> {
283    #[must_use]
284    pub fn populated(version: i16) -> Self {
285        let mut m = Self::default();
286        if version >= 0 {
287            m.group_id = "x";
288        }
289        if version >= 0 {
290            m.protocol_type = "x";
291        }
292        if version >= 4 {
293            m.group_state = "x";
294        }
295        if version >= 5 {
296            m.group_type = "x";
297        }
298        m
299    }
300}