kafka_protocol/messages/
create_acls_response.rs

1//! CreateAclsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/CreateAclsResponse.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 AclCreationResult {
24    /// The result error, or zero if there was no error.
25    ///
26    /// Supported API versions: 0-3
27    pub error_code: i16,
28
29    /// The result message, or null if there was no error.
30    ///
31    /// Supported API versions: 0-3
32    pub error_message: Option<StrBytes>,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AclCreationResult {
39    /// Sets `error_code` to the passed value.
40    ///
41    /// The result error, or zero if there was no error.
42    ///
43    /// Supported API versions: 0-3
44    pub fn with_error_code(mut self, value: i16) -> Self {
45        self.error_code = value;
46        self
47    }
48    /// Sets `error_message` to the passed value.
49    ///
50    /// The result message, or null if there was no error.
51    ///
52    /// Supported API versions: 0-3
53    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
54        self.error_message = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for AclCreationResult {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version < 0 || version > 3 {
73            bail!("specified version not supported by this message type");
74        }
75        types::Int16.encode(buf, &self.error_code)?;
76        if version >= 2 {
77            types::CompactString.encode(buf, &self.error_message)?;
78        } else {
79            types::String.encode(buf, &self.error_message)?;
80        }
81        if version >= 2 {
82            let num_tagged_fields = self.unknown_tagged_fields.len();
83            if num_tagged_fields > std::u32::MAX as usize {
84                bail!(
85                    "Too many tagged fields to encode ({} fields)",
86                    num_tagged_fields
87                );
88            }
89            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
90
91            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
92        }
93        Ok(())
94    }
95    fn compute_size(&self, version: i16) -> Result<usize> {
96        let mut total_size = 0;
97        total_size += types::Int16.compute_size(&self.error_code)?;
98        if version >= 2 {
99            total_size += types::CompactString.compute_size(&self.error_message)?;
100        } else {
101            total_size += types::String.compute_size(&self.error_message)?;
102        }
103        if version >= 2 {
104            let num_tagged_fields = self.unknown_tagged_fields.len();
105            if num_tagged_fields > std::u32::MAX as usize {
106                bail!(
107                    "Too many tagged fields to encode ({} fields)",
108                    num_tagged_fields
109                );
110            }
111            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
112
113            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
114        }
115        Ok(total_size)
116    }
117}
118
119#[cfg(feature = "client")]
120impl Decodable for AclCreationResult {
121    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
122        if version < 0 || version > 3 {
123            bail!("specified version not supported by this message type");
124        }
125        let error_code = types::Int16.decode(buf)?;
126        let error_message = if version >= 2 {
127            types::CompactString.decode(buf)?
128        } else {
129            types::String.decode(buf)?
130        };
131        let mut unknown_tagged_fields = BTreeMap::new();
132        if version >= 2 {
133            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
134            for _ in 0..num_tagged_fields {
135                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
136                let size: u32 = types::UnsignedVarInt.decode(buf)?;
137                let unknown_value = buf.try_get_bytes(size as usize)?;
138                unknown_tagged_fields.insert(tag as i32, unknown_value);
139            }
140        }
141        Ok(Self {
142            error_code,
143            error_message,
144            unknown_tagged_fields,
145        })
146    }
147}
148
149impl Default for AclCreationResult {
150    fn default() -> Self {
151        Self {
152            error_code: 0,
153            error_message: Some(Default::default()),
154            unknown_tagged_fields: BTreeMap::new(),
155        }
156    }
157}
158
159impl Message for AclCreationResult {
160    const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
161    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
162}
163
164/// Valid versions: 0-3
165#[non_exhaustive]
166#[derive(Debug, Clone, PartialEq)]
167pub struct CreateAclsResponse {
168    /// 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.
169    ///
170    /// Supported API versions: 0-3
171    pub throttle_time_ms: i32,
172
173    /// The results for each ACL creation.
174    ///
175    /// Supported API versions: 0-3
176    pub results: Vec<AclCreationResult>,
177
178    /// Other tagged fields
179    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
180}
181
182impl CreateAclsResponse {
183    /// Sets `throttle_time_ms` to the passed value.
184    ///
185    /// 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.
186    ///
187    /// Supported API versions: 0-3
188    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
189        self.throttle_time_ms = value;
190        self
191    }
192    /// Sets `results` to the passed value.
193    ///
194    /// The results for each ACL creation.
195    ///
196    /// Supported API versions: 0-3
197    pub fn with_results(mut self, value: Vec<AclCreationResult>) -> Self {
198        self.results = value;
199        self
200    }
201    /// Sets unknown_tagged_fields to the passed value.
202    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
203        self.unknown_tagged_fields = value;
204        self
205    }
206    /// Inserts an entry into unknown_tagged_fields.
207    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
208        self.unknown_tagged_fields.insert(key, value);
209        self
210    }
211}
212
213#[cfg(feature = "broker")]
214impl Encodable for CreateAclsResponse {
215    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
216        if version < 0 || version > 3 {
217            bail!("specified version not supported by this message type");
218        }
219        types::Int32.encode(buf, &self.throttle_time_ms)?;
220        if version >= 2 {
221            types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
222        } else {
223            types::Array(types::Struct { version }).encode(buf, &self.results)?;
224        }
225        if version >= 2 {
226            let num_tagged_fields = self.unknown_tagged_fields.len();
227            if num_tagged_fields > std::u32::MAX as usize {
228                bail!(
229                    "Too many tagged fields to encode ({} fields)",
230                    num_tagged_fields
231                );
232            }
233            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
234
235            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
236        }
237        Ok(())
238    }
239    fn compute_size(&self, version: i16) -> Result<usize> {
240        let mut total_size = 0;
241        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
242        if version >= 2 {
243            total_size +=
244                types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
245        } else {
246            total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
247        }
248        if version >= 2 {
249            let num_tagged_fields = self.unknown_tagged_fields.len();
250            if num_tagged_fields > std::u32::MAX as usize {
251                bail!(
252                    "Too many tagged fields to encode ({} fields)",
253                    num_tagged_fields
254                );
255            }
256            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
257
258            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
259        }
260        Ok(total_size)
261    }
262}
263
264#[cfg(feature = "client")]
265impl Decodable for CreateAclsResponse {
266    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
267        if version < 0 || version > 3 {
268            bail!("specified version not supported by this message type");
269        }
270        let throttle_time_ms = types::Int32.decode(buf)?;
271        let results = if version >= 2 {
272            types::CompactArray(types::Struct { version }).decode(buf)?
273        } else {
274            types::Array(types::Struct { version }).decode(buf)?
275        };
276        let mut unknown_tagged_fields = BTreeMap::new();
277        if version >= 2 {
278            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
279            for _ in 0..num_tagged_fields {
280                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
281                let size: u32 = types::UnsignedVarInt.decode(buf)?;
282                let unknown_value = buf.try_get_bytes(size as usize)?;
283                unknown_tagged_fields.insert(tag as i32, unknown_value);
284            }
285        }
286        Ok(Self {
287            throttle_time_ms,
288            results,
289            unknown_tagged_fields,
290        })
291    }
292}
293
294impl Default for CreateAclsResponse {
295    fn default() -> Self {
296        Self {
297            throttle_time_ms: 0,
298            results: Default::default(),
299            unknown_tagged_fields: BTreeMap::new(),
300        }
301    }
302}
303
304impl Message for CreateAclsResponse {
305    const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
306    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
307}
308
309impl HeaderVersion for CreateAclsResponse {
310    fn header_version(version: i16) -> i16 {
311        if version >= 2 {
312            1
313        } else {
314            0
315        }
316    }
317}