Skip to main content

odradek_protocol/messages/
describe_configs_response.rs

1//! `DescribeConfigsResponse` — generated from `schemas/DescribeConfigsResponse.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 4
25}
26
27/// `DescribeConfigsResponse`, versions 1-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct DescribeConfigsResponse {
31    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
32    pub throttle_time_ms: i32,
33    /// The results for each resource.
34    pub results: Vec<DescribeConfigsResult>,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for DescribeConfigsResponse {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0,
43            results: Vec::new(),
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl DescribeConfigsResponse {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 32;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 1;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 4;
56
57    /// Encode this `DescribeConfigsResponse` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        buf.put_i32(self.throttle_time_ms);
60        if is_flexible(version) {
61            wire::put_compact_array_len(buf, Some(self.results.len()));
62        } else {
63            wire::put_array_len(buf, Some(self.results.len()))?;
64        }
65        for item in &self.results {
66            item.encode(buf, version)?;
67        }
68        if is_flexible(version) {
69            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73
74    /// Decode one `DescribeConfigsResponse`, bounding allocation by the default
75    /// [`Limits`] derived from `buf`'s remaining length.
76    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
77        Self::decode_with_limits(buf, version, Limits::default())
78    }
79
80    /// Decode one `DescribeConfigsResponse` under `limits`.
81    pub fn decode_with_limits(
82        buf: &mut impl Buf,
83        version: i16,
84        limits: Limits,
85    ) -> Result<Self, DecodeError> {
86        let mut budget = limits.budget(buf.remaining());
87        Self::decode_with_budget(buf, version, &mut budget)
88    }
89
90    /// Decode one `DescribeConfigsResponse` against an existing `budget`.
91    pub fn decode_with_budget(
92        buf: &mut impl Buf,
93        version: i16,
94        budget: &mut Budget,
95    ) -> Result<Self, DecodeError> {
96        let mut this = Self::default();
97        this.throttle_time_ms = wire::get_i32(buf)?;
98        this.results = {
99            let len = if is_flexible(version) {
100                wire::get_compact_array_len(buf)?
101            } else {
102                wire::get_array_len(buf)?
103            };
104            match len {
105                None => return Err(DecodeError::InvalidLength(-1)),
106                Some(n) => {
107                    let mut items = Vec::new();
108                    for _ in 0..n {
109                        let mark = buf.remaining();
110                        let item = DescribeConfigsResult::decode_with_budget(buf, version, budget)?;
111                        budget.progress(mark, buf.remaining())?;
112                        budget.push(&mut items, item)?;
113                    }
114                    items
115                }
116            }
117        };
118        if is_flexible(version) {
119            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
120        }
121        Ok(this)
122    }
123}
124
125impl crate::Message for DescribeConfigsResponse {
126    const API_KEY: i16 = 32;
127    const MIN_VERSION: i16 = 1;
128    const MAX_VERSION: i16 = 4;
129
130    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
131        DescribeConfigsResponse::encode(self, buf, version)
132    }
133    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
134        DescribeConfigsResponse::decode(buf, version)
135    }
136    fn decode_with_limits(
137        buf: &mut impl Buf,
138        version: i16,
139        limits: Limits,
140    ) -> Result<Self, DecodeError> {
141        DescribeConfigsResponse::decode_with_limits(buf, version, limits)
142    }
143    fn throttle_time_ms(&self) -> Option<i32> {
144        Some(self.throttle_time_ms)
145    }
146}
147
148/// `DescribeConfigsResult` (nested in [`DescribeConfigsResponse`]).
149#[derive(Debug, Clone, PartialEq)]
150#[non_exhaustive]
151pub struct DescribeConfigsResult {
152    /// The error code, or 0 if we were able to successfully describe the configurations.
153    pub error_code: i16,
154    /// The error message, or null if we were able to successfully describe the configurations.
155    pub error_message: Option<String>,
156    /// The resource type.
157    pub resource_type: i8,
158    /// The resource name.
159    pub resource_name: String,
160    /// Each listed configuration.
161    pub configs: Vec<DescribeConfigsResourceResult>,
162    /// Tagged fields not (yet) known to this crate, kept raw.
163    pub unknown_tagged_fields: Vec<RawTaggedField>,
164}
165
166impl Default for DescribeConfigsResult {
167    fn default() -> Self {
168        Self {
169            error_code: 0,
170            error_message: Some(String::new()),
171            resource_type: 0,
172            resource_name: String::new(),
173            configs: Vec::new(),
174            unknown_tagged_fields: Vec::new(),
175        }
176    }
177}
178
179impl DescribeConfigsResult {
180    /// Encode this `DescribeConfigsResult` at `version`.
181    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
182        buf.put_i16(self.error_code);
183        if is_flexible(version) {
184            wire::put_compact_nullable_string(buf, self.error_message.as_deref());
185        } else {
186            wire::put_nullable_string(buf, self.error_message.as_deref())?;
187        }
188        buf.put_i8(self.resource_type);
189        if is_flexible(version) {
190            wire::put_compact_string(buf, &self.resource_name);
191        } else {
192            wire::put_string(buf, &self.resource_name)?;
193        }
194        if is_flexible(version) {
195            wire::put_compact_array_len(buf, Some(self.configs.len()));
196        } else {
197            wire::put_array_len(buf, Some(self.configs.len()))?;
198        }
199        for item in &self.configs {
200            item.encode(buf, version)?;
201        }
202        if is_flexible(version) {
203            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
204        }
205        Ok(())
206    }
207
208    /// Decode one `DescribeConfigsResult`, bounding allocation by the default
209    /// [`Limits`] derived from `buf`'s remaining length.
210    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
211        Self::decode_with_limits(buf, version, Limits::default())
212    }
213
214    /// Decode one `DescribeConfigsResult` under `limits`.
215    pub fn decode_with_limits(
216        buf: &mut impl Buf,
217        version: i16,
218        limits: Limits,
219    ) -> Result<Self, DecodeError> {
220        let mut budget = limits.budget(buf.remaining());
221        Self::decode_with_budget(buf, version, &mut budget)
222    }
223
224    /// Decode one `DescribeConfigsResult` against an existing `budget`.
225    pub fn decode_with_budget(
226        buf: &mut impl Buf,
227        version: i16,
228        budget: &mut Budget,
229    ) -> Result<Self, DecodeError> {
230        let mut this = Self::default();
231        this.error_code = wire::get_i16(buf)?;
232        this.error_message = if is_flexible(version) {
233            wire::get_compact_nullable_string(buf)?
234        } else {
235            wire::get_nullable_string(buf)?
236        };
237        this.resource_type = wire::get_i8(buf)?;
238        this.resource_name = if is_flexible(version) {
239            wire::get_compact_string(buf)?
240        } else {
241            wire::get_string(buf)?
242        };
243        this.configs = {
244            let len = if is_flexible(version) {
245                wire::get_compact_array_len(buf)?
246            } else {
247                wire::get_array_len(buf)?
248            };
249            match len {
250                None => return Err(DecodeError::InvalidLength(-1)),
251                Some(n) => {
252                    let mut items = Vec::new();
253                    for _ in 0..n {
254                        let mark = buf.remaining();
255                        let item = DescribeConfigsResourceResult::decode_with_budget(
256                            buf, version, budget,
257                        )?;
258                        budget.progress(mark, buf.remaining())?;
259                        budget.push(&mut items, item)?;
260                    }
261                    items
262                }
263            }
264        };
265        if is_flexible(version) {
266            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
267        }
268        Ok(this)
269    }
270}
271
272/// `DescribeConfigsResourceResult` (nested in [`DescribeConfigsResponse`]).
273#[derive(Debug, Clone, PartialEq)]
274#[non_exhaustive]
275pub struct DescribeConfigsResourceResult {
276    /// The configuration name.
277    pub name: String,
278    /// The configuration value.
279    pub value: Option<String>,
280    /// True if the configuration is read-only.
281    pub read_only: bool,
282    /// The configuration source.
283    pub config_source: i8,
284    /// True if this configuration is sensitive.
285    pub is_sensitive: bool,
286    /// The synonyms for this configuration key.
287    pub synonyms: Vec<DescribeConfigsSynonym>,
288    /// The configuration data type. Type can be one of the following values - BOOLEAN, STRING, INT, SHORT, LONG, DOUBLE, LIST, CLASS, PASSWORD.
289    pub config_type: i8,
290    /// The configuration documentation.
291    pub documentation: Option<String>,
292    /// Tagged fields not (yet) known to this crate, kept raw.
293    pub unknown_tagged_fields: Vec<RawTaggedField>,
294}
295
296impl Default for DescribeConfigsResourceResult {
297    fn default() -> Self {
298        Self {
299            name: String::new(),
300            value: Some(String::new()),
301            read_only: false,
302            config_source: -1,
303            is_sensitive: false,
304            synonyms: Vec::new(),
305            config_type: 0,
306            documentation: Some(String::new()),
307            unknown_tagged_fields: Vec::new(),
308        }
309    }
310}
311
312impl DescribeConfigsResourceResult {
313    /// Encode this `DescribeConfigsResourceResult` at `version`.
314    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
315        if is_flexible(version) {
316            wire::put_compact_string(buf, &self.name);
317        } else {
318            wire::put_string(buf, &self.name)?;
319        }
320        if is_flexible(version) {
321            wire::put_compact_nullable_string(buf, self.value.as_deref());
322        } else {
323            wire::put_nullable_string(buf, self.value.as_deref())?;
324        }
325        buf.put_u8(u8::from(self.read_only));
326        buf.put_i8(self.config_source);
327        buf.put_u8(u8::from(self.is_sensitive));
328        if is_flexible(version) {
329            wire::put_compact_array_len(buf, Some(self.synonyms.len()));
330        } else {
331            wire::put_array_len(buf, Some(self.synonyms.len()))?;
332        }
333        for item in &self.synonyms {
334            item.encode(buf, version)?;
335        }
336        if version >= 3 {
337            buf.put_i8(self.config_type);
338        }
339        if version >= 3 {
340            if is_flexible(version) {
341                wire::put_compact_nullable_string(buf, self.documentation.as_deref());
342            } else {
343                wire::put_nullable_string(buf, self.documentation.as_deref())?;
344            }
345        }
346        if is_flexible(version) {
347            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
348        }
349        Ok(())
350    }
351
352    /// Decode one `DescribeConfigsResourceResult`, bounding allocation by the default
353    /// [`Limits`] derived from `buf`'s remaining length.
354    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
355        Self::decode_with_limits(buf, version, Limits::default())
356    }
357
358    /// Decode one `DescribeConfigsResourceResult` under `limits`.
359    pub fn decode_with_limits(
360        buf: &mut impl Buf,
361        version: i16,
362        limits: Limits,
363    ) -> Result<Self, DecodeError> {
364        let mut budget = limits.budget(buf.remaining());
365        Self::decode_with_budget(buf, version, &mut budget)
366    }
367
368    /// Decode one `DescribeConfigsResourceResult` against an existing `budget`.
369    pub fn decode_with_budget(
370        buf: &mut impl Buf,
371        version: i16,
372        budget: &mut Budget,
373    ) -> Result<Self, DecodeError> {
374        let mut this = Self::default();
375        this.name = if is_flexible(version) {
376            wire::get_compact_string(buf)?
377        } else {
378            wire::get_string(buf)?
379        };
380        this.value = if is_flexible(version) {
381            wire::get_compact_nullable_string(buf)?
382        } else {
383            wire::get_nullable_string(buf)?
384        };
385        this.read_only = wire::get_bool(buf)?;
386        this.config_source = wire::get_i8(buf)?;
387        this.is_sensitive = wire::get_bool(buf)?;
388        this.synonyms = {
389            let len = if is_flexible(version) {
390                wire::get_compact_array_len(buf)?
391            } else {
392                wire::get_array_len(buf)?
393            };
394            match len {
395                None => return Err(DecodeError::InvalidLength(-1)),
396                Some(n) => {
397                    let mut items = Vec::new();
398                    for _ in 0..n {
399                        let mark = buf.remaining();
400                        let item =
401                            DescribeConfigsSynonym::decode_with_budget(buf, version, budget)?;
402                        budget.progress(mark, buf.remaining())?;
403                        budget.push(&mut items, item)?;
404                    }
405                    items
406                }
407            }
408        };
409        if version >= 3 {
410            this.config_type = wire::get_i8(buf)?;
411        }
412        if version >= 3 {
413            this.documentation = if is_flexible(version) {
414                wire::get_compact_nullable_string(buf)?
415            } else {
416                wire::get_nullable_string(buf)?
417            };
418        }
419        if is_flexible(version) {
420            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
421        }
422        Ok(this)
423    }
424}
425
426/// `DescribeConfigsSynonym` (nested in [`DescribeConfigsResponse`]).
427#[derive(Debug, Clone, PartialEq)]
428#[non_exhaustive]
429pub struct DescribeConfigsSynonym {
430    /// The synonym name.
431    pub name: String,
432    /// The synonym value.
433    pub value: Option<String>,
434    /// The synonym source.
435    pub source: i8,
436    /// Tagged fields not (yet) known to this crate, kept raw.
437    pub unknown_tagged_fields: Vec<RawTaggedField>,
438}
439
440impl Default for DescribeConfigsSynonym {
441    fn default() -> Self {
442        Self {
443            name: String::new(),
444            value: Some(String::new()),
445            source: 0,
446            unknown_tagged_fields: Vec::new(),
447        }
448    }
449}
450
451impl DescribeConfigsSynonym {
452    /// Encode this `DescribeConfigsSynonym` at `version`.
453    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
454        if is_flexible(version) {
455            wire::put_compact_string(buf, &self.name);
456        } else {
457            wire::put_string(buf, &self.name)?;
458        }
459        if is_flexible(version) {
460            wire::put_compact_nullable_string(buf, self.value.as_deref());
461        } else {
462            wire::put_nullable_string(buf, self.value.as_deref())?;
463        }
464        buf.put_i8(self.source);
465        if is_flexible(version) {
466            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
467        }
468        Ok(())
469    }
470
471    /// Decode one `DescribeConfigsSynonym`, bounding allocation by the default
472    /// [`Limits`] derived from `buf`'s remaining length.
473    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
474        Self::decode_with_limits(buf, version, Limits::default())
475    }
476
477    /// Decode one `DescribeConfigsSynonym` under `limits`.
478    pub fn decode_with_limits(
479        buf: &mut impl Buf,
480        version: i16,
481        limits: Limits,
482    ) -> Result<Self, DecodeError> {
483        let mut budget = limits.budget(buf.remaining());
484        Self::decode_with_budget(buf, version, &mut budget)
485    }
486
487    /// Decode one `DescribeConfigsSynonym` against an existing `budget`.
488    pub fn decode_with_budget(
489        buf: &mut impl Buf,
490        version: i16,
491        budget: &mut Budget,
492    ) -> Result<Self, DecodeError> {
493        let mut this = Self::default();
494        this.name = if is_flexible(version) {
495            wire::get_compact_string(buf)?
496        } else {
497            wire::get_string(buf)?
498        };
499        this.value = if is_flexible(version) {
500            wire::get_compact_nullable_string(buf)?
501        } else {
502            wire::get_nullable_string(buf)?
503        };
504        this.source = wire::get_i8(buf)?;
505        if is_flexible(version) {
506            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
507        }
508        Ok(this)
509    }
510}