kafka_protocol/messages/
list_config_resources_response.rs

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