kafka_protocol/messages/
list_client_metrics_resources_response.rs

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