kafka_protocol/messages/
delete_acls_response.rs

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