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: 1-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: 1-3
27    pub error_code: i16,
28
29    /// The error message, or null if the filter succeeded.
30    ///
31    /// Supported API versions: 1-3
32    pub error_message: Option<StrBytes>,
33
34    /// The ACLs which matched this filter.
35    ///
36    /// Supported API versions: 1-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: 1-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: 1-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: 1-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 < 1 || 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 < 1 || 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: 1, max: 3 };
194    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
195}
196
197/// Valid versions: 1-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: 1-3
204    pub error_code: i16,
205
206    /// The deletion error message, or null if the deletion succeeded.
207    ///
208    /// Supported API versions: 1-3
209    pub error_message: Option<StrBytes>,
210
211    /// The ACL resource type.
212    ///
213    /// Supported API versions: 1-3
214    pub resource_type: i8,
215
216    /// The ACL resource name.
217    ///
218    /// Supported API versions: 1-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: 1-3
229    pub principal: StrBytes,
230
231    /// The ACL host.
232    ///
233    /// Supported API versions: 1-3
234    pub host: StrBytes,
235
236    /// The ACL operation.
237    ///
238    /// Supported API versions: 1-3
239    pub operation: i8,
240
241    /// The ACL permission type.
242    ///
243    /// Supported API versions: 1-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: 1-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: 1-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: 1-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: 1-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: 1-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: 1-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: 1-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: 1-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 < 1 || 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        types::Int8.encode(buf, &self.pattern_type)?;
363        if version >= 2 {
364            types::CompactString.encode(buf, &self.principal)?;
365        } else {
366            types::String.encode(buf, &self.principal)?;
367        }
368        if version >= 2 {
369            types::CompactString.encode(buf, &self.host)?;
370        } else {
371            types::String.encode(buf, &self.host)?;
372        }
373        types::Int8.encode(buf, &self.operation)?;
374        types::Int8.encode(buf, &self.permission_type)?;
375        if version >= 2 {
376            let num_tagged_fields = self.unknown_tagged_fields.len();
377            if num_tagged_fields > std::u32::MAX as usize {
378                bail!(
379                    "Too many tagged fields to encode ({} fields)",
380                    num_tagged_fields
381                );
382            }
383            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
384
385            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
386        }
387        Ok(())
388    }
389    fn compute_size(&self, version: i16) -> Result<usize> {
390        let mut total_size = 0;
391        total_size += types::Int16.compute_size(&self.error_code)?;
392        if version >= 2 {
393            total_size += types::CompactString.compute_size(&self.error_message)?;
394        } else {
395            total_size += types::String.compute_size(&self.error_message)?;
396        }
397        total_size += types::Int8.compute_size(&self.resource_type)?;
398        if version >= 2 {
399            total_size += types::CompactString.compute_size(&self.resource_name)?;
400        } else {
401            total_size += types::String.compute_size(&self.resource_name)?;
402        }
403        total_size += types::Int8.compute_size(&self.pattern_type)?;
404        if version >= 2 {
405            total_size += types::CompactString.compute_size(&self.principal)?;
406        } else {
407            total_size += types::String.compute_size(&self.principal)?;
408        }
409        if version >= 2 {
410            total_size += types::CompactString.compute_size(&self.host)?;
411        } else {
412            total_size += types::String.compute_size(&self.host)?;
413        }
414        total_size += types::Int8.compute_size(&self.operation)?;
415        total_size += types::Int8.compute_size(&self.permission_type)?;
416        if version >= 2 {
417            let num_tagged_fields = self.unknown_tagged_fields.len();
418            if num_tagged_fields > std::u32::MAX as usize {
419                bail!(
420                    "Too many tagged fields to encode ({} fields)",
421                    num_tagged_fields
422                );
423            }
424            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
425
426            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
427        }
428        Ok(total_size)
429    }
430}
431
432#[cfg(feature = "client")]
433impl Decodable for DeleteAclsMatchingAcl {
434    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
435        if version < 1 || version > 3 {
436            bail!("specified version not supported by this message type");
437        }
438        let error_code = types::Int16.decode(buf)?;
439        let error_message = if version >= 2 {
440            types::CompactString.decode(buf)?
441        } else {
442            types::String.decode(buf)?
443        };
444        let resource_type = types::Int8.decode(buf)?;
445        let resource_name = if version >= 2 {
446            types::CompactString.decode(buf)?
447        } else {
448            types::String.decode(buf)?
449        };
450        let pattern_type = types::Int8.decode(buf)?;
451        let principal = if version >= 2 {
452            types::CompactString.decode(buf)?
453        } else {
454            types::String.decode(buf)?
455        };
456        let host = if version >= 2 {
457            types::CompactString.decode(buf)?
458        } else {
459            types::String.decode(buf)?
460        };
461        let operation = types::Int8.decode(buf)?;
462        let permission_type = types::Int8.decode(buf)?;
463        let mut unknown_tagged_fields = BTreeMap::new();
464        if version >= 2 {
465            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
466            for _ in 0..num_tagged_fields {
467                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
468                let size: u32 = types::UnsignedVarInt.decode(buf)?;
469                let unknown_value = buf.try_get_bytes(size as usize)?;
470                unknown_tagged_fields.insert(tag as i32, unknown_value);
471            }
472        }
473        Ok(Self {
474            error_code,
475            error_message,
476            resource_type,
477            resource_name,
478            pattern_type,
479            principal,
480            host,
481            operation,
482            permission_type,
483            unknown_tagged_fields,
484        })
485    }
486}
487
488impl Default for DeleteAclsMatchingAcl {
489    fn default() -> Self {
490        Self {
491            error_code: 0,
492            error_message: Some(Default::default()),
493            resource_type: 0,
494            resource_name: Default::default(),
495            pattern_type: 3,
496            principal: Default::default(),
497            host: Default::default(),
498            operation: 0,
499            permission_type: 0,
500            unknown_tagged_fields: BTreeMap::new(),
501        }
502    }
503}
504
505impl Message for DeleteAclsMatchingAcl {
506    const VERSIONS: VersionRange = VersionRange { min: 1, max: 3 };
507    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
508}
509
510/// Valid versions: 1-3
511#[non_exhaustive]
512#[derive(Debug, Clone, PartialEq)]
513pub struct DeleteAclsResponse {
514    /// 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.
515    ///
516    /// Supported API versions: 1-3
517    pub throttle_time_ms: i32,
518
519    /// The results for each filter.
520    ///
521    /// Supported API versions: 1-3
522    pub filter_results: Vec<DeleteAclsFilterResult>,
523
524    /// Other tagged fields
525    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
526}
527
528impl DeleteAclsResponse {
529    /// Sets `throttle_time_ms` to the passed value.
530    ///
531    /// 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.
532    ///
533    /// Supported API versions: 1-3
534    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
535        self.throttle_time_ms = value;
536        self
537    }
538    /// Sets `filter_results` to the passed value.
539    ///
540    /// The results for each filter.
541    ///
542    /// Supported API versions: 1-3
543    pub fn with_filter_results(mut self, value: Vec<DeleteAclsFilterResult>) -> Self {
544        self.filter_results = value;
545        self
546    }
547    /// Sets unknown_tagged_fields to the passed value.
548    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
549        self.unknown_tagged_fields = value;
550        self
551    }
552    /// Inserts an entry into unknown_tagged_fields.
553    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
554        self.unknown_tagged_fields.insert(key, value);
555        self
556    }
557}
558
559#[cfg(feature = "broker")]
560impl Encodable for DeleteAclsResponse {
561    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
562        if version < 1 || version > 3 {
563            bail!("specified version not supported by this message type");
564        }
565        types::Int32.encode(buf, &self.throttle_time_ms)?;
566        if version >= 2 {
567            types::CompactArray(types::Struct { version }).encode(buf, &self.filter_results)?;
568        } else {
569            types::Array(types::Struct { version }).encode(buf, &self.filter_results)?;
570        }
571        if version >= 2 {
572            let num_tagged_fields = self.unknown_tagged_fields.len();
573            if num_tagged_fields > std::u32::MAX as usize {
574                bail!(
575                    "Too many tagged fields to encode ({} fields)",
576                    num_tagged_fields
577                );
578            }
579            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
580
581            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
582        }
583        Ok(())
584    }
585    fn compute_size(&self, version: i16) -> Result<usize> {
586        let mut total_size = 0;
587        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
588        if version >= 2 {
589            total_size += types::CompactArray(types::Struct { version })
590                .compute_size(&self.filter_results)?;
591        } else {
592            total_size +=
593                types::Array(types::Struct { version }).compute_size(&self.filter_results)?;
594        }
595        if version >= 2 {
596            let num_tagged_fields = self.unknown_tagged_fields.len();
597            if num_tagged_fields > std::u32::MAX as usize {
598                bail!(
599                    "Too many tagged fields to encode ({} fields)",
600                    num_tagged_fields
601                );
602            }
603            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
604
605            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
606        }
607        Ok(total_size)
608    }
609}
610
611#[cfg(feature = "client")]
612impl Decodable for DeleteAclsResponse {
613    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
614        if version < 1 || version > 3 {
615            bail!("specified version not supported by this message type");
616        }
617        let throttle_time_ms = types::Int32.decode(buf)?;
618        let filter_results = if version >= 2 {
619            types::CompactArray(types::Struct { version }).decode(buf)?
620        } else {
621            types::Array(types::Struct { version }).decode(buf)?
622        };
623        let mut unknown_tagged_fields = BTreeMap::new();
624        if version >= 2 {
625            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
626            for _ in 0..num_tagged_fields {
627                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
628                let size: u32 = types::UnsignedVarInt.decode(buf)?;
629                let unknown_value = buf.try_get_bytes(size as usize)?;
630                unknown_tagged_fields.insert(tag as i32, unknown_value);
631            }
632        }
633        Ok(Self {
634            throttle_time_ms,
635            filter_results,
636            unknown_tagged_fields,
637        })
638    }
639}
640
641impl Default for DeleteAclsResponse {
642    fn default() -> Self {
643        Self {
644            throttle_time_ms: 0,
645            filter_results: Default::default(),
646            unknown_tagged_fields: BTreeMap::new(),
647        }
648    }
649}
650
651impl Message for DeleteAclsResponse {
652    const VERSIONS: VersionRange = VersionRange { min: 1, max: 3 };
653    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
654}
655
656impl HeaderVersion for DeleteAclsResponse {
657    fn header_version(version: i16) -> i16 {
658        if version >= 2 {
659            1
660        } else {
661            0
662        }
663    }
664}