kafka_protocol/messages/
list_client_metrics_resources_response.rs1#![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#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ClientMetricsResource {
24 pub name: StrBytes,
28
29 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl ClientMetricsResource {
34 pub fn with_name(mut self, value: StrBytes) -> Self {
40 self.name = value;
41 self
42 }
43 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45 self.unknown_tagged_fields = value;
46 self
47 }
48 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#[non_exhaustive]
129#[derive(Debug, Clone, PartialEq)]
130pub struct ListClientMetricsResourcesResponse {
131 pub throttle_time_ms: i32,
135
136 pub error_code: i16,
140
141 pub client_metrics_resources: Vec<ClientMetricsResource>,
145
146 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
148}
149
150impl ListClientMetricsResourcesResponse {
151 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
157 self.throttle_time_ms = value;
158 self
159 }
160 pub fn with_error_code(mut self, value: i16) -> Self {
166 self.error_code = value;
167 self
168 }
169 pub fn with_client_metrics_resources(mut self, value: Vec<ClientMetricsResource>) -> Self {
175 self.client_metrics_resources = value;
176 self
177 }
178 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
180 self.unknown_tagged_fields = value;
181 self
182 }
183 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}