kafka_protocol/messages/
describe_client_quotas_request.rs

1//! DescribeClientQuotasRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeClientQuotasRequest.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-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ComponentData {
24    /// The entity type that the filter component applies to.
25    ///
26    /// Supported API versions: 0-1
27    pub entity_type: StrBytes,
28
29    /// How to match the entity {0 = exact name, 1 = default name, 2 = any specified name}.
30    ///
31    /// Supported API versions: 0-1
32    pub match_type: i8,
33
34    /// The string to match against, or null if unused for the match type.
35    ///
36    /// Supported API versions: 0-1
37    pub _match: Option<StrBytes>,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl ComponentData {
44    /// Sets `entity_type` to the passed value.
45    ///
46    /// The entity type that the filter component applies to.
47    ///
48    /// Supported API versions: 0-1
49    pub fn with_entity_type(mut self, value: StrBytes) -> Self {
50        self.entity_type = value;
51        self
52    }
53    /// Sets `match_type` to the passed value.
54    ///
55    /// How to match the entity {0 = exact name, 1 = default name, 2 = any specified name}.
56    ///
57    /// Supported API versions: 0-1
58    pub fn with_match_type(mut self, value: i8) -> Self {
59        self.match_type = value;
60        self
61    }
62    /// Sets `_match` to the passed value.
63    ///
64    /// The string to match against, or null if unused for the match type.
65    ///
66    /// Supported API versions: 0-1
67    pub fn with_match(mut self, value: Option<StrBytes>) -> Self {
68        self._match = 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 ComponentData {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 0 || version > 1 {
87            bail!("specified version not supported by this message type");
88        }
89        if version >= 1 {
90            types::CompactString.encode(buf, &self.entity_type)?;
91        } else {
92            types::String.encode(buf, &self.entity_type)?;
93        }
94        types::Int8.encode(buf, &self.match_type)?;
95        if version >= 1 {
96            types::CompactString.encode(buf, &self._match)?;
97        } else {
98            types::String.encode(buf, &self._match)?;
99        }
100        if version >= 1 {
101            let num_tagged_fields = self.unknown_tagged_fields.len();
102            if num_tagged_fields > std::u32::MAX as usize {
103                bail!(
104                    "Too many tagged fields to encode ({} fields)",
105                    num_tagged_fields
106                );
107            }
108            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
109
110            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
111        }
112        Ok(())
113    }
114    fn compute_size(&self, version: i16) -> Result<usize> {
115        let mut total_size = 0;
116        if version >= 1 {
117            total_size += types::CompactString.compute_size(&self.entity_type)?;
118        } else {
119            total_size += types::String.compute_size(&self.entity_type)?;
120        }
121        total_size += types::Int8.compute_size(&self.match_type)?;
122        if version >= 1 {
123            total_size += types::CompactString.compute_size(&self._match)?;
124        } else {
125            total_size += types::String.compute_size(&self._match)?;
126        }
127        if version >= 1 {
128            let num_tagged_fields = self.unknown_tagged_fields.len();
129            if num_tagged_fields > std::u32::MAX as usize {
130                bail!(
131                    "Too many tagged fields to encode ({} fields)",
132                    num_tagged_fields
133                );
134            }
135            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
136
137            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
138        }
139        Ok(total_size)
140    }
141}
142
143#[cfg(feature = "broker")]
144impl Decodable for ComponentData {
145    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
146        if version < 0 || version > 1 {
147            bail!("specified version not supported by this message type");
148        }
149        let entity_type = if version >= 1 {
150            types::CompactString.decode(buf)?
151        } else {
152            types::String.decode(buf)?
153        };
154        let match_type = types::Int8.decode(buf)?;
155        let _match = if version >= 1 {
156            types::CompactString.decode(buf)?
157        } else {
158            types::String.decode(buf)?
159        };
160        let mut unknown_tagged_fields = BTreeMap::new();
161        if version >= 1 {
162            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
163            for _ in 0..num_tagged_fields {
164                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
165                let size: u32 = types::UnsignedVarInt.decode(buf)?;
166                let unknown_value = buf.try_get_bytes(size as usize)?;
167                unknown_tagged_fields.insert(tag as i32, unknown_value);
168            }
169        }
170        Ok(Self {
171            entity_type,
172            match_type,
173            _match,
174            unknown_tagged_fields,
175        })
176    }
177}
178
179impl Default for ComponentData {
180    fn default() -> Self {
181        Self {
182            entity_type: Default::default(),
183            match_type: 0,
184            _match: Some(Default::default()),
185            unknown_tagged_fields: BTreeMap::new(),
186        }
187    }
188}
189
190impl Message for ComponentData {
191    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
192    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
193}
194
195/// Valid versions: 0-1
196#[non_exhaustive]
197#[derive(Debug, Clone, PartialEq)]
198pub struct DescribeClientQuotasRequest {
199    /// Filter components to apply to quota entities.
200    ///
201    /// Supported API versions: 0-1
202    pub components: Vec<ComponentData>,
203
204    /// Whether the match is strict, i.e. should exclude entities with unspecified entity types.
205    ///
206    /// Supported API versions: 0-1
207    pub strict: bool,
208
209    /// Other tagged fields
210    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
211}
212
213impl DescribeClientQuotasRequest {
214    /// Sets `components` to the passed value.
215    ///
216    /// Filter components to apply to quota entities.
217    ///
218    /// Supported API versions: 0-1
219    pub fn with_components(mut self, value: Vec<ComponentData>) -> Self {
220        self.components = value;
221        self
222    }
223    /// Sets `strict` to the passed value.
224    ///
225    /// Whether the match is strict, i.e. should exclude entities with unspecified entity types.
226    ///
227    /// Supported API versions: 0-1
228    pub fn with_strict(mut self, value: bool) -> Self {
229        self.strict = value;
230        self
231    }
232    /// Sets unknown_tagged_fields to the passed value.
233    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
234        self.unknown_tagged_fields = value;
235        self
236    }
237    /// Inserts an entry into unknown_tagged_fields.
238    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
239        self.unknown_tagged_fields.insert(key, value);
240        self
241    }
242}
243
244#[cfg(feature = "client")]
245impl Encodable for DescribeClientQuotasRequest {
246    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
247        if version < 0 || version > 1 {
248            bail!("specified version not supported by this message type");
249        }
250        if version >= 1 {
251            types::CompactArray(types::Struct { version }).encode(buf, &self.components)?;
252        } else {
253            types::Array(types::Struct { version }).encode(buf, &self.components)?;
254        }
255        types::Boolean.encode(buf, &self.strict)?;
256        if version >= 1 {
257            let num_tagged_fields = self.unknown_tagged_fields.len();
258            if num_tagged_fields > std::u32::MAX as usize {
259                bail!(
260                    "Too many tagged fields to encode ({} fields)",
261                    num_tagged_fields
262                );
263            }
264            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
265
266            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
267        }
268        Ok(())
269    }
270    fn compute_size(&self, version: i16) -> Result<usize> {
271        let mut total_size = 0;
272        if version >= 1 {
273            total_size +=
274                types::CompactArray(types::Struct { version }).compute_size(&self.components)?;
275        } else {
276            total_size += types::Array(types::Struct { version }).compute_size(&self.components)?;
277        }
278        total_size += types::Boolean.compute_size(&self.strict)?;
279        if version >= 1 {
280            let num_tagged_fields = self.unknown_tagged_fields.len();
281            if num_tagged_fields > std::u32::MAX as usize {
282                bail!(
283                    "Too many tagged fields to encode ({} fields)",
284                    num_tagged_fields
285                );
286            }
287            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
288
289            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
290        }
291        Ok(total_size)
292    }
293}
294
295#[cfg(feature = "broker")]
296impl Decodable for DescribeClientQuotasRequest {
297    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
298        if version < 0 || version > 1 {
299            bail!("specified version not supported by this message type");
300        }
301        let components = if version >= 1 {
302            types::CompactArray(types::Struct { version }).decode(buf)?
303        } else {
304            types::Array(types::Struct { version }).decode(buf)?
305        };
306        let strict = types::Boolean.decode(buf)?;
307        let mut unknown_tagged_fields = BTreeMap::new();
308        if version >= 1 {
309            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
310            for _ in 0..num_tagged_fields {
311                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
312                let size: u32 = types::UnsignedVarInt.decode(buf)?;
313                let unknown_value = buf.try_get_bytes(size as usize)?;
314                unknown_tagged_fields.insert(tag as i32, unknown_value);
315            }
316        }
317        Ok(Self {
318            components,
319            strict,
320            unknown_tagged_fields,
321        })
322    }
323}
324
325impl Default for DescribeClientQuotasRequest {
326    fn default() -> Self {
327        Self {
328            components: Default::default(),
329            strict: false,
330            unknown_tagged_fields: BTreeMap::new(),
331        }
332    }
333}
334
335impl Message for DescribeClientQuotasRequest {
336    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
337    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
338}
339
340impl HeaderVersion for DescribeClientQuotasRequest {
341    fn header_version(version: i16) -> i16 {
342        if version >= 1 {
343            2
344        } else {
345            1
346        }
347    }
348}