1use bytes::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, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 32;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 4;
21pub const FLEXIBLE_MIN: i16 = 4;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DescribeConfigsResponse<'a> {
28 pub throttle_time_ms: i32,
29 pub results: Vec<DescribeConfigsResult<'a>>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for DescribeConfigsResponse<'a> {
34 fn default() -> Self {
35 Self {
36 throttle_time_ms: 0i32,
37 results: Vec::new(),
38 unknown_tagged_fields: Default::default(),
39 }
40 }
41}
42
43impl<'a> DescribeConfigsResponse<'a> {
44 pub fn to_owned(&self) -> crate::owned::describe_configs_response::DescribeConfigsResponse {
45 crate::owned::describe_configs_response::DescribeConfigsResponse {
46 throttle_time_ms: (self.throttle_time_ms),
47 results: (self.results).iter().map(|it| it.to_owned()).collect(),
48 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49 }
50 }
51}
52
53impl<'a> Encode for DescribeConfigsResponse<'a> {
54 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57 }
58 let flex = is_flexible(version);
59 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
60 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.results).len(), flex); for it in &self.results { it.encode(buf, version)?; } } }
61 if flex {
62 let tagged = WriteTaggedFields::new();
63 tagged.write(buf, &self.unknown_tagged_fields);
64 }
65 Ok(())
66 }
67 fn encoded_len(&self, version: i16) -> usize {
68 let flex = is_flexible(version);
69 let mut n: usize = 0;
70 if version >= 0 { n += 4; }
71 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 }; }
72 if flex {
73 let known_pairs: Vec<(u32, usize)> = Vec::new();
74 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75 }
76 n
77 }
78}
79
80impl<'de> DecodeBorrow<'de> for DescribeConfigsResponse<'de> {
81 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
84 }
85 let flex = is_flexible(version);
86 let mut out = Self::default();
87 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
88 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_borrow(buf, version)?); } v }; }
89 if flex {
90 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
91 Ok(false)
92 })?;
93 }
94 Ok(out)
95 }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct DescribeConfigsResult<'a> {
100 pub error_code: i16,
101 pub error_message: Option<&'a str>,
102 pub resource_type: i8,
103 pub resource_name: &'a str,
104 pub configs: Vec<DescribeConfigsResourceResult<'a>>,
105 pub unknown_tagged_fields: UnknownTaggedFields,
106}
107
108impl<'a> Default for DescribeConfigsResult<'a> {
109 fn default() -> Self {
110 Self {
111 error_code: 0i16,
112 error_message: None,
113 resource_type: 0i8,
114 resource_name: "",
115 configs: Vec::new(),
116 unknown_tagged_fields: Default::default(),
117 }
118 }
119}
120
121impl<'a> DescribeConfigsResult<'a> {
122 pub fn to_owned(&self) -> crate::owned::describe_configs_response::DescribeConfigsResult {
123 crate::owned::describe_configs_response::DescribeConfigsResult {
124 error_code: (self.error_code),
125 error_message: (self.error_message).map(|s| s.to_string()),
126 resource_type: (self.resource_type),
127 resource_name: (self.resource_name).to_string(),
128 configs: (self.configs).iter().map(|it| it.to_owned()).collect(),
129 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
130 }
131 }
132}
133
134impl<'a> Encode for DescribeConfigsResult<'a> {
135 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136 let flex = version >= 4;
137 if version >= 0 { put_i16(buf, self.error_code) }
138 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
139 if version >= 0 { put_i8(buf, self.resource_type) }
140 if version >= 0 { if flex { put_compact_string(buf, self.resource_name) } else { put_string(buf, self.resource_name) } }
141 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.configs).len(), flex); for it in &self.configs { it.encode(buf, version)?; } } }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = version >= 4;
150 let mut n: usize = 0;
151 if version >= 0 { n += 2; }
152 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
153 if version >= 0 { n += 1; }
154 if version >= 0 { n += if flex { compact_string_len(self.resource_name) } else { string_len(self.resource_name) }; }
155 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 }; }
156 if flex {
157 let known_pairs: Vec<(u32, usize)> = Vec::new();
158 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
159 }
160 n
161 }
162}
163
164impl<'de> DecodeBorrow<'de> for DescribeConfigsResult<'de> {
165 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
166 let flex = version >= 4;
167 let mut out = Self::default();
168 if version >= 0 { out.error_code = get_i16(buf)?; }
169 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
170 if version >= 0 { out.resource_type = get_i8(buf)?; }
171 if version >= 0 { out.resource_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
172 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_borrow(buf, version)?); } v }; }
173 if flex {
174 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
175 Ok(false)
176 })?;
177 }
178 Ok(out)
179 }
180}
181
182#[derive(Debug, Clone, PartialEq, Eq)]
183pub struct DescribeConfigsResourceResult<'a> {
184 pub name: &'a str,
185 pub value: Option<&'a str>,
186 pub read_only: bool,
187 pub config_source: i8,
188 pub is_sensitive: bool,
189 pub synonyms: Vec<DescribeConfigsSynonym<'a>>,
190 pub config_type: i8,
191 pub documentation: Option<&'a str>,
192 pub unknown_tagged_fields: UnknownTaggedFields,
193}
194
195impl<'a> Default for DescribeConfigsResourceResult<'a> {
196 fn default() -> Self {
197 Self {
198 name: "",
199 value: None,
200 read_only: false,
201 config_source: -1i8,
202 is_sensitive: false,
203 synonyms: Vec::new(),
204 config_type: 0i8,
205 documentation: None,
206 unknown_tagged_fields: Default::default(),
207 }
208 }
209}
210
211impl<'a> DescribeConfigsResourceResult<'a> {
212 pub fn to_owned(&self) -> crate::owned::describe_configs_response::DescribeConfigsResourceResult {
213 crate::owned::describe_configs_response::DescribeConfigsResourceResult {
214 name: (self.name).to_string(),
215 value: (self.value).map(|s| s.to_string()),
216 read_only: (self.read_only),
217 config_source: (self.config_source),
218 is_sensitive: (self.is_sensitive),
219 synonyms: (self.synonyms).iter().map(|it| it.to_owned()).collect(),
220 config_type: (self.config_type),
221 documentation: (self.documentation).map(|s| s.to_string()),
222 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
223 }
224 }
225}
226
227impl<'a> Encode for DescribeConfigsResourceResult<'a> {
228 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
229 let flex = version >= 4;
230 if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
231 if version >= 0 { if flex { put_compact_nullable_string(buf, self.value) } else { put_nullable_string(buf, self.value) } }
232 if version >= 0 { put_bool(buf, self.read_only) }
233 if version >= 1 { put_i8(buf, self.config_source) }
234 if version >= 0 { put_bool(buf, self.is_sensitive) }
235 if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.synonyms).len(), flex); for it in &self.synonyms { it.encode(buf, version)?; } } }
236 if version >= 3 { put_i8(buf, self.config_type) }
237 if version >= 3 { if flex { put_compact_nullable_string(buf, self.documentation) } else { put_nullable_string(buf, self.documentation) } }
238 if flex {
239 let tagged = WriteTaggedFields::new();
240 tagged.write(buf, &self.unknown_tagged_fields);
241 }
242 Ok(())
243 }
244 fn encoded_len(&self, version: i16) -> usize {
245 let flex = version >= 4;
246 let mut n: usize = 0;
247 if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
248 if version >= 0 { n += if flex { compact_nullable_string_len(self.value) } else { nullable_string_len(self.value) }; }
249 if version >= 0 { n += 1; }
250 if version >= 1 { n += 1; }
251 if version >= 0 { n += 1; }
252 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 }; }
253 if version >= 3 { n += 1; }
254 if version >= 3 { n += if flex { compact_nullable_string_len(self.documentation) } else { nullable_string_len(self.documentation) }; }
255 if flex {
256 let known_pairs: Vec<(u32, usize)> = Vec::new();
257 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
258 }
259 n
260 }
261}
262
263impl<'de> DecodeBorrow<'de> for DescribeConfigsResourceResult<'de> {
264 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
265 let flex = version >= 4;
266 let mut out = Self::default();
267 if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
268 if version >= 0 { out.value = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
269 if version >= 0 { out.read_only = get_bool(buf)?; }
270 if version >= 1 { out.config_source = get_i8(buf)?; }
271 if version >= 0 { out.is_sensitive = get_bool(buf)?; }
272 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_borrow(buf, version)?); } v }; }
273 if version >= 3 { out.config_type = get_i8(buf)?; }
274 if version >= 3 { out.documentation = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
275 if flex {
276 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
277 Ok(false)
278 })?;
279 }
280 Ok(out)
281 }
282}
283
284#[derive(Debug, Clone, PartialEq, Eq)]
285pub struct DescribeConfigsSynonym<'a> {
286 pub name: &'a str,
287 pub value: Option<&'a str>,
288 pub source: i8,
289 pub unknown_tagged_fields: UnknownTaggedFields,
290}
291
292impl<'a> Default for DescribeConfigsSynonym<'a> {
293 fn default() -> Self {
294 Self {
295 name: "",
296 value: None,
297 source: 0i8,
298 unknown_tagged_fields: Default::default(),
299 }
300 }
301}
302
303impl<'a> DescribeConfigsSynonym<'a> {
304 pub fn to_owned(&self) -> crate::owned::describe_configs_response::DescribeConfigsSynonym {
305 crate::owned::describe_configs_response::DescribeConfigsSynonym {
306 name: (self.name).to_string(),
307 value: (self.value).map(|s| s.to_string()),
308 source: (self.source),
309 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
310 }
311 }
312}
313
314impl<'a> Encode for DescribeConfigsSynonym<'a> {
315 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
316 let flex = version >= 4;
317 if version >= 1 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
318 if version >= 1 { if flex { put_compact_nullable_string(buf, self.value) } else { put_nullable_string(buf, self.value) } }
319 if version >= 1 { put_i8(buf, self.source) }
320 if flex {
321 let tagged = WriteTaggedFields::new();
322 tagged.write(buf, &self.unknown_tagged_fields);
323 }
324 Ok(())
325 }
326 fn encoded_len(&self, version: i16) -> usize {
327 let flex = version >= 4;
328 let mut n: usize = 0;
329 if version >= 1 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
330 if version >= 1 { n += if flex { compact_nullable_string_len(self.value) } else { nullable_string_len(self.value) }; }
331 if version >= 1 { n += 1; }
332 if flex {
333 let known_pairs: Vec<(u32, usize)> = Vec::new();
334 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
335 }
336 n
337 }
338}
339
340impl<'de> DecodeBorrow<'de> for DescribeConfigsSynonym<'de> {
341 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
342 let flex = version >= 4;
343 let mut out = Self::default();
344 if version >= 1 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
345 if version >= 1 { out.value = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
346 if version >= 1 { out.source = get_i8(buf)?; }
347 if flex {
348 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
349 Ok(false)
350 })?;
351 }
352 Ok(out)
353 }
354}