Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32},
10        string_bytes::{
11            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13            nullable_string_len, put_compact_nullable_string, put_compact_string,
14            put_nullable_string, put_string, string_len,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 32;
20pub const MIN_VERSION: i16 = 1;
21pub const MAX_VERSION: i16 = 4;
22pub const FLEXIBLE_MIN: i16 = 4;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct DescribeConfigsResponse {
30    pub throttle_time_ms: i32,
31    pub results: Vec<DescribeConfigsResult>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for DescribeConfigsResponse {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::UnsupportedVersion {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 0 {
44            put_i32(buf, self.throttle_time_ms);
45        }
46        if version >= 0 {
47            {
48                put_array_len(buf, (self.results).len(), flex)?;
49                for it in &self.results {
50                    it.encode(buf, version)?;
51                }
52            }
53        }
54        if flex {
55            let tagged = WriteTaggedFields::new();
56            tagged.write(buf, &self.unknown_tagged_fields)?;
57        }
58        Ok(())
59    }
60    fn encoded_len(&self, version: i16) -> usize {
61        let flex = is_flexible(version);
62        let mut n: usize = 0;
63        if version >= 0 {
64            n += 4;
65        }
66        if version >= 0 {
67            n += {
68                let prefix = 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 = 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                put_compact_nullable_string(buf, self.error_message.as_deref())?;
156            } else {
157                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                put_compact_string(buf, &self.resource_name)?;
166            } else {
167                put_string(buf, &self.resource_name)?;
168            }
169        }
170        if version >= 0 {
171            {
172                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 = array_len_prefix_len((self.configs).len(), flex);
210                let body: usize = (self.configs)
211                    .iter()
212                    .map(|it| it.encoded_len(version))
213                    .sum();
214                prefix + body
215            };
216        }
217        if flex {
218            let known_pairs: Vec<(u32, usize)> = Vec::new();
219            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
220        }
221        n
222    }
223}
224impl Decode<'_> for DescribeConfigsResult {
225    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
226        let flex = version >= 4;
227        let mut out = Self::default();
228        if version >= 0 {
229            out.error_code = get_i16(buf)?;
230        }
231        if version >= 0 {
232            out.error_message = if flex {
233                get_compact_nullable_string_owned(buf)?
234            } else {
235                get_nullable_string_owned(buf)?
236            };
237        }
238        if version >= 0 {
239            out.resource_type = get_i8(buf)?;
240        }
241        if version >= 0 {
242            out.resource_name = if flex {
243                get_compact_string_owned(buf)?
244            } else {
245                get_string_owned(buf)?
246            };
247        }
248        if version >= 0 {
249            out.configs = {
250                let n = get_array_len(buf, flex)?;
251                let mut v = Vec::with_capacity(n);
252                for _ in 0..n {
253                    v.push(DescribeConfigsResourceResult::decode(buf, version)?);
254                }
255                v
256            };
257        }
258        if flex {
259            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
260        }
261        Ok(out)
262    }
263}
264#[cfg(test)]
265impl DescribeConfigsResult {
266    #[must_use]
267    pub fn populated(version: i16) -> Self {
268        let mut m = Self::default();
269        if version >= 0 {
270            m.error_code = 1i16;
271        }
272        if version >= 0 {
273            m.error_message = Some("x".to_owned());
274        }
275        if version >= 0 {
276            m.resource_type = 1i8;
277        }
278        if version >= 0 {
279            m.resource_name = "x".to_owned();
280        }
281        if version >= 0 {
282            m.configs = vec![DescribeConfigsResourceResult::populated(version)];
283        }
284        m
285    }
286}
287#[derive(Debug, Clone, PartialEq, Eq)]
288pub struct DescribeConfigsResourceResult {
289    pub name: String,
290    pub value: Option<String>,
291    pub read_only: bool,
292    pub config_source: i8,
293    pub is_sensitive: bool,
294    pub synonyms: Vec<DescribeConfigsSynonym>,
295    pub config_type: i8,
296    pub documentation: Option<String>,
297    pub unknown_tagged_fields: UnknownTaggedFields,
298}
299impl Default for DescribeConfigsResourceResult {
300    fn default() -> Self {
301        Self {
302            name: String::new(),
303            value: Some(String::new()),
304            read_only: false,
305            config_source: -1i8,
306            is_sensitive: false,
307            synonyms: Vec::new(),
308            config_type: 0i8,
309            documentation: Some(String::new()),
310            unknown_tagged_fields: UnknownTaggedFields::default(),
311        }
312    }
313}
314impl DescribeConfigsResourceResult {
315    fn encode_field_0<B: BufMut>(
316        &self,
317        buf: &mut B,
318        version: i16,
319        flex: bool,
320    ) -> Result<(), ProtocolError> {
321        if version >= 0 {
322            if flex {
323                put_compact_string(buf, &self.name)?;
324            } else {
325                put_string(buf, &self.name)?;
326            }
327        }
328        Ok(())
329    }
330    fn encode_field_1<B: BufMut>(
331        &self,
332        buf: &mut B,
333        version: i16,
334        flex: bool,
335    ) -> Result<(), ProtocolError> {
336        if version >= 0 {
337            if flex {
338                put_compact_nullable_string(buf, self.value.as_deref())?;
339            } else {
340                put_nullable_string(buf, self.value.as_deref())?;
341            }
342        }
343        Ok(())
344    }
345    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
346        if version >= 0 {
347            put_bool(buf, self.read_only);
348        }
349    }
350    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
351        if version >= 1 {
352            put_i8(buf, self.config_source);
353        }
354    }
355    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
356        if version >= 0 {
357            put_bool(buf, self.is_sensitive);
358        }
359    }
360    fn encode_field_5<B: BufMut>(
361        &self,
362        buf: &mut B,
363        version: i16,
364        flex: bool,
365    ) -> Result<(), ProtocolError> {
366        if version >= 1 {
367            {
368                put_array_len(buf, (self.synonyms).len(), flex)?;
369                for it in &self.synonyms {
370                    it.encode(buf, version)?;
371                }
372            }
373        }
374        Ok(())
375    }
376    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
377        if version >= 3 {
378            put_i8(buf, self.config_type);
379        }
380    }
381    fn encode_field_7<B: BufMut>(
382        &self,
383        buf: &mut B,
384        version: i16,
385        flex: bool,
386    ) -> Result<(), ProtocolError> {
387        if version >= 3 {
388            if flex {
389                put_compact_nullable_string(buf, self.documentation.as_deref())?;
390            } else {
391                put_nullable_string(buf, self.documentation.as_deref())?;
392            }
393        }
394        Ok(())
395    }
396    fn encode_tagged_fields<B: BufMut>(
397        &self,
398        buf: &mut B,
399        _version: i16,
400        flex: bool,
401    ) -> Result<(), ProtocolError> {
402        if flex {
403            let tagged = WriteTaggedFields::new();
404            tagged.write(buf, &self.unknown_tagged_fields)?;
405        }
406        Ok(())
407    }
408    fn decode_field_0<B: Buf>(
409        out: &mut Self,
410        buf: &mut B,
411        version: i16,
412        flex: bool,
413    ) -> Result<(), ProtocolError> {
414        if version >= 0 {
415            out.name = if flex {
416                get_compact_string_owned(buf)?
417            } else {
418                get_string_owned(buf)?
419            };
420        }
421        Ok(())
422    }
423    fn decode_field_1<B: Buf>(
424        out: &mut Self,
425        buf: &mut B,
426        version: i16,
427        flex: bool,
428    ) -> Result<(), ProtocolError> {
429        if version >= 0 {
430            out.value = if flex {
431                get_compact_nullable_string_owned(buf)?
432            } else {
433                get_nullable_string_owned(buf)?
434            };
435        }
436        Ok(())
437    }
438    fn decode_field_2<B: Buf>(
439        out: &mut Self,
440        buf: &mut B,
441        version: i16,
442        _flex: bool,
443    ) -> Result<(), ProtocolError> {
444        if version >= 0 {
445            out.read_only = get_bool(buf)?;
446        }
447        Ok(())
448    }
449    fn decode_field_3<B: Buf>(
450        out: &mut Self,
451        buf: &mut B,
452        version: i16,
453        _flex: bool,
454    ) -> Result<(), ProtocolError> {
455        if version >= 1 {
456            out.config_source = get_i8(buf)?;
457        }
458        Ok(())
459    }
460    fn decode_field_4<B: Buf>(
461        out: &mut Self,
462        buf: &mut B,
463        version: i16,
464        _flex: bool,
465    ) -> Result<(), ProtocolError> {
466        if version >= 0 {
467            out.is_sensitive = get_bool(buf)?;
468        }
469        Ok(())
470    }
471    fn decode_field_5<B: Buf>(
472        out: &mut Self,
473        buf: &mut B,
474        version: i16,
475        flex: bool,
476    ) -> Result<(), ProtocolError> {
477        if version >= 1 {
478            out.synonyms = {
479                let n = get_array_len(buf, flex)?;
480                let mut v = Vec::with_capacity(n);
481                for _ in 0..n {
482                    v.push(DescribeConfigsSynonym::decode(buf, version)?);
483                }
484                v
485            };
486        }
487        Ok(())
488    }
489    fn decode_field_6<B: Buf>(
490        out: &mut Self,
491        buf: &mut B,
492        version: i16,
493        _flex: bool,
494    ) -> Result<(), ProtocolError> {
495        if version >= 3 {
496            out.config_type = get_i8(buf)?;
497        }
498        Ok(())
499    }
500    fn decode_field_7<B: Buf>(
501        out: &mut Self,
502        buf: &mut B,
503        version: i16,
504        flex: bool,
505    ) -> Result<(), ProtocolError> {
506        if version >= 3 {
507            out.documentation = if flex {
508                get_compact_nullable_string_owned(buf)?
509            } else {
510                get_nullable_string_owned(buf)?
511            };
512        }
513        Ok(())
514    }
515    fn decode_tagged_fields<B: Buf>(
516        out: &mut Self,
517        buf: &mut B,
518        _version: i16,
519        flex: bool,
520    ) -> Result<(), ProtocolError> {
521        if flex {
522            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
523        }
524        Ok(())
525    }
526}
527impl Encode for DescribeConfigsResourceResult {
528    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
529        let flex = version >= 4;
530        self.encode_field_0(buf, version, flex)?;
531        self.encode_field_1(buf, version, flex)?;
532        self.encode_field_2(buf, version, flex);
533        self.encode_field_3(buf, version, flex);
534        self.encode_field_4(buf, version, flex);
535        self.encode_field_5(buf, version, flex)?;
536        self.encode_field_6(buf, version, flex);
537        self.encode_field_7(buf, version, flex)?;
538        self.encode_tagged_fields(buf, version, flex)?;
539        Ok(())
540    }
541    fn encoded_len(&self, version: i16) -> usize {
542        let flex = version >= 4;
543        let mut n: usize = 0;
544        if version >= 0 {
545            n += if flex {
546                compact_string_len(&self.name)
547            } else {
548                string_len(&self.name)
549            };
550        }
551        if version >= 0 {
552            n += if flex {
553                compact_nullable_string_len(self.value.as_deref())
554            } else {
555                nullable_string_len(self.value.as_deref())
556            };
557        }
558        if version >= 0 {
559            n += 1;
560        }
561        if version >= 1 {
562            n += 1;
563        }
564        if version >= 0 {
565            n += 1;
566        }
567        if version >= 1 {
568            n += {
569                let prefix = array_len_prefix_len((self.synonyms).len(), flex);
570                let body: usize = (self.synonyms)
571                    .iter()
572                    .map(|it| it.encoded_len(version))
573                    .sum();
574                prefix + body
575            };
576        }
577        if version >= 3 {
578            n += 1;
579        }
580        if version >= 3 {
581            n += if flex {
582                compact_nullable_string_len(self.documentation.as_deref())
583            } else {
584                nullable_string_len(self.documentation.as_deref())
585            };
586        }
587        if flex {
588            let known_pairs: Vec<(u32, usize)> = Vec::new();
589            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
590        }
591        n
592    }
593}
594impl Decode<'_> for DescribeConfigsResourceResult {
595    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
596        let flex = version >= 4;
597        let mut out = Self::default();
598        Self::decode_field_0(&mut out, buf, version, flex)?;
599        Self::decode_field_1(&mut out, buf, version, flex)?;
600        Self::decode_field_2(&mut out, buf, version, flex)?;
601        Self::decode_field_3(&mut out, buf, version, flex)?;
602        Self::decode_field_4(&mut out, buf, version, flex)?;
603        Self::decode_field_5(&mut out, buf, version, flex)?;
604        Self::decode_field_6(&mut out, buf, version, flex)?;
605        Self::decode_field_7(&mut out, buf, version, flex)?;
606        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
607        Ok(out)
608    }
609}
610#[cfg(test)]
611impl DescribeConfigsResourceResult {
612    #[must_use]
613    pub fn populated(version: i16) -> Self {
614        let mut m = Self::default();
615        if version >= 0 {
616            m.name = "x".to_owned();
617        }
618        if version >= 0 {
619            m.value = Some("x".to_owned());
620        }
621        if version >= 0 {
622            m.read_only = true;
623        }
624        if version >= 1 {
625            m.config_source = 1i8;
626        }
627        if version >= 0 {
628            m.is_sensitive = true;
629        }
630        if version >= 1 {
631            m.synonyms = vec![DescribeConfigsSynonym::populated(version)];
632        }
633        if version >= 3 {
634            m.config_type = 1i8;
635        }
636        if version >= 3 {
637            m.documentation = Some("x".to_owned());
638        }
639        m
640    }
641}
642#[derive(Debug, Clone, PartialEq, Eq)]
643pub struct DescribeConfigsSynonym {
644    pub name: String,
645    pub value: Option<String>,
646    pub source: i8,
647    pub unknown_tagged_fields: UnknownTaggedFields,
648}
649impl Default for DescribeConfigsSynonym {
650    fn default() -> Self {
651        Self {
652            name: String::new(),
653            value: Some(String::new()),
654            source: 0i8,
655            unknown_tagged_fields: UnknownTaggedFields::default(),
656        }
657    }
658}
659impl Encode for DescribeConfigsSynonym {
660    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
661        let flex = version >= 4;
662        if version >= 1 {
663            if flex {
664                put_compact_string(buf, &self.name)?;
665            } else {
666                put_string(buf, &self.name)?;
667            }
668        }
669        if version >= 1 {
670            if flex {
671                put_compact_nullable_string(buf, self.value.as_deref())?;
672            } else {
673                put_nullable_string(buf, self.value.as_deref())?;
674            }
675        }
676        if version >= 1 {
677            put_i8(buf, self.source);
678        }
679        if flex {
680            let tagged = WriteTaggedFields::new();
681            tagged.write(buf, &self.unknown_tagged_fields)?;
682        }
683        Ok(())
684    }
685    fn encoded_len(&self, version: i16) -> usize {
686        let flex = version >= 4;
687        let mut n: usize = 0;
688        if version >= 1 {
689            n += if flex {
690                compact_string_len(&self.name)
691            } else {
692                string_len(&self.name)
693            };
694        }
695        if version >= 1 {
696            n += if flex {
697                compact_nullable_string_len(self.value.as_deref())
698            } else {
699                nullable_string_len(self.value.as_deref())
700            };
701        }
702        if version >= 1 {
703            n += 1;
704        }
705        if flex {
706            let known_pairs: Vec<(u32, usize)> = Vec::new();
707            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
708        }
709        n
710    }
711}
712impl Decode<'_> for DescribeConfigsSynonym {
713    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
714        let flex = version >= 4;
715        let mut out = Self::default();
716        if version >= 1 {
717            out.name = if flex {
718                get_compact_string_owned(buf)?
719            } else {
720                get_string_owned(buf)?
721            };
722        }
723        if version >= 1 {
724            out.value = if flex {
725                get_compact_nullable_string_owned(buf)?
726            } else {
727                get_nullable_string_owned(buf)?
728            };
729        }
730        if version >= 1 {
731            out.source = get_i8(buf)?;
732        }
733        if flex {
734            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
735        }
736        Ok(out)
737    }
738}
739#[cfg(test)]
740impl DescribeConfigsSynonym {
741    #[must_use]
742    pub fn populated(version: i16) -> Self {
743        let mut m = Self::default();
744        if version >= 1 {
745            m.name = "x".to_owned();
746        }
747        if version >= 1 {
748            m.value = Some("x".to_owned());
749        }
750        if version >= 1 {
751            m.source = 1i8;
752        }
753        m
754    }
755}
756/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
757/// Only includes fields valid for the given version.
758#[must_use]
759#[allow(unused_comparisons)]
760pub fn default_json(_version: i16) -> ::serde_json::Value {
761    let mut obj = ::serde_json::Map::new();
762    obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
763    obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
764    ::serde_json::Value::Object(obj)
765}