Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsRequest.owned.rs

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