kafka_protocol/messages/
describe_cluster_response.rs

1//! DescribeClusterResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeClusterResponse.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 DescribeClusterBroker {
24    /// The broker ID.
25    ///
26    /// Supported API versions: 0-1
27    pub broker_id: super::BrokerId,
28
29    /// The broker hostname.
30    ///
31    /// Supported API versions: 0-1
32    pub host: StrBytes,
33
34    /// The broker port.
35    ///
36    /// Supported API versions: 0-1
37    pub port: i32,
38
39    /// The rack of the broker, or null if it has not been assigned to a rack.
40    ///
41    /// Supported API versions: 0-1
42    pub rack: Option<StrBytes>,
43
44    /// Other tagged fields
45    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl DescribeClusterBroker {
49    /// Sets `broker_id` to the passed value.
50    ///
51    /// The broker ID.
52    ///
53    /// Supported API versions: 0-1
54    pub fn with_broker_id(mut self, value: super::BrokerId) -> Self {
55        self.broker_id = value;
56        self
57    }
58    /// Sets `host` to the passed value.
59    ///
60    /// The broker hostname.
61    ///
62    /// Supported API versions: 0-1
63    pub fn with_host(mut self, value: StrBytes) -> Self {
64        self.host = value;
65        self
66    }
67    /// Sets `port` to the passed value.
68    ///
69    /// The broker port.
70    ///
71    /// Supported API versions: 0-1
72    pub fn with_port(mut self, value: i32) -> Self {
73        self.port = value;
74        self
75    }
76    /// Sets `rack` to the passed value.
77    ///
78    /// The rack of the broker, or null if it has not been assigned to a rack.
79    ///
80    /// Supported API versions: 0-1
81    pub fn with_rack(mut self, value: Option<StrBytes>) -> Self {
82        self.rack = value;
83        self
84    }
85    /// Sets unknown_tagged_fields to the passed value.
86    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87        self.unknown_tagged_fields = value;
88        self
89    }
90    /// Inserts an entry into unknown_tagged_fields.
91    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92        self.unknown_tagged_fields.insert(key, value);
93        self
94    }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for DescribeClusterBroker {
99    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100        if version < 0 || version > 1 {
101            bail!("specified version not supported by this message type");
102        }
103        types::Int32.encode(buf, &self.broker_id)?;
104        types::CompactString.encode(buf, &self.host)?;
105        types::Int32.encode(buf, &self.port)?;
106        types::CompactString.encode(buf, &self.rack)?;
107        let num_tagged_fields = self.unknown_tagged_fields.len();
108        if num_tagged_fields > std::u32::MAX as usize {
109            bail!(
110                "Too many tagged fields to encode ({} fields)",
111                num_tagged_fields
112            );
113        }
114        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
115
116        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
117        Ok(())
118    }
119    fn compute_size(&self, version: i16) -> Result<usize> {
120        let mut total_size = 0;
121        total_size += types::Int32.compute_size(&self.broker_id)?;
122        total_size += types::CompactString.compute_size(&self.host)?;
123        total_size += types::Int32.compute_size(&self.port)?;
124        total_size += types::CompactString.compute_size(&self.rack)?;
125        let num_tagged_fields = self.unknown_tagged_fields.len();
126        if num_tagged_fields > std::u32::MAX as usize {
127            bail!(
128                "Too many tagged fields to encode ({} fields)",
129                num_tagged_fields
130            );
131        }
132        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
133
134        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
135        Ok(total_size)
136    }
137}
138
139#[cfg(feature = "client")]
140impl Decodable for DescribeClusterBroker {
141    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
142        if version < 0 || version > 1 {
143            bail!("specified version not supported by this message type");
144        }
145        let broker_id = types::Int32.decode(buf)?;
146        let host = types::CompactString.decode(buf)?;
147        let port = types::Int32.decode(buf)?;
148        let rack = types::CompactString.decode(buf)?;
149        let mut unknown_tagged_fields = BTreeMap::new();
150        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
151        for _ in 0..num_tagged_fields {
152            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
153            let size: u32 = types::UnsignedVarInt.decode(buf)?;
154            let unknown_value = buf.try_get_bytes(size as usize)?;
155            unknown_tagged_fields.insert(tag as i32, unknown_value);
156        }
157        Ok(Self {
158            broker_id,
159            host,
160            port,
161            rack,
162            unknown_tagged_fields,
163        })
164    }
165}
166
167impl Default for DescribeClusterBroker {
168    fn default() -> Self {
169        Self {
170            broker_id: (0).into(),
171            host: Default::default(),
172            port: 0,
173            rack: None,
174            unknown_tagged_fields: BTreeMap::new(),
175        }
176    }
177}
178
179impl Message for DescribeClusterBroker {
180    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
181    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
182}
183
184/// Valid versions: 0-1
185#[non_exhaustive]
186#[derive(Debug, Clone, PartialEq)]
187pub struct DescribeClusterResponse {
188    /// 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.
189    ///
190    /// Supported API versions: 0-1
191    pub throttle_time_ms: i32,
192
193    /// The top-level error code, or 0 if there was no error
194    ///
195    /// Supported API versions: 0-1
196    pub error_code: i16,
197
198    /// The top-level error message, or null if there was no error.
199    ///
200    /// Supported API versions: 0-1
201    pub error_message: Option<StrBytes>,
202
203    /// The endpoint type that was described. 1=brokers, 2=controllers.
204    ///
205    /// Supported API versions: 1
206    pub endpoint_type: i8,
207
208    /// The cluster ID that responding broker belongs to.
209    ///
210    /// Supported API versions: 0-1
211    pub cluster_id: StrBytes,
212
213    /// The ID of the controller broker.
214    ///
215    /// Supported API versions: 0-1
216    pub controller_id: super::BrokerId,
217
218    /// Each broker in the response.
219    ///
220    /// Supported API versions: 0-1
221    pub brokers: Vec<DescribeClusterBroker>,
222
223    /// 32-bit bitfield to represent authorized operations for this cluster.
224    ///
225    /// Supported API versions: 0-1
226    pub cluster_authorized_operations: i32,
227
228    /// Other tagged fields
229    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
230}
231
232impl DescribeClusterResponse {
233    /// Sets `throttle_time_ms` to the passed value.
234    ///
235    /// 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.
236    ///
237    /// Supported API versions: 0-1
238    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
239        self.throttle_time_ms = value;
240        self
241    }
242    /// Sets `error_code` to the passed value.
243    ///
244    /// The top-level error code, or 0 if there was no error
245    ///
246    /// Supported API versions: 0-1
247    pub fn with_error_code(mut self, value: i16) -> Self {
248        self.error_code = value;
249        self
250    }
251    /// Sets `error_message` to the passed value.
252    ///
253    /// The top-level error message, or null if there was no error.
254    ///
255    /// Supported API versions: 0-1
256    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
257        self.error_message = value;
258        self
259    }
260    /// Sets `endpoint_type` to the passed value.
261    ///
262    /// The endpoint type that was described. 1=brokers, 2=controllers.
263    ///
264    /// Supported API versions: 1
265    pub fn with_endpoint_type(mut self, value: i8) -> Self {
266        self.endpoint_type = value;
267        self
268    }
269    /// Sets `cluster_id` to the passed value.
270    ///
271    /// The cluster ID that responding broker belongs to.
272    ///
273    /// Supported API versions: 0-1
274    pub fn with_cluster_id(mut self, value: StrBytes) -> Self {
275        self.cluster_id = value;
276        self
277    }
278    /// Sets `controller_id` to the passed value.
279    ///
280    /// The ID of the controller broker.
281    ///
282    /// Supported API versions: 0-1
283    pub fn with_controller_id(mut self, value: super::BrokerId) -> Self {
284        self.controller_id = value;
285        self
286    }
287    /// Sets `brokers` to the passed value.
288    ///
289    /// Each broker in the response.
290    ///
291    /// Supported API versions: 0-1
292    pub fn with_brokers(mut self, value: Vec<DescribeClusterBroker>) -> Self {
293        self.brokers = value;
294        self
295    }
296    /// Sets `cluster_authorized_operations` to the passed value.
297    ///
298    /// 32-bit bitfield to represent authorized operations for this cluster.
299    ///
300    /// Supported API versions: 0-1
301    pub fn with_cluster_authorized_operations(mut self, value: i32) -> Self {
302        self.cluster_authorized_operations = value;
303        self
304    }
305    /// Sets unknown_tagged_fields to the passed value.
306    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
307        self.unknown_tagged_fields = value;
308        self
309    }
310    /// Inserts an entry into unknown_tagged_fields.
311    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
312        self.unknown_tagged_fields.insert(key, value);
313        self
314    }
315}
316
317#[cfg(feature = "broker")]
318impl Encodable for DescribeClusterResponse {
319    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
320        if version < 0 || version > 1 {
321            bail!("specified version not supported by this message type");
322        }
323        types::Int32.encode(buf, &self.throttle_time_ms)?;
324        types::Int16.encode(buf, &self.error_code)?;
325        types::CompactString.encode(buf, &self.error_message)?;
326        if version >= 1 {
327            types::Int8.encode(buf, &self.endpoint_type)?;
328        } else {
329            if self.endpoint_type != 1 {
330                bail!("A field is set that is not available on the selected protocol version");
331            }
332        }
333        types::CompactString.encode(buf, &self.cluster_id)?;
334        types::Int32.encode(buf, &self.controller_id)?;
335        types::CompactArray(types::Struct { version }).encode(buf, &self.brokers)?;
336        types::Int32.encode(buf, &self.cluster_authorized_operations)?;
337        let num_tagged_fields = self.unknown_tagged_fields.len();
338        if num_tagged_fields > std::u32::MAX as usize {
339            bail!(
340                "Too many tagged fields to encode ({} fields)",
341                num_tagged_fields
342            );
343        }
344        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
345
346        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
347        Ok(())
348    }
349    fn compute_size(&self, version: i16) -> Result<usize> {
350        let mut total_size = 0;
351        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
352        total_size += types::Int16.compute_size(&self.error_code)?;
353        total_size += types::CompactString.compute_size(&self.error_message)?;
354        if version >= 1 {
355            total_size += types::Int8.compute_size(&self.endpoint_type)?;
356        } else {
357            if self.endpoint_type != 1 {
358                bail!("A field is set that is not available on the selected protocol version");
359            }
360        }
361        total_size += types::CompactString.compute_size(&self.cluster_id)?;
362        total_size += types::Int32.compute_size(&self.controller_id)?;
363        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.brokers)?;
364        total_size += types::Int32.compute_size(&self.cluster_authorized_operations)?;
365        let num_tagged_fields = self.unknown_tagged_fields.len();
366        if num_tagged_fields > std::u32::MAX as usize {
367            bail!(
368                "Too many tagged fields to encode ({} fields)",
369                num_tagged_fields
370            );
371        }
372        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
373
374        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
375        Ok(total_size)
376    }
377}
378
379#[cfg(feature = "client")]
380impl Decodable for DescribeClusterResponse {
381    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
382        if version < 0 || version > 1 {
383            bail!("specified version not supported by this message type");
384        }
385        let throttle_time_ms = types::Int32.decode(buf)?;
386        let error_code = types::Int16.decode(buf)?;
387        let error_message = types::CompactString.decode(buf)?;
388        let endpoint_type = if version >= 1 {
389            types::Int8.decode(buf)?
390        } else {
391            1
392        };
393        let cluster_id = types::CompactString.decode(buf)?;
394        let controller_id = types::Int32.decode(buf)?;
395        let brokers = types::CompactArray(types::Struct { version }).decode(buf)?;
396        let cluster_authorized_operations = types::Int32.decode(buf)?;
397        let mut unknown_tagged_fields = BTreeMap::new();
398        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
399        for _ in 0..num_tagged_fields {
400            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
401            let size: u32 = types::UnsignedVarInt.decode(buf)?;
402            let unknown_value = buf.try_get_bytes(size as usize)?;
403            unknown_tagged_fields.insert(tag as i32, unknown_value);
404        }
405        Ok(Self {
406            throttle_time_ms,
407            error_code,
408            error_message,
409            endpoint_type,
410            cluster_id,
411            controller_id,
412            brokers,
413            cluster_authorized_operations,
414            unknown_tagged_fields,
415        })
416    }
417}
418
419impl Default for DescribeClusterResponse {
420    fn default() -> Self {
421        Self {
422            throttle_time_ms: 0,
423            error_code: 0,
424            error_message: None,
425            endpoint_type: 1,
426            cluster_id: Default::default(),
427            controller_id: (-1).into(),
428            brokers: Default::default(),
429            cluster_authorized_operations: -2147483648,
430            unknown_tagged_fields: BTreeMap::new(),
431        }
432    }
433}
434
435impl Message for DescribeClusterResponse {
436    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
437    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
438}
439
440impl HeaderVersion for DescribeClusterResponse {
441    fn header_version(version: i16) -> i16 {
442        1
443    }
444}