kafka_protocol/messages/
alter_client_quotas_response.rs

1//! AlterClientQuotasResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/AlterClientQuotasResponse.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 AlterClientQuotasResponse {
24    /// 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.
25    ///
26    /// Supported API versions: 0-1
27    pub throttle_time_ms: i32,
28
29    /// The quota configuration entries to alter.
30    ///
31    /// Supported API versions: 0-1
32    pub entries: Vec<EntryData>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterClientQuotasResponse {
39    /// Sets `throttle_time_ms` to the passed value.
40    ///
41    /// 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.
42    ///
43    /// Supported API versions: 0-1
44    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45        self.throttle_time_ms = value;
46        self
47    }
48    /// Sets `entries` to the passed value.
49    ///
50    /// The quota configuration entries to alter.
51    ///
52    /// Supported API versions: 0-1
53    pub fn with_entries(mut self, value: Vec<EntryData>) -> Self {
54        self.entries = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for AlterClientQuotasResponse {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version < 0 || version > 1 {
73            bail!("specified version not supported by this message type");
74        }
75        types::Int32.encode(buf, &self.throttle_time_ms)?;
76        if version >= 1 {
77            types::CompactArray(types::Struct { version }).encode(buf, &self.entries)?;
78        } else {
79            types::Array(types::Struct { version }).encode(buf, &self.entries)?;
80        }
81        if version >= 1 {
82            let num_tagged_fields = self.unknown_tagged_fields.len();
83            if num_tagged_fields > std::u32::MAX as usize {
84                bail!(
85                    "Too many tagged fields to encode ({} fields)",
86                    num_tagged_fields
87                );
88            }
89            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
90
91            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
92        }
93        Ok(())
94    }
95    fn compute_size(&self, version: i16) -> Result<usize> {
96        let mut total_size = 0;
97        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
98        if version >= 1 {
99            total_size +=
100                types::CompactArray(types::Struct { version }).compute_size(&self.entries)?;
101        } else {
102            total_size += types::Array(types::Struct { version }).compute_size(&self.entries)?;
103        }
104        if version >= 1 {
105            let num_tagged_fields = self.unknown_tagged_fields.len();
106            if num_tagged_fields > std::u32::MAX as usize {
107                bail!(
108                    "Too many tagged fields to encode ({} fields)",
109                    num_tagged_fields
110                );
111            }
112            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
113
114            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
115        }
116        Ok(total_size)
117    }
118}
119
120#[cfg(feature = "client")]
121impl Decodable for AlterClientQuotasResponse {
122    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
123        if version < 0 || version > 1 {
124            bail!("specified version not supported by this message type");
125        }
126        let throttle_time_ms = types::Int32.decode(buf)?;
127        let entries = if version >= 1 {
128            types::CompactArray(types::Struct { version }).decode(buf)?
129        } else {
130            types::Array(types::Struct { version }).decode(buf)?
131        };
132        let mut unknown_tagged_fields = BTreeMap::new();
133        if version >= 1 {
134            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
135            for _ in 0..num_tagged_fields {
136                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
137                let size: u32 = types::UnsignedVarInt.decode(buf)?;
138                let unknown_value = buf.try_get_bytes(size as usize)?;
139                unknown_tagged_fields.insert(tag as i32, unknown_value);
140            }
141        }
142        Ok(Self {
143            throttle_time_ms,
144            entries,
145            unknown_tagged_fields,
146        })
147    }
148}
149
150impl Default for AlterClientQuotasResponse {
151    fn default() -> Self {
152        Self {
153            throttle_time_ms: 0,
154            entries: Default::default(),
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for AlterClientQuotasResponse {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165/// Valid versions: 0-1
166#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct EntityData {
169    /// The entity type.
170    ///
171    /// Supported API versions: 0-1
172    pub entity_type: StrBytes,
173
174    /// The name of the entity, or null if the default.
175    ///
176    /// Supported API versions: 0-1
177    pub entity_name: Option<StrBytes>,
178
179    /// Other tagged fields
180    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
181}
182
183impl EntityData {
184    /// Sets `entity_type` to the passed value.
185    ///
186    /// The entity type.
187    ///
188    /// Supported API versions: 0-1
189    pub fn with_entity_type(mut self, value: StrBytes) -> Self {
190        self.entity_type = value;
191        self
192    }
193    /// Sets `entity_name` to the passed value.
194    ///
195    /// The name of the entity, or null if the default.
196    ///
197    /// Supported API versions: 0-1
198    pub fn with_entity_name(mut self, value: Option<StrBytes>) -> Self {
199        self.entity_name = value;
200        self
201    }
202    /// Sets unknown_tagged_fields to the passed value.
203    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
204        self.unknown_tagged_fields = value;
205        self
206    }
207    /// Inserts an entry into unknown_tagged_fields.
208    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
209        self.unknown_tagged_fields.insert(key, value);
210        self
211    }
212}
213
214#[cfg(feature = "broker")]
215impl Encodable for EntityData {
216    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
217        if version < 0 || version > 1 {
218            bail!("specified version not supported by this message type");
219        }
220        if version >= 1 {
221            types::CompactString.encode(buf, &self.entity_type)?;
222        } else {
223            types::String.encode(buf, &self.entity_type)?;
224        }
225        if version >= 1 {
226            types::CompactString.encode(buf, &self.entity_name)?;
227        } else {
228            types::String.encode(buf, &self.entity_name)?;
229        }
230        if version >= 1 {
231            let num_tagged_fields = self.unknown_tagged_fields.len();
232            if num_tagged_fields > std::u32::MAX as usize {
233                bail!(
234                    "Too many tagged fields to encode ({} fields)",
235                    num_tagged_fields
236                );
237            }
238            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
239
240            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
241        }
242        Ok(())
243    }
244    fn compute_size(&self, version: i16) -> Result<usize> {
245        let mut total_size = 0;
246        if version >= 1 {
247            total_size += types::CompactString.compute_size(&self.entity_type)?;
248        } else {
249            total_size += types::String.compute_size(&self.entity_type)?;
250        }
251        if version >= 1 {
252            total_size += types::CompactString.compute_size(&self.entity_name)?;
253        } else {
254            total_size += types::String.compute_size(&self.entity_name)?;
255        }
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            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
265
266            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
267        }
268        Ok(total_size)
269    }
270}
271
272#[cfg(feature = "client")]
273impl Decodable for EntityData {
274    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
275        if version < 0 || version > 1 {
276            bail!("specified version not supported by this message type");
277        }
278        let entity_type = if version >= 1 {
279            types::CompactString.decode(buf)?
280        } else {
281            types::String.decode(buf)?
282        };
283        let entity_name = if version >= 1 {
284            types::CompactString.decode(buf)?
285        } else {
286            types::String.decode(buf)?
287        };
288        let mut unknown_tagged_fields = BTreeMap::new();
289        if version >= 1 {
290            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
291            for _ in 0..num_tagged_fields {
292                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
293                let size: u32 = types::UnsignedVarInt.decode(buf)?;
294                let unknown_value = buf.try_get_bytes(size as usize)?;
295                unknown_tagged_fields.insert(tag as i32, unknown_value);
296            }
297        }
298        Ok(Self {
299            entity_type,
300            entity_name,
301            unknown_tagged_fields,
302        })
303    }
304}
305
306impl Default for EntityData {
307    fn default() -> Self {
308        Self {
309            entity_type: Default::default(),
310            entity_name: Some(Default::default()),
311            unknown_tagged_fields: BTreeMap::new(),
312        }
313    }
314}
315
316impl Message for EntityData {
317    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
318    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
319}
320
321/// Valid versions: 0-1
322#[non_exhaustive]
323#[derive(Debug, Clone, PartialEq)]
324pub struct EntryData {
325    /// The error code, or `0` if the quota alteration succeeded.
326    ///
327    /// Supported API versions: 0-1
328    pub error_code: i16,
329
330    /// The error message, or `null` if the quota alteration succeeded.
331    ///
332    /// Supported API versions: 0-1
333    pub error_message: Option<StrBytes>,
334
335    /// The quota entity to alter.
336    ///
337    /// Supported API versions: 0-1
338    pub entity: Vec<EntityData>,
339
340    /// Other tagged fields
341    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
342}
343
344impl EntryData {
345    /// Sets `error_code` to the passed value.
346    ///
347    /// The error code, or `0` if the quota alteration succeeded.
348    ///
349    /// Supported API versions: 0-1
350    pub fn with_error_code(mut self, value: i16) -> Self {
351        self.error_code = value;
352        self
353    }
354    /// Sets `error_message` to the passed value.
355    ///
356    /// The error message, or `null` if the quota alteration succeeded.
357    ///
358    /// Supported API versions: 0-1
359    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
360        self.error_message = value;
361        self
362    }
363    /// Sets `entity` to the passed value.
364    ///
365    /// The quota entity to alter.
366    ///
367    /// Supported API versions: 0-1
368    pub fn with_entity(mut self, value: Vec<EntityData>) -> Self {
369        self.entity = value;
370        self
371    }
372    /// Sets unknown_tagged_fields to the passed value.
373    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
374        self.unknown_tagged_fields = value;
375        self
376    }
377    /// Inserts an entry into unknown_tagged_fields.
378    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
379        self.unknown_tagged_fields.insert(key, value);
380        self
381    }
382}
383
384#[cfg(feature = "broker")]
385impl Encodable for EntryData {
386    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
387        if version < 0 || version > 1 {
388            bail!("specified version not supported by this message type");
389        }
390        types::Int16.encode(buf, &self.error_code)?;
391        if version >= 1 {
392            types::CompactString.encode(buf, &self.error_message)?;
393        } else {
394            types::String.encode(buf, &self.error_message)?;
395        }
396        if version >= 1 {
397            types::CompactArray(types::Struct { version }).encode(buf, &self.entity)?;
398        } else {
399            types::Array(types::Struct { version }).encode(buf, &self.entity)?;
400        }
401        if version >= 1 {
402            let num_tagged_fields = self.unknown_tagged_fields.len();
403            if num_tagged_fields > std::u32::MAX as usize {
404                bail!(
405                    "Too many tagged fields to encode ({} fields)",
406                    num_tagged_fields
407                );
408            }
409            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
410
411            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
412        }
413        Ok(())
414    }
415    fn compute_size(&self, version: i16) -> Result<usize> {
416        let mut total_size = 0;
417        total_size += types::Int16.compute_size(&self.error_code)?;
418        if version >= 1 {
419            total_size += types::CompactString.compute_size(&self.error_message)?;
420        } else {
421            total_size += types::String.compute_size(&self.error_message)?;
422        }
423        if version >= 1 {
424            total_size +=
425                types::CompactArray(types::Struct { version }).compute_size(&self.entity)?;
426        } else {
427            total_size += types::Array(types::Struct { version }).compute_size(&self.entity)?;
428        }
429        if version >= 1 {
430            let num_tagged_fields = self.unknown_tagged_fields.len();
431            if num_tagged_fields > std::u32::MAX as usize {
432                bail!(
433                    "Too many tagged fields to encode ({} fields)",
434                    num_tagged_fields
435                );
436            }
437            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
438
439            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
440        }
441        Ok(total_size)
442    }
443}
444
445#[cfg(feature = "client")]
446impl Decodable for EntryData {
447    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
448        if version < 0 || version > 1 {
449            bail!("specified version not supported by this message type");
450        }
451        let error_code = types::Int16.decode(buf)?;
452        let error_message = if version >= 1 {
453            types::CompactString.decode(buf)?
454        } else {
455            types::String.decode(buf)?
456        };
457        let entity = if version >= 1 {
458            types::CompactArray(types::Struct { version }).decode(buf)?
459        } else {
460            types::Array(types::Struct { version }).decode(buf)?
461        };
462        let mut unknown_tagged_fields = BTreeMap::new();
463        if version >= 1 {
464            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
465            for _ in 0..num_tagged_fields {
466                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
467                let size: u32 = types::UnsignedVarInt.decode(buf)?;
468                let unknown_value = buf.try_get_bytes(size as usize)?;
469                unknown_tagged_fields.insert(tag as i32, unknown_value);
470            }
471        }
472        Ok(Self {
473            error_code,
474            error_message,
475            entity,
476            unknown_tagged_fields,
477        })
478    }
479}
480
481impl Default for EntryData {
482    fn default() -> Self {
483        Self {
484            error_code: 0,
485            error_message: Some(Default::default()),
486            entity: Default::default(),
487            unknown_tagged_fields: BTreeMap::new(),
488        }
489    }
490}
491
492impl Message for EntryData {
493    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
494    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
495}
496
497impl HeaderVersion for AlterClientQuotasResponse {
498    fn header_version(version: i16) -> i16 {
499        if version >= 1 {
500            1
501        } else {
502            0
503        }
504    }
505}