crabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{
6 get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32,
7};
8use crate::primitives::string_bytes::{
9 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
10 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
11 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 32;
17pub const MIN_VERSION: i16 = 1;
18pub const MAX_VERSION: i16 = 4;
19pub const FLEXIBLE_MIN: i16 = 4;
20
21#[inline]
22fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct DescribeConfigsResponse {
28 pub throttle_time_ms: i32,
29 pub results: Vec<DescribeConfigsResult>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for DescribeConfigsResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 put_i32(buf, self.throttle_time_ms);
43 }
44 if version >= 0 {
45 {
46 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
47 for it in &self.results {
48 it.encode(buf, version)?;
49 }
50 }
51 }
52 if flex {
53 let tagged = WriteTaggedFields::new();
54 tagged.write(buf, &self.unknown_tagged_fields);
55 }
56 Ok(())
57 }
58 fn encoded_len(&self, version: i16) -> usize {
59 let flex = is_flexible(version);
60 let mut n: usize = 0;
61 if version >= 0 {
62 n += 4;
63 }
64 if version >= 0 {
65 n += {
66 let prefix =
67 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
68 let body: usize = (self.results)
69 .iter()
70 .map(|it| it.encoded_len(version))
71 .sum();
72 prefix + body
73 };
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 DescribeConfigsResponse {
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.throttle_time_ms = get_i32(buf)?;
94 }
95 if version >= 0 {
96 out.results = {
97 let n = crate::primitives::array::get_array_len(buf, flex)?;
98 let mut v = Vec::with_capacity(n);
99 for _ in 0..n {
100 v.push(DescribeConfigsResult::decode(buf, version)?);
101 }
102 v
103 };
104 }
105 if flex {
106 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
107 }
108 Ok(out)
109 }
110}
111#[cfg(test)]
112impl DescribeConfigsResponse {
113 #[must_use]
114 pub fn populated(version: i16) -> Self {
115 let mut m = Self::default();
116 if version >= 0 {
117 m.throttle_time_ms = 1i32;
118 }
119 if version >= 0 {
120 m.results = vec![DescribeConfigsResult::populated(version)];
121 }
122 m
123 }
124}
125#[derive(Debug, Clone, PartialEq, Eq, Default)]
126pub struct DescribeConfigsResult {
127 pub error_code: i16,
128 pub error_message: Option<String>,
129 pub resource_type: i8,
130 pub resource_name: String,
131 pub configs: Vec<DescribeConfigsResourceResult>,
132 pub unknown_tagged_fields: UnknownTaggedFields,
133}
134impl Encode for DescribeConfigsResult {
135 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136 let flex = version >= 4;
137 if version >= 0 {
138 put_i16(buf, self.error_code);
139 }
140 if version >= 0 {
141 if flex {
142 put_compact_nullable_string(buf, self.error_message.as_deref());
143 } else {
144 put_nullable_string(buf, self.error_message.as_deref());
145 }
146 }
147 if version >= 0 {
148 put_i8(buf, self.resource_type);
149 }
150 if version >= 0 {
151 if flex {
152 put_compact_string(buf, &self.resource_name);
153 } else {
154 put_string(buf, &self.resource_name);
155 }
156 }
157 if version >= 0 {
158 {
159 crate::primitives::array::put_array_len(buf, (self.configs).len(), flex);
160 for it in &self.configs {
161 it.encode(buf, version)?;
162 }
163 }
164 }
165 if flex {
166 let tagged = WriteTaggedFields::new();
167 tagged.write(buf, &self.unknown_tagged_fields);
168 }
169 Ok(())
170 }
171 fn encoded_len(&self, version: i16) -> usize {
172 let flex = version >= 4;
173 let mut n: usize = 0;
174 if version >= 0 {
175 n += 2;
176 }
177 if version >= 0 {
178 n += if flex {
179 compact_nullable_string_len(self.error_message.as_deref())
180 } else {
181 nullable_string_len(self.error_message.as_deref())
182 };
183 }
184 if version >= 0 {
185 n += 1;
186 }
187 if version >= 0 {
188 n += if flex {
189 compact_string_len(&self.resource_name)
190 } else {
191 string_len(&self.resource_name)
192 };
193 }
194 if version >= 0 {
195 n += {
196 let prefix =
197 crate::primitives::array::array_len_prefix_len((self.configs).len(), flex);
198 let body: usize = (self.configs)
199 .iter()
200 .map(|it| it.encoded_len(version))
201 .sum();
202 prefix + body
203 };
204 }
205 if flex {
206 let known_pairs: Vec<(u32, usize)> = Vec::new();
207 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
208 }
209 n
210 }
211}
212impl Decode<'_> for DescribeConfigsResult {
213 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
214 let flex = version >= 4;
215 let mut out = Self::default();
216 if version >= 0 {
217 out.error_code = get_i16(buf)?;
218 }
219 if version >= 0 {
220 out.error_message = if flex {
221 get_compact_nullable_string_owned(buf)?
222 } else {
223 get_nullable_string_owned(buf)?
224 };
225 }
226 if version >= 0 {
227 out.resource_type = get_i8(buf)?;
228 }
229 if version >= 0 {
230 out.resource_name = if flex {
231 get_compact_string_owned(buf)?
232 } else {
233 get_string_owned(buf)?
234 };
235 }
236 if version >= 0 {
237 out.configs = {
238 let n = crate::primitives::array::get_array_len(buf, flex)?;
239 let mut v = Vec::with_capacity(n);
240 for _ in 0..n {
241 v.push(DescribeConfigsResourceResult::decode(buf, version)?);
242 }
243 v
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 DescribeConfigsResult {
254 #[must_use]
255 pub fn populated(version: i16) -> Self {
256 let mut m = Self::default();
257 if version >= 0 {
258 m.error_code = 1i16;
259 }
260 if version >= 0 {
261 m.error_message = Some("x".to_string());
262 }
263 if version >= 0 {
264 m.resource_type = 1i8;
265 }
266 if version >= 0 {
267 m.resource_name = "x".to_string();
268 }
269 if version >= 0 {
270 m.configs = vec![DescribeConfigsResourceResult::populated(version)];
271 }
272 m
273 }
274}
275#[derive(Debug, Clone, PartialEq, Eq)]
276pub struct DescribeConfigsResourceResult {
277 pub name: String,
278 pub value: Option<String>,
279 pub read_only: bool,
280 pub config_source: i8,
281 pub is_sensitive: bool,
282 pub synonyms: Vec<DescribeConfigsSynonym>,
283 pub config_type: i8,
284 pub documentation: Option<String>,
285 pub unknown_tagged_fields: UnknownTaggedFields,
286}
287impl Default for DescribeConfigsResourceResult {
288 fn default() -> Self {
289 Self {
290 name: String::new(),
291 value: None,
292 read_only: false,
293 config_source: -1i8,
294 is_sensitive: false,
295 synonyms: Vec::new(),
296 config_type: 0i8,
297 documentation: None,
298 unknown_tagged_fields: Default::default(),
299 }
300 }
301}
302impl Encode for DescribeConfigsResourceResult {
303 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
304 let flex = version >= 4;
305 if version >= 0 {
306 if flex {
307 put_compact_string(buf, &self.name);
308 } else {
309 put_string(buf, &self.name);
310 }
311 }
312 if version >= 0 {
313 if flex {
314 put_compact_nullable_string(buf, self.value.as_deref());
315 } else {
316 put_nullable_string(buf, self.value.as_deref());
317 }
318 }
319 if version >= 0 {
320 put_bool(buf, self.read_only);
321 }
322 if version >= 1 {
323 put_i8(buf, self.config_source);
324 }
325 if version >= 0 {
326 put_bool(buf, self.is_sensitive);
327 }
328 if version >= 1 {
329 {
330 crate::primitives::array::put_array_len(buf, (self.synonyms).len(), flex);
331 for it in &self.synonyms {
332 it.encode(buf, version)?;
333 }
334 }
335 }
336 if version >= 3 {
337 put_i8(buf, self.config_type);
338 }
339 if version >= 3 {
340 if flex {
341 put_compact_nullable_string(buf, self.documentation.as_deref());
342 } else {
343 put_nullable_string(buf, self.documentation.as_deref());
344 }
345 }
346 if flex {
347 let tagged = WriteTaggedFields::new();
348 tagged.write(buf, &self.unknown_tagged_fields);
349 }
350 Ok(())
351 }
352 fn encoded_len(&self, version: i16) -> usize {
353 let flex = version >= 4;
354 let mut n: usize = 0;
355 if version >= 0 {
356 n += if flex {
357 compact_string_len(&self.name)
358 } else {
359 string_len(&self.name)
360 };
361 }
362 if version >= 0 {
363 n += if flex {
364 compact_nullable_string_len(self.value.as_deref())
365 } else {
366 nullable_string_len(self.value.as_deref())
367 };
368 }
369 if version >= 0 {
370 n += 1;
371 }
372 if version >= 1 {
373 n += 1;
374 }
375 if version >= 0 {
376 n += 1;
377 }
378 if version >= 1 {
379 n += {
380 let prefix =
381 crate::primitives::array::array_len_prefix_len((self.synonyms).len(), flex);
382 let body: usize = (self.synonyms)
383 .iter()
384 .map(|it| it.encoded_len(version))
385 .sum();
386 prefix + body
387 };
388 }
389 if version >= 3 {
390 n += 1;
391 }
392 if version >= 3 {
393 n += if flex {
394 compact_nullable_string_len(self.documentation.as_deref())
395 } else {
396 nullable_string_len(self.documentation.as_deref())
397 };
398 }
399 if flex {
400 let known_pairs: Vec<(u32, usize)> = Vec::new();
401 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
402 }
403 n
404 }
405}
406impl Decode<'_> for DescribeConfigsResourceResult {
407 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
408 let flex = version >= 4;
409 let mut out = Self::default();
410 if version >= 0 {
411 out.name = if flex {
412 get_compact_string_owned(buf)?
413 } else {
414 get_string_owned(buf)?
415 };
416 }
417 if version >= 0 {
418 out.value = if flex {
419 get_compact_nullable_string_owned(buf)?
420 } else {
421 get_nullable_string_owned(buf)?
422 };
423 }
424 if version >= 0 {
425 out.read_only = get_bool(buf)?;
426 }
427 if version >= 1 {
428 out.config_source = get_i8(buf)?;
429 }
430 if version >= 0 {
431 out.is_sensitive = get_bool(buf)?;
432 }
433 if version >= 1 {
434 out.synonyms = {
435 let n = crate::primitives::array::get_array_len(buf, flex)?;
436 let mut v = Vec::with_capacity(n);
437 for _ in 0..n {
438 v.push(DescribeConfigsSynonym::decode(buf, version)?);
439 }
440 v
441 };
442 }
443 if version >= 3 {
444 out.config_type = get_i8(buf)?;
445 }
446 if version >= 3 {
447 out.documentation = if flex {
448 get_compact_nullable_string_owned(buf)?
449 } else {
450 get_nullable_string_owned(buf)?
451 };
452 }
453 if flex {
454 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
455 }
456 Ok(out)
457 }
458}
459#[cfg(test)]
460impl DescribeConfigsResourceResult {
461 #[must_use]
462 pub fn populated(version: i16) -> Self {
463 let mut m = Self::default();
464 if version >= 0 {
465 m.name = "x".to_string();
466 }
467 if version >= 0 {
468 m.value = Some("x".to_string());
469 }
470 if version >= 0 {
471 m.read_only = true;
472 }
473 if version >= 1 {
474 m.config_source = 1i8;
475 }
476 if version >= 0 {
477 m.is_sensitive = true;
478 }
479 if version >= 1 {
480 m.synonyms = vec![DescribeConfigsSynonym::populated(version)];
481 }
482 if version >= 3 {
483 m.config_type = 1i8;
484 }
485 if version >= 3 {
486 m.documentation = Some("x".to_string());
487 }
488 m
489 }
490}
491#[derive(Debug, Clone, PartialEq, Eq, Default)]
492pub struct DescribeConfigsSynonym {
493 pub name: String,
494 pub value: Option<String>,
495 pub source: i8,
496 pub unknown_tagged_fields: UnknownTaggedFields,
497}
498impl Encode for DescribeConfigsSynonym {
499 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
500 let flex = version >= 4;
501 if version >= 1 {
502 if flex {
503 put_compact_string(buf, &self.name);
504 } else {
505 put_string(buf, &self.name);
506 }
507 }
508 if version >= 1 {
509 if flex {
510 put_compact_nullable_string(buf, self.value.as_deref());
511 } else {
512 put_nullable_string(buf, self.value.as_deref());
513 }
514 }
515 if version >= 1 {
516 put_i8(buf, self.source);
517 }
518 if flex {
519 let tagged = WriteTaggedFields::new();
520 tagged.write(buf, &self.unknown_tagged_fields);
521 }
522 Ok(())
523 }
524 fn encoded_len(&self, version: i16) -> usize {
525 let flex = version >= 4;
526 let mut n: usize = 0;
527 if version >= 1 {
528 n += if flex {
529 compact_string_len(&self.name)
530 } else {
531 string_len(&self.name)
532 };
533 }
534 if version >= 1 {
535 n += if flex {
536 compact_nullable_string_len(self.value.as_deref())
537 } else {
538 nullable_string_len(self.value.as_deref())
539 };
540 }
541 if version >= 1 {
542 n += 1;
543 }
544 if flex {
545 let known_pairs: Vec<(u32, usize)> = Vec::new();
546 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
547 }
548 n
549 }
550}
551impl Decode<'_> for DescribeConfigsSynonym {
552 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
553 let flex = version >= 4;
554 let mut out = Self::default();
555 if version >= 1 {
556 out.name = if flex {
557 get_compact_string_owned(buf)?
558 } else {
559 get_string_owned(buf)?
560 };
561 }
562 if version >= 1 {
563 out.value = if flex {
564 get_compact_nullable_string_owned(buf)?
565 } else {
566 get_nullable_string_owned(buf)?
567 };
568 }
569 if version >= 1 {
570 out.source = get_i8(buf)?;
571 }
572 if flex {
573 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
574 }
575 Ok(out)
576 }
577}
578#[cfg(test)]
579impl DescribeConfigsSynonym {
580 #[must_use]
581 pub fn populated(version: i16) -> Self {
582 let mut m = Self::default();
583 if version >= 1 {
584 m.name = "x".to_string();
585 }
586 if version >= 1 {
587 m.value = Some("x".to_string());
588 }
589 if version >= 1 {
590 m.source = 1i8;
591 }
592 m
593 }
594}
595
596#[must_use]
599#[allow(unused_comparisons)]
600pub fn default_json(version: i16) -> ::serde_json::Value {
601 let mut obj = ::serde_json::Map::new();
602 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
603 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
604 ::serde_json::Value::Object(obj)
605}