krabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{
9 array_len_prefix_len, get_array_len, get_nullable_array_len,
10 nullable_array_len_prefix_len, put_array_len, put_nullable_array_len,
11 },
12 fixed::{get_bool, get_i8, put_bool, put_i8},
13 string_bytes::{
14 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
15 put_string, string_len,
16 },
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 32;
21pub const MIN_VERSION: i16 = 1;
22pub const MAX_VERSION: i16 = 4;
23pub const LATEST_STABLE_VERSION: i16 = 4;
24pub const FLEXIBLE_MIN: i16 = 4;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28 version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq, Default)]
31pub struct DescribeConfigsRequest {
32 pub resources: Vec<DescribeConfigsResource>,
33 pub include_synonyms: bool,
34 pub include_documentation: bool,
35 pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Encode for DescribeConfigsRequest {
38 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40 return Err(ProtocolError::UnsupportedVersion {
41 api_key: API_KEY,
42 version,
43 });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 {
47 {
48 put_array_len(buf, (self.resources).len(), flex)?;
49 for it in &self.resources {
50 it.encode(buf, version)?;
51 }
52 }
53 }
54 if version >= 1 {
55 put_bool(buf, self.include_synonyms);
56 }
57 if version >= 3 {
58 put_bool(buf, self.include_documentation);
59 }
60 if flex {
61 let tagged = WriteTaggedFields::new();
62 tagged.write(buf, &self.unknown_tagged_fields)?;
63 }
64 Ok(())
65 }
66 fn encoded_len(&self, version: i16) -> usize {
67 let flex = is_flexible(version);
68 let mut n: usize = 0;
69 if version >= 0 {
70 n += {
71 let prefix = array_len_prefix_len((self.resources).len(), flex);
72 let body: usize = (self.resources)
73 .iter()
74 .map(|it| it.encoded_len(version))
75 .sum();
76 prefix + body
77 };
78 }
79 if version >= 1 {
80 n += 1;
81 }
82 if version >= 3 {
83 n += 1;
84 }
85 if flex {
86 let known_pairs: Vec<(u32, usize)> = Vec::new();
87 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88 }
89 n
90 }
91}
92impl Decode<'_> for DescribeConfigsRequest {
93 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
94 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95 return Err(ProtocolError::UnsupportedVersion {
96 api_key: API_KEY,
97 version,
98 });
99 }
100 let flex = is_flexible(version);
101 let mut out = Self::default();
102 if version >= 0 {
103 out.resources = {
104 let n = get_array_len(buf, flex)?;
105 let mut v = Vec::with_capacity(n);
106 for _ in 0..n {
107 v.push(DescribeConfigsResource::decode(buf, version)?);
108 }
109 v
110 };
111 }
112 if version >= 1 {
113 out.include_synonyms = get_bool(buf)?;
114 }
115 if version >= 3 {
116 out.include_documentation = get_bool(buf)?;
117 }
118 if flex {
119 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
120 }
121 Ok(out)
122 }
123}
124#[cfg(test)]
125impl DescribeConfigsRequest {
126 #[must_use]
127 pub fn populated(version: i16) -> Self {
128 let mut m = Self::default();
129 if version >= 0 {
130 m.resources = vec![DescribeConfigsResource::populated(version)];
131 }
132 if version >= 1 {
133 m.include_synonyms = true;
134 }
135 if version >= 3 {
136 m.include_documentation = true;
137 }
138 m
139 }
140}
141#[derive(Debug, Clone, PartialEq, Eq)]
142pub struct DescribeConfigsResource {
143 pub resource_type: i8,
144 pub resource_name: String,
145 pub configuration_keys: Option<Vec<String>>,
146 pub unknown_tagged_fields: UnknownTaggedFields,
147}
148impl Default for DescribeConfigsResource {
149 fn default() -> Self {
150 Self {
151 resource_type: 0i8,
152 resource_name: String::new(),
153 configuration_keys: Some(Vec::new()),
154 unknown_tagged_fields: UnknownTaggedFields::default(),
155 }
156 }
157}
158impl Encode for DescribeConfigsResource {
159 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
160 let flex = version >= 4;
161 if version >= 0 {
162 put_i8(buf, self.resource_type);
163 }
164 if version >= 0 {
165 if flex {
166 put_compact_string(buf, &self.resource_name)?;
167 } else {
168 put_string(buf, &self.resource_name)?;
169 }
170 }
171 if version >= 0 {
172 {
173 let len = (self.configuration_keys).as_ref().map(Vec::len);
174 put_nullable_array_len(buf, len, flex)?;
175 if let Some(v) = &self.configuration_keys {
176 for it in v {
177 if flex {
178 put_compact_string(buf, it)?;
179 } else {
180 put_string(buf, it)?;
181 }
182 }
183 }
184 }
185 }
186 if flex {
187 let tagged = WriteTaggedFields::new();
188 tagged.write(buf, &self.unknown_tagged_fields)?;
189 }
190 Ok(())
191 }
192 fn encoded_len(&self, version: i16) -> usize {
193 let flex = version >= 4;
194 let mut n: usize = 0;
195 if version >= 0 {
196 n += 1;
197 }
198 if version >= 0 {
199 n += if flex {
200 compact_string_len(&self.resource_name)
201 } else {
202 string_len(&self.resource_name)
203 };
204 }
205 if version >= 0 {
206 n += {
207 let opt: Option<&Vec<_>> = (self.configuration_keys).as_ref();
208 let prefix = nullable_array_len_prefix_len(opt.map(Vec::len), flex);
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 = 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_owned();
279 }
280 if version >= 0 {
281 m.configuration_keys = Some(vec!["x".to_owned()]);
282 }
283 m
284 }
285}
286#[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_owned(), ::serde_json::Value::Array(vec![]));
293 if version >= 1 {
294 obj.insert(
295 "includeSynonyms".to_owned(),
296 ::serde_json::Value::Bool(false),
297 );
298 }
299 if version >= 3 {
300 obj.insert(
301 "includeDocumentation".to_owned(),
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}