Skip to main content

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

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