Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i8, put_bool, put_i8};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 32;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 4;
18pub const FLEXIBLE_MIN: i16 = 4;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeConfigsRequest {
25    pub resources: Vec<DescribeConfigsResource>,
26    pub include_synonyms: bool,
27    pub include_documentation: bool,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for DescribeConfigsRequest {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35        }
36        let flex = is_flexible(version);
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.resources).len(), flex); for it in &self.resources { it.encode(buf, version)?; } } }
38        if version >= 1 { put_bool(buf, self.include_synonyms) }
39        if version >= 3 { put_bool(buf, self.include_documentation) }
40        if flex {
41            let tagged = WriteTaggedFields::new();
42            tagged.write(buf, &self.unknown_tagged_fields);
43        }
44        Ok(())
45    }
46    fn encoded_len(&self, version: i16) -> usize {
47        let flex = is_flexible(version);
48        let mut n: usize = 0;
49        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.resources).len(), flex); let body: usize = (self.resources).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
50        if version >= 1 { n += 1; }
51        if version >= 3 { n += 1; }
52        if flex {
53            let known_pairs: Vec<(u32, usize)> = Vec::new();
54            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55        }
56        n
57    }
58}
59
60impl<'de> Decode<'de> for DescribeConfigsRequest {
61    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
64        }
65        let flex = is_flexible(version);
66        let mut out = Self::default();
67        if version >= 0 { out.resources = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeConfigsResource::decode(buf, version)?); } v }; }
68        if version >= 1 { out.include_synonyms = get_bool(buf)?; }
69        if version >= 3 { out.include_documentation = get_bool(buf)?; }
70        if flex {
71            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
72                Ok(false)
73            })?;
74        }
75        Ok(out)
76    }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Default)]
80pub struct DescribeConfigsResource {
81    pub resource_type: i8,
82    pub resource_name: String,
83    pub configuration_keys: Option<Vec<String>>,
84    pub unknown_tagged_fields: UnknownTaggedFields,
85}
86
87impl Encode for DescribeConfigsResource {
88    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
89        let flex = version >= 4;
90        if version >= 0 { put_i8(buf, self.resource_type) }
91        if version >= 0 { if flex { put_compact_string(buf, &self.resource_name) } else { put_string(buf, &self.resource_name) } }
92        if version >= 0 { { let len = (self.configuration_keys).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.configuration_keys { for it in v { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } } }
93        if flex {
94            let tagged = WriteTaggedFields::new();
95            tagged.write(buf, &self.unknown_tagged_fields);
96        }
97        Ok(())
98    }
99    fn encoded_len(&self, version: i16) -> usize {
100        let flex = version >= 4;
101        let mut n: usize = 0;
102        if version >= 0 { n += 1; }
103        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
104        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.configuration_keys).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum()); prefix + body }; }
105        if flex {
106            let known_pairs: Vec<(u32, usize)> = Vec::new();
107            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
108        }
109        n
110    }
111}
112
113impl<'de> Decode<'de> for DescribeConfigsResource {
114    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
115        let flex = version >= 4;
116        let mut out = Self::default();
117        if version >= 0 { out.resource_type = get_i8(buf)?; }
118        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
119        if version >= 0 { out.configuration_keys = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } Some(v) } } }; }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
122                Ok(false)
123            })?;
124        }
125        Ok(out)
126    }
127}
128
129/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
130/// Only includes fields valid for the given version.
131#[must_use]
132#[allow(unused_comparisons)]
133pub fn default_json(version: i16) -> ::serde_json::Value {
134    let mut obj = ::serde_json::Map::new();
135    obj.insert("resources".to_string(), ::serde_json::Value::Array(vec![]));
136    if version >= 1 {
137        obj.insert("includeSynonyms".to_string(), ::serde_json::Value::Bool(false));
138    }
139    if version >= 3 {
140        obj.insert("includeDocumentation".to_string(), ::serde_json::Value::Bool(false));
141    }
142    ::serde_json::Value::Object(obj)
143}
144
145impl crate::ProtocolRequest for DescribeConfigsRequest {
146    const API_KEY: i16 = API_KEY;
147    const MIN_VERSION: i16 = MIN_VERSION;
148    const MAX_VERSION: i16 = MAX_VERSION;
149    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
150    type Response = super::describe_configs_response::DescribeConfigsResponse;
151}