kafka_protocol/messages/
alter_configs_response.rs

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