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