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