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: 0-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: 0-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: 0-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 < 0 || 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        if version >= 1 {
95            types::Boolean.encode(buf, &self.include_synonyms)?;
96        } else {
97            if self.include_synonyms {
98                bail!("A field is set that is not available on the selected protocol version");
99            }
100        }
101        if version >= 3 {
102            types::Boolean.encode(buf, &self.include_documentation)?;
103        } else {
104            if self.include_documentation {
105                bail!("A field is set that is not available on the selected protocol version");
106            }
107        }
108        if version >= 4 {
109            let num_tagged_fields = self.unknown_tagged_fields.len();
110            if num_tagged_fields > std::u32::MAX as usize {
111                bail!(
112                    "Too many tagged fields to encode ({} fields)",
113                    num_tagged_fields
114                );
115            }
116            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
117
118            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
119        }
120        Ok(())
121    }
122    fn compute_size(&self, version: i16) -> Result<usize> {
123        let mut total_size = 0;
124        if version >= 4 {
125            total_size +=
126                types::CompactArray(types::Struct { version }).compute_size(&self.resources)?;
127        } else {
128            total_size += types::Array(types::Struct { version }).compute_size(&self.resources)?;
129        }
130        if version >= 1 {
131            total_size += types::Boolean.compute_size(&self.include_synonyms)?;
132        } else {
133            if self.include_synonyms {
134                bail!("A field is set that is not available on the selected protocol version");
135            }
136        }
137        if version >= 3 {
138            total_size += types::Boolean.compute_size(&self.include_documentation)?;
139        } else {
140            if self.include_documentation {
141                bail!("A field is set that is not available on the selected protocol version");
142            }
143        }
144        if version >= 4 {
145            let num_tagged_fields = self.unknown_tagged_fields.len();
146            if num_tagged_fields > std::u32::MAX as usize {
147                bail!(
148                    "Too many tagged fields to encode ({} fields)",
149                    num_tagged_fields
150                );
151            }
152            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
153
154            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
155        }
156        Ok(total_size)
157    }
158}
159
160#[cfg(feature = "broker")]
161impl Decodable for DescribeConfigsRequest {
162    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
163        if version < 0 || version > 4 {
164            bail!("specified version not supported by this message type");
165        }
166        let resources = if version >= 4 {
167            types::CompactArray(types::Struct { version }).decode(buf)?
168        } else {
169            types::Array(types::Struct { version }).decode(buf)?
170        };
171        let include_synonyms = if version >= 1 {
172            types::Boolean.decode(buf)?
173        } else {
174            false
175        };
176        let include_documentation = if version >= 3 {
177            types::Boolean.decode(buf)?
178        } else {
179            false
180        };
181        let mut unknown_tagged_fields = BTreeMap::new();
182        if version >= 4 {
183            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
184            for _ in 0..num_tagged_fields {
185                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
186                let size: u32 = types::UnsignedVarInt.decode(buf)?;
187                let unknown_value = buf.try_get_bytes(size as usize)?;
188                unknown_tagged_fields.insert(tag as i32, unknown_value);
189            }
190        }
191        Ok(Self {
192            resources,
193            include_synonyms,
194            include_documentation,
195            unknown_tagged_fields,
196        })
197    }
198}
199
200impl Default for DescribeConfigsRequest {
201    fn default() -> Self {
202        Self {
203            resources: Default::default(),
204            include_synonyms: false,
205            include_documentation: false,
206            unknown_tagged_fields: BTreeMap::new(),
207        }
208    }
209}
210
211impl Message for DescribeConfigsRequest {
212    const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
213    const DEPRECATED_VERSIONS: Option<VersionRange> = Some(VersionRange { min: 0, max: 0 });
214}
215
216/// Valid versions: 0-4
217#[non_exhaustive]
218#[derive(Debug, Clone, PartialEq)]
219pub struct DescribeConfigsResource {
220    /// The resource type.
221    ///
222    /// Supported API versions: 0-4
223    pub resource_type: i8,
224
225    /// The resource name.
226    ///
227    /// Supported API versions: 0-4
228    pub resource_name: StrBytes,
229
230    /// The configuration keys to list, or null to list all configuration keys.
231    ///
232    /// Supported API versions: 0-4
233    pub configuration_keys: Option<Vec<StrBytes>>,
234
235    /// Other tagged fields
236    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
237}
238
239impl DescribeConfigsResource {
240    /// Sets `resource_type` to the passed value.
241    ///
242    /// The resource type.
243    ///
244    /// Supported API versions: 0-4
245    pub fn with_resource_type(mut self, value: i8) -> Self {
246        self.resource_type = value;
247        self
248    }
249    /// Sets `resource_name` to the passed value.
250    ///
251    /// The resource name.
252    ///
253    /// Supported API versions: 0-4
254    pub fn with_resource_name(mut self, value: StrBytes) -> Self {
255        self.resource_name = value;
256        self
257    }
258    /// Sets `configuration_keys` to the passed value.
259    ///
260    /// The configuration keys to list, or null to list all configuration keys.
261    ///
262    /// Supported API versions: 0-4
263    pub fn with_configuration_keys(mut self, value: Option<Vec<StrBytes>>) -> Self {
264        self.configuration_keys = value;
265        self
266    }
267    /// Sets unknown_tagged_fields to the passed value.
268    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
269        self.unknown_tagged_fields = value;
270        self
271    }
272    /// Inserts an entry into unknown_tagged_fields.
273    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
274        self.unknown_tagged_fields.insert(key, value);
275        self
276    }
277}
278
279#[cfg(feature = "client")]
280impl Encodable for DescribeConfigsResource {
281    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
282        if version < 0 || version > 4 {
283            bail!("specified version not supported by this message type");
284        }
285        types::Int8.encode(buf, &self.resource_type)?;
286        if version >= 4 {
287            types::CompactString.encode(buf, &self.resource_name)?;
288        } else {
289            types::String.encode(buf, &self.resource_name)?;
290        }
291        if version >= 4 {
292            types::CompactArray(types::CompactString).encode(buf, &self.configuration_keys)?;
293        } else {
294            types::Array(types::String).encode(buf, &self.configuration_keys)?;
295        }
296        if version >= 4 {
297            let num_tagged_fields = self.unknown_tagged_fields.len();
298            if num_tagged_fields > std::u32::MAX as usize {
299                bail!(
300                    "Too many tagged fields to encode ({} fields)",
301                    num_tagged_fields
302                );
303            }
304            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
305
306            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
307        }
308        Ok(())
309    }
310    fn compute_size(&self, version: i16) -> Result<usize> {
311        let mut total_size = 0;
312        total_size += types::Int8.compute_size(&self.resource_type)?;
313        if version >= 4 {
314            total_size += types::CompactString.compute_size(&self.resource_name)?;
315        } else {
316            total_size += types::String.compute_size(&self.resource_name)?;
317        }
318        if version >= 4 {
319            total_size +=
320                types::CompactArray(types::CompactString).compute_size(&self.configuration_keys)?;
321        } else {
322            total_size += types::Array(types::String).compute_size(&self.configuration_keys)?;
323        }
324        if version >= 4 {
325            let num_tagged_fields = self.unknown_tagged_fields.len();
326            if num_tagged_fields > std::u32::MAX as usize {
327                bail!(
328                    "Too many tagged fields to encode ({} fields)",
329                    num_tagged_fields
330                );
331            }
332            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
333
334            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
335        }
336        Ok(total_size)
337    }
338}
339
340#[cfg(feature = "broker")]
341impl Decodable for DescribeConfigsResource {
342    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
343        if version < 0 || version > 4 {
344            bail!("specified version not supported by this message type");
345        }
346        let resource_type = types::Int8.decode(buf)?;
347        let resource_name = if version >= 4 {
348            types::CompactString.decode(buf)?
349        } else {
350            types::String.decode(buf)?
351        };
352        let configuration_keys = if version >= 4 {
353            types::CompactArray(types::CompactString).decode(buf)?
354        } else {
355            types::Array(types::String).decode(buf)?
356        };
357        let mut unknown_tagged_fields = BTreeMap::new();
358        if version >= 4 {
359            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
360            for _ in 0..num_tagged_fields {
361                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
362                let size: u32 = types::UnsignedVarInt.decode(buf)?;
363                let unknown_value = buf.try_get_bytes(size as usize)?;
364                unknown_tagged_fields.insert(tag as i32, unknown_value);
365            }
366        }
367        Ok(Self {
368            resource_type,
369            resource_name,
370            configuration_keys,
371            unknown_tagged_fields,
372        })
373    }
374}
375
376impl Default for DescribeConfigsResource {
377    fn default() -> Self {
378        Self {
379            resource_type: 0,
380            resource_name: Default::default(),
381            configuration_keys: Some(Default::default()),
382            unknown_tagged_fields: BTreeMap::new(),
383        }
384    }
385}
386
387impl Message for DescribeConfigsResource {
388    const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
389    const DEPRECATED_VERSIONS: Option<VersionRange> = Some(VersionRange { min: 0, max: 0 });
390}
391
392impl HeaderVersion for DescribeConfigsRequest {
393    fn header_version(version: i16) -> i16 {
394        if version >= 4 {
395            2
396        } else {
397            1
398        }
399    }
400}