kafka_protocol/messages/
describe_acls_response.rs

1//! DescribeAclsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeAclsResponse.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-3
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AclDescription {
24    /// The ACL principal.
25    ///
26    /// Supported API versions: 1-3
27    pub principal: StrBytes,
28
29    /// The ACL host.
30    ///
31    /// Supported API versions: 1-3
32    pub host: StrBytes,
33
34    /// The ACL operation.
35    ///
36    /// Supported API versions: 1-3
37    pub operation: i8,
38
39    /// The ACL permission type.
40    ///
41    /// Supported API versions: 1-3
42    pub permission_type: i8,
43
44    /// Other tagged fields
45    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl AclDescription {
49    /// Sets `principal` to the passed value.
50    ///
51    /// The ACL principal.
52    ///
53    /// Supported API versions: 1-3
54    pub fn with_principal(mut self, value: StrBytes) -> Self {
55        self.principal = value;
56        self
57    }
58    /// Sets `host` to the passed value.
59    ///
60    /// The ACL host.
61    ///
62    /// Supported API versions: 1-3
63    pub fn with_host(mut self, value: StrBytes) -> Self {
64        self.host = value;
65        self
66    }
67    /// Sets `operation` to the passed value.
68    ///
69    /// The ACL operation.
70    ///
71    /// Supported API versions: 1-3
72    pub fn with_operation(mut self, value: i8) -> Self {
73        self.operation = value;
74        self
75    }
76    /// Sets `permission_type` to the passed value.
77    ///
78    /// The ACL permission type.
79    ///
80    /// Supported API versions: 1-3
81    pub fn with_permission_type(mut self, value: i8) -> Self {
82        self.permission_type = value;
83        self
84    }
85    /// Sets unknown_tagged_fields to the passed value.
86    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87        self.unknown_tagged_fields = value;
88        self
89    }
90    /// Inserts an entry into unknown_tagged_fields.
91    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92        self.unknown_tagged_fields.insert(key, value);
93        self
94    }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for AclDescription {
99    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100        if version < 1 || version > 3 {
101            bail!("specified version not supported by this message type");
102        }
103        if version >= 2 {
104            types::CompactString.encode(buf, &self.principal)?;
105        } else {
106            types::String.encode(buf, &self.principal)?;
107        }
108        if version >= 2 {
109            types::CompactString.encode(buf, &self.host)?;
110        } else {
111            types::String.encode(buf, &self.host)?;
112        }
113        types::Int8.encode(buf, &self.operation)?;
114        types::Int8.encode(buf, &self.permission_type)?;
115        if version >= 2 {
116            let num_tagged_fields = self.unknown_tagged_fields.len();
117            if num_tagged_fields > std::u32::MAX as usize {
118                bail!(
119                    "Too many tagged fields to encode ({} fields)",
120                    num_tagged_fields
121                );
122            }
123            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
124
125            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
126        }
127        Ok(())
128    }
129    fn compute_size(&self, version: i16) -> Result<usize> {
130        let mut total_size = 0;
131        if version >= 2 {
132            total_size += types::CompactString.compute_size(&self.principal)?;
133        } else {
134            total_size += types::String.compute_size(&self.principal)?;
135        }
136        if version >= 2 {
137            total_size += types::CompactString.compute_size(&self.host)?;
138        } else {
139            total_size += types::String.compute_size(&self.host)?;
140        }
141        total_size += types::Int8.compute_size(&self.operation)?;
142        total_size += types::Int8.compute_size(&self.permission_type)?;
143        if version >= 2 {
144            let num_tagged_fields = self.unknown_tagged_fields.len();
145            if num_tagged_fields > std::u32::MAX as usize {
146                bail!(
147                    "Too many tagged fields to encode ({} fields)",
148                    num_tagged_fields
149                );
150            }
151            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
152
153            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
154        }
155        Ok(total_size)
156    }
157}
158
159#[cfg(feature = "client")]
160impl Decodable for AclDescription {
161    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
162        if version < 1 || version > 3 {
163            bail!("specified version not supported by this message type");
164        }
165        let principal = if version >= 2 {
166            types::CompactString.decode(buf)?
167        } else {
168            types::String.decode(buf)?
169        };
170        let host = if version >= 2 {
171            types::CompactString.decode(buf)?
172        } else {
173            types::String.decode(buf)?
174        };
175        let operation = types::Int8.decode(buf)?;
176        let permission_type = types::Int8.decode(buf)?;
177        let mut unknown_tagged_fields = BTreeMap::new();
178        if version >= 2 {
179            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
180            for _ in 0..num_tagged_fields {
181                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
182                let size: u32 = types::UnsignedVarInt.decode(buf)?;
183                let unknown_value = buf.try_get_bytes(size as usize)?;
184                unknown_tagged_fields.insert(tag as i32, unknown_value);
185            }
186        }
187        Ok(Self {
188            principal,
189            host,
190            operation,
191            permission_type,
192            unknown_tagged_fields,
193        })
194    }
195}
196
197impl Default for AclDescription {
198    fn default() -> Self {
199        Self {
200            principal: Default::default(),
201            host: Default::default(),
202            operation: 0,
203            permission_type: 0,
204            unknown_tagged_fields: BTreeMap::new(),
205        }
206    }
207}
208
209impl Message for AclDescription {
210    const VERSIONS: VersionRange = VersionRange { min: 1, max: 3 };
211    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
212}
213
214/// Valid versions: 1-3
215#[non_exhaustive]
216#[derive(Debug, Clone, PartialEq)]
217pub struct DescribeAclsResource {
218    /// The resource type.
219    ///
220    /// Supported API versions: 1-3
221    pub resource_type: i8,
222
223    /// The resource name.
224    ///
225    /// Supported API versions: 1-3
226    pub resource_name: StrBytes,
227
228    /// The resource pattern type.
229    ///
230    /// Supported API versions: 1-3
231    pub pattern_type: i8,
232
233    /// The ACLs.
234    ///
235    /// Supported API versions: 1-3
236    pub acls: Vec<AclDescription>,
237
238    /// Other tagged fields
239    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
240}
241
242impl DescribeAclsResource {
243    /// Sets `resource_type` to the passed value.
244    ///
245    /// The resource type.
246    ///
247    /// Supported API versions: 1-3
248    pub fn with_resource_type(mut self, value: i8) -> Self {
249        self.resource_type = value;
250        self
251    }
252    /// Sets `resource_name` to the passed value.
253    ///
254    /// The resource name.
255    ///
256    /// Supported API versions: 1-3
257    pub fn with_resource_name(mut self, value: StrBytes) -> Self {
258        self.resource_name = value;
259        self
260    }
261    /// Sets `pattern_type` to the passed value.
262    ///
263    /// The resource pattern type.
264    ///
265    /// Supported API versions: 1-3
266    pub fn with_pattern_type(mut self, value: i8) -> Self {
267        self.pattern_type = value;
268        self
269    }
270    /// Sets `acls` to the passed value.
271    ///
272    /// The ACLs.
273    ///
274    /// Supported API versions: 1-3
275    pub fn with_acls(mut self, value: Vec<AclDescription>) -> Self {
276        self.acls = value;
277        self
278    }
279    /// Sets unknown_tagged_fields to the passed value.
280    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
281        self.unknown_tagged_fields = value;
282        self
283    }
284    /// Inserts an entry into unknown_tagged_fields.
285    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
286        self.unknown_tagged_fields.insert(key, value);
287        self
288    }
289}
290
291#[cfg(feature = "broker")]
292impl Encodable for DescribeAclsResource {
293    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
294        if version < 1 || version > 3 {
295            bail!("specified version not supported by this message type");
296        }
297        types::Int8.encode(buf, &self.resource_type)?;
298        if version >= 2 {
299            types::CompactString.encode(buf, &self.resource_name)?;
300        } else {
301            types::String.encode(buf, &self.resource_name)?;
302        }
303        types::Int8.encode(buf, &self.pattern_type)?;
304        if version >= 2 {
305            types::CompactArray(types::Struct { version }).encode(buf, &self.acls)?;
306        } else {
307            types::Array(types::Struct { version }).encode(buf, &self.acls)?;
308        }
309        if version >= 2 {
310            let num_tagged_fields = self.unknown_tagged_fields.len();
311            if num_tagged_fields > std::u32::MAX as usize {
312                bail!(
313                    "Too many tagged fields to encode ({} fields)",
314                    num_tagged_fields
315                );
316            }
317            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
318
319            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
320        }
321        Ok(())
322    }
323    fn compute_size(&self, version: i16) -> Result<usize> {
324        let mut total_size = 0;
325        total_size += types::Int8.compute_size(&self.resource_type)?;
326        if version >= 2 {
327            total_size += types::CompactString.compute_size(&self.resource_name)?;
328        } else {
329            total_size += types::String.compute_size(&self.resource_name)?;
330        }
331        total_size += types::Int8.compute_size(&self.pattern_type)?;
332        if version >= 2 {
333            total_size +=
334                types::CompactArray(types::Struct { version }).compute_size(&self.acls)?;
335        } else {
336            total_size += types::Array(types::Struct { version }).compute_size(&self.acls)?;
337        }
338        if version >= 2 {
339            let num_tagged_fields = self.unknown_tagged_fields.len();
340            if num_tagged_fields > std::u32::MAX as usize {
341                bail!(
342                    "Too many tagged fields to encode ({} fields)",
343                    num_tagged_fields
344                );
345            }
346            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
347
348            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
349        }
350        Ok(total_size)
351    }
352}
353
354#[cfg(feature = "client")]
355impl Decodable for DescribeAclsResource {
356    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
357        if version < 1 || version > 3 {
358            bail!("specified version not supported by this message type");
359        }
360        let resource_type = types::Int8.decode(buf)?;
361        let resource_name = if version >= 2 {
362            types::CompactString.decode(buf)?
363        } else {
364            types::String.decode(buf)?
365        };
366        let pattern_type = types::Int8.decode(buf)?;
367        let acls = if version >= 2 {
368            types::CompactArray(types::Struct { version }).decode(buf)?
369        } else {
370            types::Array(types::Struct { version }).decode(buf)?
371        };
372        let mut unknown_tagged_fields = BTreeMap::new();
373        if version >= 2 {
374            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
375            for _ in 0..num_tagged_fields {
376                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
377                let size: u32 = types::UnsignedVarInt.decode(buf)?;
378                let unknown_value = buf.try_get_bytes(size as usize)?;
379                unknown_tagged_fields.insert(tag as i32, unknown_value);
380            }
381        }
382        Ok(Self {
383            resource_type,
384            resource_name,
385            pattern_type,
386            acls,
387            unknown_tagged_fields,
388        })
389    }
390}
391
392impl Default for DescribeAclsResource {
393    fn default() -> Self {
394        Self {
395            resource_type: 0,
396            resource_name: Default::default(),
397            pattern_type: 3,
398            acls: Default::default(),
399            unknown_tagged_fields: BTreeMap::new(),
400        }
401    }
402}
403
404impl Message for DescribeAclsResource {
405    const VERSIONS: VersionRange = VersionRange { min: 1, max: 3 };
406    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
407}
408
409/// Valid versions: 1-3
410#[non_exhaustive]
411#[derive(Debug, Clone, PartialEq)]
412pub struct DescribeAclsResponse {
413    /// 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.
414    ///
415    /// Supported API versions: 1-3
416    pub throttle_time_ms: i32,
417
418    /// The error code, or 0 if there was no error.
419    ///
420    /// Supported API versions: 1-3
421    pub error_code: i16,
422
423    /// The error message, or null if there was no error.
424    ///
425    /// Supported API versions: 1-3
426    pub error_message: Option<StrBytes>,
427
428    /// Each Resource that is referenced in an ACL.
429    ///
430    /// Supported API versions: 1-3
431    pub resources: Vec<DescribeAclsResource>,
432
433    /// Other tagged fields
434    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
435}
436
437impl DescribeAclsResponse {
438    /// Sets `throttle_time_ms` to the passed value.
439    ///
440    /// 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.
441    ///
442    /// Supported API versions: 1-3
443    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
444        self.throttle_time_ms = value;
445        self
446    }
447    /// Sets `error_code` to the passed value.
448    ///
449    /// The error code, or 0 if there was no error.
450    ///
451    /// Supported API versions: 1-3
452    pub fn with_error_code(mut self, value: i16) -> Self {
453        self.error_code = value;
454        self
455    }
456    /// Sets `error_message` to the passed value.
457    ///
458    /// The error message, or null if there was no error.
459    ///
460    /// Supported API versions: 1-3
461    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
462        self.error_message = value;
463        self
464    }
465    /// Sets `resources` to the passed value.
466    ///
467    /// Each Resource that is referenced in an ACL.
468    ///
469    /// Supported API versions: 1-3
470    pub fn with_resources(mut self, value: Vec<DescribeAclsResource>) -> Self {
471        self.resources = value;
472        self
473    }
474    /// Sets unknown_tagged_fields to the passed value.
475    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
476        self.unknown_tagged_fields = value;
477        self
478    }
479    /// Inserts an entry into unknown_tagged_fields.
480    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
481        self.unknown_tagged_fields.insert(key, value);
482        self
483    }
484}
485
486#[cfg(feature = "broker")]
487impl Encodable for DescribeAclsResponse {
488    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
489        if version < 1 || version > 3 {
490            bail!("specified version not supported by this message type");
491        }
492        types::Int32.encode(buf, &self.throttle_time_ms)?;
493        types::Int16.encode(buf, &self.error_code)?;
494        if version >= 2 {
495            types::CompactString.encode(buf, &self.error_message)?;
496        } else {
497            types::String.encode(buf, &self.error_message)?;
498        }
499        if version >= 2 {
500            types::CompactArray(types::Struct { version }).encode(buf, &self.resources)?;
501        } else {
502            types::Array(types::Struct { version }).encode(buf, &self.resources)?;
503        }
504        if version >= 2 {
505            let num_tagged_fields = self.unknown_tagged_fields.len();
506            if num_tagged_fields > std::u32::MAX as usize {
507                bail!(
508                    "Too many tagged fields to encode ({} fields)",
509                    num_tagged_fields
510                );
511            }
512            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
513
514            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
515        }
516        Ok(())
517    }
518    fn compute_size(&self, version: i16) -> Result<usize> {
519        let mut total_size = 0;
520        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
521        total_size += types::Int16.compute_size(&self.error_code)?;
522        if version >= 2 {
523            total_size += types::CompactString.compute_size(&self.error_message)?;
524        } else {
525            total_size += types::String.compute_size(&self.error_message)?;
526        }
527        if version >= 2 {
528            total_size +=
529                types::CompactArray(types::Struct { version }).compute_size(&self.resources)?;
530        } else {
531            total_size += types::Array(types::Struct { version }).compute_size(&self.resources)?;
532        }
533        if version >= 2 {
534            let num_tagged_fields = self.unknown_tagged_fields.len();
535            if num_tagged_fields > std::u32::MAX as usize {
536                bail!(
537                    "Too many tagged fields to encode ({} fields)",
538                    num_tagged_fields
539                );
540            }
541            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
542
543            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
544        }
545        Ok(total_size)
546    }
547}
548
549#[cfg(feature = "client")]
550impl Decodable for DescribeAclsResponse {
551    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
552        if version < 1 || version > 3 {
553            bail!("specified version not supported by this message type");
554        }
555        let throttle_time_ms = types::Int32.decode(buf)?;
556        let error_code = types::Int16.decode(buf)?;
557        let error_message = if version >= 2 {
558            types::CompactString.decode(buf)?
559        } else {
560            types::String.decode(buf)?
561        };
562        let resources = if version >= 2 {
563            types::CompactArray(types::Struct { version }).decode(buf)?
564        } else {
565            types::Array(types::Struct { version }).decode(buf)?
566        };
567        let mut unknown_tagged_fields = BTreeMap::new();
568        if version >= 2 {
569            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
570            for _ in 0..num_tagged_fields {
571                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
572                let size: u32 = types::UnsignedVarInt.decode(buf)?;
573                let unknown_value = buf.try_get_bytes(size as usize)?;
574                unknown_tagged_fields.insert(tag as i32, unknown_value);
575            }
576        }
577        Ok(Self {
578            throttle_time_ms,
579            error_code,
580            error_message,
581            resources,
582            unknown_tagged_fields,
583        })
584    }
585}
586
587impl Default for DescribeAclsResponse {
588    fn default() -> Self {
589        Self {
590            throttle_time_ms: 0,
591            error_code: 0,
592            error_message: Some(Default::default()),
593            resources: Default::default(),
594            unknown_tagged_fields: BTreeMap::new(),
595        }
596    }
597}
598
599impl Message for DescribeAclsResponse {
600    const VERSIONS: VersionRange = VersionRange { min: 1, max: 3 };
601    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
602}
603
604impl HeaderVersion for DescribeAclsResponse {
605    fn header_version(version: i16) -> i16 {
606        if version >= 2 {
607            1
608        } else {
609            0
610        }
611    }
612}