Skip to main content

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

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