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