Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeConfigsResponse.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_i16, get_i32, get_i8, put_bool, put_i16, put_i32, 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 DescribeConfigsResponse {
25    pub throttle_time_ms: i32,
26    pub results: Vec<DescribeConfigsResult>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for DescribeConfigsResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.results).len(), flex); for it in &self.results { it.encode(buf, version)?; } } }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 { n += 4; }
48        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results).len(), flex); let body: usize = (self.results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for DescribeConfigsResponse {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
65        if version >= 0 { out.results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeConfigsResult::decode(buf, version)?); } v }; }
66        if flex {
67            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68                Ok(false)
69            })?;
70        }
71        Ok(out)
72    }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Default)]
76pub struct DescribeConfigsResult {
77    pub error_code: i16,
78    pub error_message: Option<String>,
79    pub resource_type: i8,
80    pub resource_name: String,
81    pub configs: Vec<DescribeConfigsResourceResult>,
82    pub unknown_tagged_fields: UnknownTaggedFields,
83}
84
85impl Encode for DescribeConfigsResult {
86    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
87        let flex = version >= 4;
88        if version >= 0 { put_i16(buf, self.error_code) }
89        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
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 { { crate::primitives::array::put_array_len(buf, (self.configs).len(), flex); for it in &self.configs { it.encode(buf, version)?; } } }
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 += 2; }
103        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
104        if version >= 0 { n += 1; }
105        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
106        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.configs).len(), flex); let body: usize = (self.configs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
107        if flex {
108            let known_pairs: Vec<(u32, usize)> = Vec::new();
109            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
110        }
111        n
112    }
113}
114
115impl<'de> Decode<'de> for DescribeConfigsResult {
116    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
117        let flex = version >= 4;
118        let mut out = Self::default();
119        if version >= 0 { out.error_code = get_i16(buf)?; }
120        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
121        if version >= 0 { out.resource_type = get_i8(buf)?; }
122        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
123        if version >= 0 { out.configs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeConfigsResourceResult::decode(buf, version)?); } v }; }
124        if flex {
125            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
126                Ok(false)
127            })?;
128        }
129        Ok(out)
130    }
131}
132
133#[derive(Debug, Clone, PartialEq, Eq)]
134pub struct DescribeConfigsResourceResult {
135    pub name: String,
136    pub value: Option<String>,
137    pub read_only: bool,
138    pub config_source: i8,
139    pub is_sensitive: bool,
140    pub synonyms: Vec<DescribeConfigsSynonym>,
141    pub config_type: i8,
142    pub documentation: Option<String>,
143    pub unknown_tagged_fields: UnknownTaggedFields,
144}
145
146impl Default for DescribeConfigsResourceResult {
147    fn default() -> Self {
148        Self {
149            name: String::new(),
150            value: None,
151            read_only: false,
152            config_source: -1i8,
153            is_sensitive: false,
154            synonyms: Vec::new(),
155            config_type: 0i8,
156            documentation: None,
157            unknown_tagged_fields: Default::default(),
158        }
159    }
160}
161
162impl Encode for DescribeConfigsResourceResult {
163    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
164        let flex = version >= 4;
165        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
166        if version >= 0 { if flex { put_compact_nullable_string(buf, self.value.as_deref()) } else { put_nullable_string(buf, self.value.as_deref()) } }
167        if version >= 0 { put_bool(buf, self.read_only) }
168        if version >= 1 { put_i8(buf, self.config_source) }
169        if version >= 0 { put_bool(buf, self.is_sensitive) }
170        if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.synonyms).len(), flex); for it in &self.synonyms { it.encode(buf, version)?; } } }
171        if version >= 3 { put_i8(buf, self.config_type) }
172        if version >= 3 { if flex { put_compact_nullable_string(buf, self.documentation.as_deref()) } else { put_nullable_string(buf, self.documentation.as_deref()) } }
173        if flex {
174            let tagged = WriteTaggedFields::new();
175            tagged.write(buf, &self.unknown_tagged_fields);
176        }
177        Ok(())
178    }
179    fn encoded_len(&self, version: i16) -> usize {
180        let flex = version >= 4;
181        let mut n: usize = 0;
182        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
183        if version >= 0 { n += if flex { compact_nullable_string_len(self.value.as_deref()) } else { nullable_string_len(self.value.as_deref()) }; }
184        if version >= 0 { n += 1; }
185        if version >= 1 { n += 1; }
186        if version >= 0 { n += 1; }
187        if version >= 1 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.synonyms).len(), flex); let body: usize = (self.synonyms).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
188        if version >= 3 { n += 1; }
189        if version >= 3 { n += if flex { compact_nullable_string_len(self.documentation.as_deref()) } else { nullable_string_len(self.documentation.as_deref()) }; }
190        if flex {
191            let known_pairs: Vec<(u32, usize)> = Vec::new();
192            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
193        }
194        n
195    }
196}
197
198impl<'de> Decode<'de> for DescribeConfigsResourceResult {
199    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
200        let flex = version >= 4;
201        let mut out = Self::default();
202        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
203        if version >= 0 { out.value = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
204        if version >= 0 { out.read_only = get_bool(buf)?; }
205        if version >= 1 { out.config_source = get_i8(buf)?; }
206        if version >= 0 { out.is_sensitive = get_bool(buf)?; }
207        if version >= 1 { out.synonyms = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeConfigsSynonym::decode(buf, version)?); } v }; }
208        if version >= 3 { out.config_type = get_i8(buf)?; }
209        if version >= 3 { out.documentation = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
210        if flex {
211            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
212                Ok(false)
213            })?;
214        }
215        Ok(out)
216    }
217}
218
219#[derive(Debug, Clone, PartialEq, Eq, Default)]
220pub struct DescribeConfigsSynonym {
221    pub name: String,
222    pub value: Option<String>,
223    pub source: i8,
224    pub unknown_tagged_fields: UnknownTaggedFields,
225}
226
227impl Encode for DescribeConfigsSynonym {
228    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
229        let flex = version >= 4;
230        if version >= 1 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
231        if version >= 1 { if flex { put_compact_nullable_string(buf, self.value.as_deref()) } else { put_nullable_string(buf, self.value.as_deref()) } }
232        if version >= 1 { put_i8(buf, self.source) }
233        if flex {
234            let tagged = WriteTaggedFields::new();
235            tagged.write(buf, &self.unknown_tagged_fields);
236        }
237        Ok(())
238    }
239    fn encoded_len(&self, version: i16) -> usize {
240        let flex = version >= 4;
241        let mut n: usize = 0;
242        if version >= 1 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
243        if version >= 1 { n += if flex { compact_nullable_string_len(self.value.as_deref()) } else { nullable_string_len(self.value.as_deref()) }; }
244        if version >= 1 { n += 1; }
245        if flex {
246            let known_pairs: Vec<(u32, usize)> = Vec::new();
247            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
248        }
249        n
250    }
251}
252
253impl<'de> Decode<'de> for DescribeConfigsSynonym {
254    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
255        let flex = version >= 4;
256        let mut out = Self::default();
257        if version >= 1 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
258        if version >= 1 { out.value = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
259        if version >= 1 { out.source = get_i8(buf)?; }
260        if flex {
261            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
262                Ok(false)
263            })?;
264        }
265        Ok(out)
266    }
267}
268
269/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
270/// Only includes fields valid for the given version.
271#[must_use]
272#[allow(unused_comparisons)]
273pub fn default_json(version: i16) -> ::serde_json::Value {
274    let mut obj = ::serde_json::Map::new();
275    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
276    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
277    ::serde_json::Value::Object(obj)
278}