Skip to main content

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