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