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 >= 1 {
87            types::CompactString.encode(buf, &self.entity_type)?;
88        } else {
89            types::String.encode(buf, &self.entity_type)?;
90        }
91        types::Int8.encode(buf, &self.match_type)?;
92        if version >= 1 {
93            types::CompactString.encode(buf, &self._match)?;
94        } else {
95            types::String.encode(buf, &self._match)?;
96        }
97        if version >= 1 {
98            let num_tagged_fields = self.unknown_tagged_fields.len();
99            if num_tagged_fields > std::u32::MAX as usize {
100                bail!(
101                    "Too many tagged fields to encode ({} fields)",
102                    num_tagged_fields
103                );
104            }
105            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
106
107            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
108        }
109        Ok(())
110    }
111    fn compute_size(&self, version: i16) -> Result<usize> {
112        let mut total_size = 0;
113        if version >= 1 {
114            total_size += types::CompactString.compute_size(&self.entity_type)?;
115        } else {
116            total_size += types::String.compute_size(&self.entity_type)?;
117        }
118        total_size += types::Int8.compute_size(&self.match_type)?;
119        if version >= 1 {
120            total_size += types::CompactString.compute_size(&self._match)?;
121        } else {
122            total_size += types::String.compute_size(&self._match)?;
123        }
124        if version >= 1 {
125            let num_tagged_fields = self.unknown_tagged_fields.len();
126            if num_tagged_fields > std::u32::MAX as usize {
127                bail!(
128                    "Too many tagged fields to encode ({} fields)",
129                    num_tagged_fields
130                );
131            }
132            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
133
134            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
135        }
136        Ok(total_size)
137    }
138}
139
140#[cfg(feature = "broker")]
141impl Decodable for ComponentData {
142    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
143        let entity_type = if version >= 1 {
144            types::CompactString.decode(buf)?
145        } else {
146            types::String.decode(buf)?
147        };
148        let match_type = types::Int8.decode(buf)?;
149        let _match = if version >= 1 {
150            types::CompactString.decode(buf)?
151        } else {
152            types::String.decode(buf)?
153        };
154        let mut unknown_tagged_fields = BTreeMap::new();
155        if version >= 1 {
156            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
157            for _ in 0..num_tagged_fields {
158                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
159                let size: u32 = types::UnsignedVarInt.decode(buf)?;
160                let unknown_value = buf.try_get_bytes(size as usize)?;
161                unknown_tagged_fields.insert(tag as i32, unknown_value);
162            }
163        }
164        Ok(Self {
165            entity_type,
166            match_type,
167            _match,
168            unknown_tagged_fields,
169        })
170    }
171}
172
173impl Default for ComponentData {
174    fn default() -> Self {
175        Self {
176            entity_type: Default::default(),
177            match_type: 0,
178            _match: Some(Default::default()),
179            unknown_tagged_fields: BTreeMap::new(),
180        }
181    }
182}
183
184impl Message for ComponentData {
185    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
186    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
187}
188
189/// Valid versions: 0-1
190#[non_exhaustive]
191#[derive(Debug, Clone, PartialEq)]
192pub struct DescribeClientQuotasRequest {
193    /// Filter components to apply to quota entities.
194    ///
195    /// Supported API versions: 0-1
196    pub components: Vec<ComponentData>,
197
198    /// Whether the match is strict, i.e. should exclude entities with unspecified entity types.
199    ///
200    /// Supported API versions: 0-1
201    pub strict: bool,
202
203    /// Other tagged fields
204    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
205}
206
207impl DescribeClientQuotasRequest {
208    /// Sets `components` to the passed value.
209    ///
210    /// Filter components to apply to quota entities.
211    ///
212    /// Supported API versions: 0-1
213    pub fn with_components(mut self, value: Vec<ComponentData>) -> Self {
214        self.components = value;
215        self
216    }
217    /// Sets `strict` to the passed value.
218    ///
219    /// Whether the match is strict, i.e. should exclude entities with unspecified entity types.
220    ///
221    /// Supported API versions: 0-1
222    pub fn with_strict(mut self, value: bool) -> Self {
223        self.strict = value;
224        self
225    }
226    /// Sets unknown_tagged_fields to the passed value.
227    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
228        self.unknown_tagged_fields = value;
229        self
230    }
231    /// Inserts an entry into unknown_tagged_fields.
232    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
233        self.unknown_tagged_fields.insert(key, value);
234        self
235    }
236}
237
238#[cfg(feature = "client")]
239impl Encodable for DescribeClientQuotasRequest {
240    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
241        if version >= 1 {
242            types::CompactArray(types::Struct { version }).encode(buf, &self.components)?;
243        } else {
244            types::Array(types::Struct { version }).encode(buf, &self.components)?;
245        }
246        types::Boolean.encode(buf, &self.strict)?;
247        if version >= 1 {
248            let num_tagged_fields = self.unknown_tagged_fields.len();
249            if num_tagged_fields > std::u32::MAX as usize {
250                bail!(
251                    "Too many tagged fields to encode ({} fields)",
252                    num_tagged_fields
253                );
254            }
255            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
256
257            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
258        }
259        Ok(())
260    }
261    fn compute_size(&self, version: i16) -> Result<usize> {
262        let mut total_size = 0;
263        if version >= 1 {
264            total_size +=
265                types::CompactArray(types::Struct { version }).compute_size(&self.components)?;
266        } else {
267            total_size += types::Array(types::Struct { version }).compute_size(&self.components)?;
268        }
269        total_size += types::Boolean.compute_size(&self.strict)?;
270        if version >= 1 {
271            let num_tagged_fields = self.unknown_tagged_fields.len();
272            if num_tagged_fields > std::u32::MAX as usize {
273                bail!(
274                    "Too many tagged fields to encode ({} fields)",
275                    num_tagged_fields
276                );
277            }
278            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
279
280            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
281        }
282        Ok(total_size)
283    }
284}
285
286#[cfg(feature = "broker")]
287impl Decodable for DescribeClientQuotasRequest {
288    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
289        let components = if version >= 1 {
290            types::CompactArray(types::Struct { version }).decode(buf)?
291        } else {
292            types::Array(types::Struct { version }).decode(buf)?
293        };
294        let strict = types::Boolean.decode(buf)?;
295        let mut unknown_tagged_fields = BTreeMap::new();
296        if version >= 1 {
297            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
298            for _ in 0..num_tagged_fields {
299                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
300                let size: u32 = types::UnsignedVarInt.decode(buf)?;
301                let unknown_value = buf.try_get_bytes(size as usize)?;
302                unknown_tagged_fields.insert(tag as i32, unknown_value);
303            }
304        }
305        Ok(Self {
306            components,
307            strict,
308            unknown_tagged_fields,
309        })
310    }
311}
312
313impl Default for DescribeClientQuotasRequest {
314    fn default() -> Self {
315        Self {
316            components: Default::default(),
317            strict: false,
318            unknown_tagged_fields: BTreeMap::new(),
319        }
320    }
321}
322
323impl Message for DescribeClientQuotasRequest {
324    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
325    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
326}
327
328impl HeaderVersion for DescribeClientQuotasRequest {
329    fn header_version(version: i16) -> i16 {
330        if version >= 1 {
331            2
332        } else {
333            1
334        }
335    }
336}