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 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#[non_exhaustive]
123#[derive(Debug, Clone, PartialEq)]
124pub struct ListClientMetricsResourcesResponse {
125 pub throttle_time_ms: i32,
129
130 pub error_code: i16,
134
135 pub client_metrics_resources: Vec<ClientMetricsResource>,
139
140 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
142}
143
144impl ListClientMetricsResourcesResponse {
145 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
151 self.throttle_time_ms = value;
152 self
153 }
154 pub fn with_error_code(mut self, value: i16) -> Self {
160 self.error_code = value;
161 self
162 }
163 pub fn with_client_metrics_resources(mut self, value: Vec<ClientMetricsResource>) -> Self {
169 self.client_metrics_resources = value;
170 self
171 }
172 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
174 self.unknown_tagged_fields = value;
175 self
176 }
177 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}