Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsResponse.borrowed.rs

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