1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12 nullable_string_len, put_compact_nullable_string, put_compact_string,
13 put_nullable_string, put_string, string_len,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 32;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 4;
21pub const FLEXIBLE_MIN: i16 = 4;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DescribeConfigsResponse {
29 pub throttle_time_ms: i32,
30 pub results: Vec<DescribeConfigsResult>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DescribeConfigsResponse {
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 put_i32(buf, self.throttle_time_ms);
44 }
45 if version >= 0 {
46 {
47 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
48 for it in &self.results {
49 it.encode(buf, version)?;
50 }
51 };
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 += 4;
64 }
65 if version >= 0 {
66 n += {
67 let prefix =
68 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
69 let body: usize = (self.results)
70 .iter()
71 .map(|it| it.encoded_len(version))
72 .sum();
73 prefix + body
74 };
75 }
76 if flex {
77 let known_pairs: Vec<(u32, usize)> = Vec::new();
78 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79 }
80 n
81 }
82}
83impl Decode<'_> for DescribeConfigsResponse {
84 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86 return Err(ProtocolError::UnsupportedVersion {
87 api_key: API_KEY,
88 version,
89 });
90 }
91 let flex = is_flexible(version);
92 let mut out = Self::default();
93 if version >= 0 {
94 out.throttle_time_ms = get_i32(buf)?;
95 }
96 if version >= 0 {
97 out.results = {
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(DescribeConfigsResult::decode(buf, version)?);
102 }
103 v
104 };
105 }
106 if flex {
107 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
108 }
109 Ok(out)
110 }
111}
112#[cfg(test)]
113impl DescribeConfigsResponse {
114 #[must_use]
115 pub fn populated(version: i16) -> Self {
116 let mut m = Self::default();
117 if version >= 0 {
118 m.throttle_time_ms = 1i32;
119 }
120 if version >= 0 {
121 m.results = vec![DescribeConfigsResult::populated(version)];
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct DescribeConfigsResult {
128 pub error_code: i16,
129 pub error_message: Option<String>,
130 pub resource_type: i8,
131 pub resource_name: String,
132 pub configs: Vec<DescribeConfigsResourceResult>,
133 pub unknown_tagged_fields: UnknownTaggedFields,
134}
135impl Default for DescribeConfigsResult {
136 fn default() -> Self {
137 Self {
138 error_code: 0i16,
139 error_message: Some(String::new()),
140 resource_type: 0i8,
141 resource_name: String::new(),
142 configs: Vec::new(),
143 unknown_tagged_fields: UnknownTaggedFields::default(),
144 }
145 }
146}
147impl Encode for DescribeConfigsResult {
148 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
149 let flex = version >= 4;
150 if version >= 0 {
151 put_i16(buf, self.error_code);
152 }
153 if version >= 0 {
154 if flex {
155 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
156 } else {
157 let () = put_nullable_string(buf, self.error_message.as_deref());
158 }
159 }
160 if version >= 0 {
161 put_i8(buf, self.resource_type);
162 }
163 if version >= 0 {
164 if flex {
165 let () = put_compact_string(buf, &self.resource_name);
166 } else {
167 let () = put_string(buf, &self.resource_name);
168 }
169 }
170 if version >= 0 {
171 {
172 crate::primitives::array::put_array_len(buf, (self.configs).len(), flex);
173 for it in &self.configs {
174 it.encode(buf, version)?;
175 }
176 };
177 }
178 if flex {
179 let tagged = WriteTaggedFields::new();
180 tagged.write(buf, &self.unknown_tagged_fields);
181 }
182 Ok(())
183 }
184 fn encoded_len(&self, version: i16) -> usize {
185 let flex = version >= 4;
186 let mut n: usize = 0;
187 if version >= 0 {
188 n += 2;
189 }
190 if version >= 0 {
191 n += if flex {
192 compact_nullable_string_len(self.error_message.as_deref())
193 } else {
194 nullable_string_len(self.error_message.as_deref())
195 };
196 }
197 if version >= 0 {
198 n += 1;
199 }
200 if version >= 0 {
201 n += if flex {
202 compact_string_len(&self.resource_name)
203 } else {
204 string_len(&self.resource_name)
205 };
206 }
207 if version >= 0 {
208 n += {
209 let prefix =
210 crate::primitives::array::array_len_prefix_len((self.configs).len(), flex);
211 let body: usize = (self.configs)
212 .iter()
213 .map(|it| it.encoded_len(version))
214 .sum();
215 prefix + body
216 };
217 }
218 if flex {
219 let known_pairs: Vec<(u32, usize)> = Vec::new();
220 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
221 }
222 n
223 }
224}
225impl Decode<'_> for DescribeConfigsResult {
226 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
227 let flex = version >= 4;
228 let mut out = Self::default();
229 if version >= 0 {
230 out.error_code = get_i16(buf)?;
231 }
232 if version >= 0 {
233 out.error_message = if flex {
234 get_compact_nullable_string_owned(buf)?
235 } else {
236 get_nullable_string_owned(buf)?
237 };
238 }
239 if version >= 0 {
240 out.resource_type = get_i8(buf)?;
241 }
242 if version >= 0 {
243 out.resource_name = if flex {
244 get_compact_string_owned(buf)?
245 } else {
246 get_string_owned(buf)?
247 };
248 }
249 if version >= 0 {
250 out.configs = {
251 let n = crate::primitives::array::get_array_len(buf, flex)?;
252 let mut v = Vec::with_capacity(n);
253 for _ in 0..n {
254 v.push(DescribeConfigsResourceResult::decode(buf, version)?);
255 }
256 v
257 };
258 }
259 if flex {
260 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
261 }
262 Ok(out)
263 }
264}
265#[cfg(test)]
266impl DescribeConfigsResult {
267 #[must_use]
268 pub fn populated(version: i16) -> Self {
269 let mut m = Self::default();
270 if version >= 0 {
271 m.error_code = 1i16;
272 }
273 if version >= 0 {
274 m.error_message = Some("x".to_string());
275 }
276 if version >= 0 {
277 m.resource_type = 1i8;
278 }
279 if version >= 0 {
280 m.resource_name = "x".to_string();
281 }
282 if version >= 0 {
283 m.configs = vec![DescribeConfigsResourceResult::populated(version)];
284 }
285 m
286 }
287}
288#[derive(Debug, Clone, PartialEq, Eq)]
289pub struct DescribeConfigsResourceResult {
290 pub name: String,
291 pub value: Option<String>,
292 pub read_only: bool,
293 pub config_source: i8,
294 pub is_sensitive: bool,
295 pub synonyms: Vec<DescribeConfigsSynonym>,
296 pub config_type: i8,
297 pub documentation: Option<String>,
298 pub unknown_tagged_fields: UnknownTaggedFields,
299}
300impl Default for DescribeConfigsResourceResult {
301 fn default() -> Self {
302 Self {
303 name: String::new(),
304 value: Some(String::new()),
305 read_only: false,
306 config_source: -1i8,
307 is_sensitive: false,
308 synonyms: Vec::new(),
309 config_type: 0i8,
310 documentation: Some(String::new()),
311 unknown_tagged_fields: UnknownTaggedFields::default(),
312 }
313 }
314}
315impl DescribeConfigsResourceResult {
316 fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
317 if version >= 0 {
318 if flex {
319 let () = put_compact_string(buf, &self.name);
320 } else {
321 let () = put_string(buf, &self.name);
322 }
323 }
324 }
325 fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
326 if version >= 0 {
327 if flex {
328 let () = put_compact_nullable_string(buf, self.value.as_deref());
329 } else {
330 let () = put_nullable_string(buf, self.value.as_deref());
331 }
332 }
333 }
334 fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
335 if version >= 0 {
336 put_bool(buf, self.read_only);
337 }
338 }
339 fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
340 if version >= 1 {
341 put_i8(buf, self.config_source);
342 }
343 }
344 fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
345 if version >= 0 {
346 put_bool(buf, self.is_sensitive);
347 }
348 }
349 fn encode_field_5<B: BufMut>(
350 &self,
351 buf: &mut B,
352 version: i16,
353 flex: bool,
354 ) -> Result<(), ProtocolError> {
355 if version >= 1 {
356 {
357 crate::primitives::array::put_array_len(buf, (self.synonyms).len(), flex);
358 for it in &self.synonyms {
359 it.encode(buf, version)?;
360 }
361 };
362 }
363 Ok(())
364 }
365 fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
366 if version >= 3 {
367 put_i8(buf, self.config_type);
368 }
369 }
370 fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
371 if version >= 3 {
372 if flex {
373 let () = put_compact_nullable_string(buf, self.documentation.as_deref());
374 } else {
375 let () = put_nullable_string(buf, self.documentation.as_deref());
376 }
377 }
378 }
379 fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
380 if flex {
381 let tagged = WriteTaggedFields::new();
382 tagged.write(buf, &self.unknown_tagged_fields);
383 }
384 }
385 fn decode_field_0<B: Buf>(
386 out: &mut Self,
387 buf: &mut B,
388 version: i16,
389 flex: bool,
390 ) -> Result<(), ProtocolError> {
391 if version >= 0 {
392 out.name = if flex {
393 get_compact_string_owned(buf)?
394 } else {
395 get_string_owned(buf)?
396 };
397 }
398 Ok(())
399 }
400 fn decode_field_1<B: Buf>(
401 out: &mut Self,
402 buf: &mut B,
403 version: i16,
404 flex: bool,
405 ) -> Result<(), ProtocolError> {
406 if version >= 0 {
407 out.value = if flex {
408 get_compact_nullable_string_owned(buf)?
409 } else {
410 get_nullable_string_owned(buf)?
411 };
412 }
413 Ok(())
414 }
415 fn decode_field_2<B: Buf>(
416 out: &mut Self,
417 buf: &mut B,
418 version: i16,
419 _flex: bool,
420 ) -> Result<(), ProtocolError> {
421 if version >= 0 {
422 out.read_only = get_bool(buf)?;
423 }
424 Ok(())
425 }
426 fn decode_field_3<B: Buf>(
427 out: &mut Self,
428 buf: &mut B,
429 version: i16,
430 _flex: bool,
431 ) -> Result<(), ProtocolError> {
432 if version >= 1 {
433 out.config_source = get_i8(buf)?;
434 }
435 Ok(())
436 }
437 fn decode_field_4<B: Buf>(
438 out: &mut Self,
439 buf: &mut B,
440 version: i16,
441 _flex: bool,
442 ) -> Result<(), ProtocolError> {
443 if version >= 0 {
444 out.is_sensitive = get_bool(buf)?;
445 }
446 Ok(())
447 }
448 fn decode_field_5<B: Buf>(
449 out: &mut Self,
450 buf: &mut B,
451 version: i16,
452 flex: bool,
453 ) -> Result<(), ProtocolError> {
454 if version >= 1 {
455 out.synonyms = {
456 let n = crate::primitives::array::get_array_len(buf, flex)?;
457 let mut v = Vec::with_capacity(n);
458 for _ in 0..n {
459 v.push(DescribeConfigsSynonym::decode(buf, version)?);
460 }
461 v
462 };
463 }
464 Ok(())
465 }
466 fn decode_field_6<B: Buf>(
467 out: &mut Self,
468 buf: &mut B,
469 version: i16,
470 _flex: bool,
471 ) -> Result<(), ProtocolError> {
472 if version >= 3 {
473 out.config_type = get_i8(buf)?;
474 }
475 Ok(())
476 }
477 fn decode_field_7<B: Buf>(
478 out: &mut Self,
479 buf: &mut B,
480 version: i16,
481 flex: bool,
482 ) -> Result<(), ProtocolError> {
483 if version >= 3 {
484 out.documentation = if flex {
485 get_compact_nullable_string_owned(buf)?
486 } else {
487 get_nullable_string_owned(buf)?
488 };
489 }
490 Ok(())
491 }
492 fn decode_tagged_fields<B: Buf>(
493 out: &mut Self,
494 buf: &mut B,
495 _version: i16,
496 flex: bool,
497 ) -> Result<(), ProtocolError> {
498 if flex {
499 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
500 }
501 Ok(())
502 }
503}
504impl Encode for DescribeConfigsResourceResult {
505 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
506 let flex = version >= 4;
507 self.encode_field_0(buf, version, flex);
508 self.encode_field_1(buf, version, flex);
509 self.encode_field_2(buf, version, flex);
510 self.encode_field_3(buf, version, flex);
511 self.encode_field_4(buf, version, flex);
512 self.encode_field_5(buf, version, flex)?;
513 self.encode_field_6(buf, version, flex);
514 self.encode_field_7(buf, version, flex);
515 self.encode_tagged_fields(buf, version, flex);
516 Ok(())
517 }
518 fn encoded_len(&self, version: i16) -> usize {
519 let flex = version >= 4;
520 let mut n: usize = 0;
521 if version >= 0 {
522 n += if flex {
523 compact_string_len(&self.name)
524 } else {
525 string_len(&self.name)
526 };
527 }
528 if version >= 0 {
529 n += if flex {
530 compact_nullable_string_len(self.value.as_deref())
531 } else {
532 nullable_string_len(self.value.as_deref())
533 };
534 }
535 if version >= 0 {
536 n += 1;
537 }
538 if version >= 1 {
539 n += 1;
540 }
541 if version >= 0 {
542 n += 1;
543 }
544 if version >= 1 {
545 n += {
546 let prefix =
547 crate::primitives::array::array_len_prefix_len((self.synonyms).len(), flex);
548 let body: usize = (self.synonyms)
549 .iter()
550 .map(|it| it.encoded_len(version))
551 .sum();
552 prefix + body
553 };
554 }
555 if version >= 3 {
556 n += 1;
557 }
558 if version >= 3 {
559 n += if flex {
560 compact_nullable_string_len(self.documentation.as_deref())
561 } else {
562 nullable_string_len(self.documentation.as_deref())
563 };
564 }
565 if flex {
566 let known_pairs: Vec<(u32, usize)> = Vec::new();
567 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
568 }
569 n
570 }
571}
572impl Decode<'_> for DescribeConfigsResourceResult {
573 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
574 let flex = version >= 4;
575 let mut out = Self::default();
576 Self::decode_field_0(&mut out, buf, version, flex)?;
577 Self::decode_field_1(&mut out, buf, version, flex)?;
578 Self::decode_field_2(&mut out, buf, version, flex)?;
579 Self::decode_field_3(&mut out, buf, version, flex)?;
580 Self::decode_field_4(&mut out, buf, version, flex)?;
581 Self::decode_field_5(&mut out, buf, version, flex)?;
582 Self::decode_field_6(&mut out, buf, version, flex)?;
583 Self::decode_field_7(&mut out, buf, version, flex)?;
584 Self::decode_tagged_fields(&mut out, buf, version, flex)?;
585 Ok(out)
586 }
587}
588#[cfg(test)]
589impl DescribeConfigsResourceResult {
590 #[must_use]
591 pub fn populated(version: i16) -> Self {
592 let mut m = Self::default();
593 if version >= 0 {
594 m.name = "x".to_string();
595 }
596 if version >= 0 {
597 m.value = Some("x".to_string());
598 }
599 if version >= 0 {
600 m.read_only = true;
601 }
602 if version >= 1 {
603 m.config_source = 1i8;
604 }
605 if version >= 0 {
606 m.is_sensitive = true;
607 }
608 if version >= 1 {
609 m.synonyms = vec![DescribeConfigsSynonym::populated(version)];
610 }
611 if version >= 3 {
612 m.config_type = 1i8;
613 }
614 if version >= 3 {
615 m.documentation = Some("x".to_string());
616 }
617 m
618 }
619}
620#[derive(Debug, Clone, PartialEq, Eq)]
621pub struct DescribeConfigsSynonym {
622 pub name: String,
623 pub value: Option<String>,
624 pub source: i8,
625 pub unknown_tagged_fields: UnknownTaggedFields,
626}
627impl Default for DescribeConfigsSynonym {
628 fn default() -> Self {
629 Self {
630 name: String::new(),
631 value: Some(String::new()),
632 source: 0i8,
633 unknown_tagged_fields: UnknownTaggedFields::default(),
634 }
635 }
636}
637impl Encode for DescribeConfigsSynonym {
638 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
639 let flex = version >= 4;
640 if version >= 1 {
641 if flex {
642 let () = put_compact_string(buf, &self.name);
643 } else {
644 let () = put_string(buf, &self.name);
645 }
646 }
647 if version >= 1 {
648 if flex {
649 let () = put_compact_nullable_string(buf, self.value.as_deref());
650 } else {
651 let () = put_nullable_string(buf, self.value.as_deref());
652 }
653 }
654 if version >= 1 {
655 put_i8(buf, self.source);
656 }
657 if flex {
658 let tagged = WriteTaggedFields::new();
659 tagged.write(buf, &self.unknown_tagged_fields);
660 }
661 Ok(())
662 }
663 fn encoded_len(&self, version: i16) -> usize {
664 let flex = version >= 4;
665 let mut n: usize = 0;
666 if version >= 1 {
667 n += if flex {
668 compact_string_len(&self.name)
669 } else {
670 string_len(&self.name)
671 };
672 }
673 if version >= 1 {
674 n += if flex {
675 compact_nullable_string_len(self.value.as_deref())
676 } else {
677 nullable_string_len(self.value.as_deref())
678 };
679 }
680 if version >= 1 {
681 n += 1;
682 }
683 if flex {
684 let known_pairs: Vec<(u32, usize)> = Vec::new();
685 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
686 }
687 n
688 }
689}
690impl Decode<'_> for DescribeConfigsSynonym {
691 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
692 let flex = version >= 4;
693 let mut out = Self::default();
694 if version >= 1 {
695 out.name = if flex {
696 get_compact_string_owned(buf)?
697 } else {
698 get_string_owned(buf)?
699 };
700 }
701 if version >= 1 {
702 out.value = if flex {
703 get_compact_nullable_string_owned(buf)?
704 } else {
705 get_nullable_string_owned(buf)?
706 };
707 }
708 if version >= 1 {
709 out.source = get_i8(buf)?;
710 }
711 if flex {
712 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
713 }
714 Ok(out)
715 }
716}
717#[cfg(test)]
718impl DescribeConfigsSynonym {
719 #[must_use]
720 pub fn populated(version: i16) -> Self {
721 let mut m = Self::default();
722 if version >= 1 {
723 m.name = "x".to_string();
724 }
725 if version >= 1 {
726 m.value = Some("x".to_string());
727 }
728 if version >= 1 {
729 m.source = 1i8;
730 }
731 m
732 }
733}
734#[must_use]
737#[allow(unused_comparisons)]
738pub fn default_json(_version: i16) -> ::serde_json::Value {
739 let mut obj = ::serde_json::Map::new();
740 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
741 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
742 ::serde_json::Value::Object(obj)
743}