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