kafka_protocol/messages/
describe_configs_request.rs

1//! DescribeConfigsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeConfigsRequest.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 1-4
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DescribeConfigsRequest {
24    /// The resources whose configurations we want to describe.
25    ///
26    /// Supported API versions: 1-4
27    pub resources: Vec<DescribeConfigsResource>,
28
29    /// True if we should include all synonyms.
30    ///
31    /// Supported API versions: 1-4
32    pub include_synonyms: bool,
33
34    /// True if we should include configuration documentation.
35    ///
36    /// Supported API versions: 3-4
37    pub include_documentation: bool,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl DescribeConfigsRequest {
44    /// Sets `resources` to the passed value.
45    ///
46    /// The resources whose configurations we want to describe.
47    ///
48    /// Supported API versions: 1-4
49    pub fn with_resources(mut self, value: Vec<DescribeConfigsResource>) -> Self {
50        self.resources = value;
51        self
52    }
53    /// Sets `include_synonyms` to the passed value.
54    ///
55    /// True if we should include all synonyms.
56    ///
57    /// Supported API versions: 1-4
58    pub fn with_include_synonyms(mut self, value: bool) -> Self {
59        self.include_synonyms = value;
60        self
61    }
62    /// Sets `include_documentation` to the passed value.
63    ///
64    /// True if we should include configuration documentation.
65    ///
66    /// Supported API versions: 3-4
67    pub fn with_include_documentation(mut self, value: bool) -> Self {
68        self.include_documentation = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "client")]
84impl Encodable for DescribeConfigsRequest {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 1 || version > 4 {
87            bail!("specified version not supported by this message type");
88        }
89        if version >= 4 {
90            types::CompactArray(types::Struct { version }).encode(buf, &self.resources)?;
91        } else {
92            types::Array(types::Struct { version }).encode(buf, &self.resources)?;
93        }
94        types::Boolean.encode(buf, &self.include_synonyms)?;
95        if version >= 3 {
96            types::Boolean.encode(buf, &self.include_documentation)?;
97        } else {
98            if self.include_documentation {
99                bail!("A field is set that is not available on the selected protocol version");
100            }
101        }
102        if version >= 4 {
103            let num_tagged_fields = self.unknown_tagged_fields.len();
104            if num_tagged_fields > std::u32::MAX as usize {
105                bail!(
106                    "Too many tagged fields to encode ({} fields)",
107                    num_tagged_fields
108                );
109            }
110            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
111
112            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
113        }
114        Ok(())
115    }
116    fn compute_size(&self, version: i16) -> Result<usize> {
117        let mut total_size = 0;
118        if version >= 4 {
119            total_size +=
120                types::CompactArray(types::Struct { version }).compute_size(&self.resources)?;
121        } else {
122            total_size += types::Array(types::Struct { version }).compute_size(&self.resources)?;
123        }
124        total_size += types::Boolean.compute_size(&self.include_synonyms)?;
125        if version >= 3 {
126            total_size += types::Boolean.compute_size(&self.include_documentation)?;
127        } else {
128            if self.include_documentation {
129                bail!("A field is set that is not available on the selected protocol version");
130            }
131        }
132        if version >= 4 {
133            let num_tagged_fields = self.unknown_tagged_fields.len();
134            if num_tagged_fields > std::u32::MAX as usize {
135                bail!(
136                    "Too many tagged fields to encode ({} fields)",
137                    num_tagged_fields
138                );
139            }
140            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
141
142            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
143        }
144        Ok(total_size)
145    }
146}
147
148#[cfg(feature = "broker")]
149impl Decodable for DescribeConfigsRequest {
150    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
151        if version < 1 || version > 4 {
152            bail!("specified version not supported by this message type");
153        }
154        let resources = if version >= 4 {
155            types::CompactArray(types::Struct { version }).decode(buf)?
156        } else {
157            types::Array(types::Struct { version }).decode(buf)?
158        };
159        let include_synonyms = types::Boolean.decode(buf)?;
160        let include_documentation = if version >= 3 {
161            types::Boolean.decode(buf)?
162        } else {
163            false
164        };
165        let mut unknown_tagged_fields = BTreeMap::new();
166        if version >= 4 {
167            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
168            for _ in 0..num_tagged_fields {
169                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
170                let size: u32 = types::UnsignedVarInt.decode(buf)?;
171                let unknown_value = buf.try_get_bytes(size as usize)?;
172                unknown_tagged_fields.insert(tag as i32, unknown_value);
173            }
174        }
175        Ok(Self {
176            resources,
177            include_synonyms,
178            include_documentation,
179            unknown_tagged_fields,
180        })
181    }
182}
183
184impl Default for DescribeConfigsRequest {
185    fn default() -> Self {
186        Self {
187            resources: Default::default(),
188            include_synonyms: false,
189            include_documentation: false,
190            unknown_tagged_fields: BTreeMap::new(),
191        }
192    }
193}
194
195impl Message for DescribeConfigsRequest {
196    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
197    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
198}
199
200/// Valid versions: 1-4
201#[non_exhaustive]
202#[derive(Debug, Clone, PartialEq)]
203pub struct DescribeConfigsResource {
204    /// The resource type.
205    ///
206    /// Supported API versions: 1-4
207    pub resource_type: i8,
208
209    /// The resource name.
210    ///
211    /// Supported API versions: 1-4
212    pub resource_name: StrBytes,
213
214    /// The configuration keys to list, or null to list all configuration keys.
215    ///
216    /// Supported API versions: 1-4
217    pub configuration_keys: Option<Vec<StrBytes>>,
218
219    /// Other tagged fields
220    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
221}
222
223impl DescribeConfigsResource {
224    /// Sets `resource_type` to the passed value.
225    ///
226    /// The resource type.
227    ///
228    /// Supported API versions: 1-4
229    pub fn with_resource_type(mut self, value: i8) -> Self {
230        self.resource_type = value;
231        self
232    }
233    /// Sets `resource_name` to the passed value.
234    ///
235    /// The resource name.
236    ///
237    /// Supported API versions: 1-4
238    pub fn with_resource_name(mut self, value: StrBytes) -> Self {
239        self.resource_name = value;
240        self
241    }
242    /// Sets `configuration_keys` to the passed value.
243    ///
244    /// The configuration keys to list, or null to list all configuration keys.
245    ///
246    /// Supported API versions: 1-4
247    pub fn with_configuration_keys(mut self, value: Option<Vec<StrBytes>>) -> Self {
248        self.configuration_keys = value;
249        self
250    }
251    /// Sets unknown_tagged_fields to the passed value.
252    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
253        self.unknown_tagged_fields = value;
254        self
255    }
256    /// Inserts an entry into unknown_tagged_fields.
257    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
258        self.unknown_tagged_fields.insert(key, value);
259        self
260    }
261}
262
263#[cfg(feature = "client")]
264impl Encodable for DescribeConfigsResource {
265    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
266        if version < 1 || version > 4 {
267            bail!("specified version not supported by this message type");
268        }
269        types::Int8.encode(buf, &self.resource_type)?;
270        if version >= 4 {
271            types::CompactString.encode(buf, &self.resource_name)?;
272        } else {
273            types::String.encode(buf, &self.resource_name)?;
274        }
275        if version >= 4 {
276            types::CompactArray(types::CompactString).encode(buf, &self.configuration_keys)?;
277        } else {
278            types::Array(types::String).encode(buf, &self.configuration_keys)?;
279        }
280        if version >= 4 {
281            let num_tagged_fields = self.unknown_tagged_fields.len();
282            if num_tagged_fields > std::u32::MAX as usize {
283                bail!(
284                    "Too many tagged fields to encode ({} fields)",
285                    num_tagged_fields
286                );
287            }
288            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
289
290            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
291        }
292        Ok(())
293    }
294    fn compute_size(&self, version: i16) -> Result<usize> {
295        let mut total_size = 0;
296        total_size += types::Int8.compute_size(&self.resource_type)?;
297        if version >= 4 {
298            total_size += types::CompactString.compute_size(&self.resource_name)?;
299        } else {
300            total_size += types::String.compute_size(&self.resource_name)?;
301        }
302        if version >= 4 {
303            total_size +=
304                types::CompactArray(types::CompactString).compute_size(&self.configuration_keys)?;
305        } else {
306            total_size += types::Array(types::String).compute_size(&self.configuration_keys)?;
307        }
308        if version >= 4 {
309            let num_tagged_fields = self.unknown_tagged_fields.len();
310            if num_tagged_fields > std::u32::MAX as usize {
311                bail!(
312                    "Too many tagged fields to encode ({} fields)",
313                    num_tagged_fields
314                );
315            }
316            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
317
318            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
319        }
320        Ok(total_size)
321    }
322}
323
324#[cfg(feature = "broker")]
325impl Decodable for DescribeConfigsResource {
326    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
327        if version < 1 || version > 4 {
328            bail!("specified version not supported by this message type");
329        }
330        let resource_type = types::Int8.decode(buf)?;
331        let resource_name = if version >= 4 {
332            types::CompactString.decode(buf)?
333        } else {
334            types::String.decode(buf)?
335        };
336        let configuration_keys = if version >= 4 {
337            types::CompactArray(types::CompactString).decode(buf)?
338        } else {
339            types::Array(types::String).decode(buf)?
340        };
341        let mut unknown_tagged_fields = BTreeMap::new();
342        if version >= 4 {
343            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
344            for _ in 0..num_tagged_fields {
345                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
346                let size: u32 = types::UnsignedVarInt.decode(buf)?;
347                let unknown_value = buf.try_get_bytes(size as usize)?;
348                unknown_tagged_fields.insert(tag as i32, unknown_value);
349            }
350        }
351        Ok(Self {
352            resource_type,
353            resource_name,
354            configuration_keys,
355            unknown_tagged_fields,
356        })
357    }
358}
359
360impl Default for DescribeConfigsResource {
361    fn default() -> Self {
362        Self {
363            resource_type: 0,
364            resource_name: Default::default(),
365            configuration_keys: Some(Default::default()),
366            unknown_tagged_fields: BTreeMap::new(),
367        }
368    }
369}
370
371impl Message for DescribeConfigsResource {
372    const VERSIONS: VersionRange = VersionRange { min: 1, max: 4 };
373    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
374}
375
376impl HeaderVersion for DescribeConfigsRequest {
377    fn header_version(version: i16) -> i16 {
378        if version >= 4 {
379            2
380        } else {
381            1
382        }
383    }
384}