kafka_protocol/messages/
describe_cluster_request.rs

1//! DescribeClusterRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeClusterRequest.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-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DescribeClusterRequest {
24    /// Whether to include cluster authorized operations.
25    ///
26    /// Supported API versions: 0-2
27    pub include_cluster_authorized_operations: bool,
28
29    /// The endpoint type to describe. 1=brokers, 2=controllers.
30    ///
31    /// Supported API versions: 1-2
32    pub endpoint_type: i8,
33
34    /// Whether to include fenced brokers when listing brokers.
35    ///
36    /// Supported API versions: 2
37    pub include_fenced_brokers: bool,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl DescribeClusterRequest {
44    /// Sets `include_cluster_authorized_operations` to the passed value.
45    ///
46    /// Whether to include cluster authorized operations.
47    ///
48    /// Supported API versions: 0-2
49    pub fn with_include_cluster_authorized_operations(mut self, value: bool) -> Self {
50        self.include_cluster_authorized_operations = value;
51        self
52    }
53    /// Sets `endpoint_type` to the passed value.
54    ///
55    /// The endpoint type to describe. 1=brokers, 2=controllers.
56    ///
57    /// Supported API versions: 1-2
58    pub fn with_endpoint_type(mut self, value: i8) -> Self {
59        self.endpoint_type = value;
60        self
61    }
62    /// Sets `include_fenced_brokers` to the passed value.
63    ///
64    /// Whether to include fenced brokers when listing brokers.
65    ///
66    /// Supported API versions: 2
67    pub fn with_include_fenced_brokers(mut self, value: bool) -> Self {
68        self.include_fenced_brokers = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "client")]
84impl Encodable for DescribeClusterRequest {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 0 || version > 2 {
87            bail!("specified version not supported by this message type");
88        }
89        types::Boolean.encode(buf, &self.include_cluster_authorized_operations)?;
90        if version >= 1 {
91            types::Int8.encode(buf, &self.endpoint_type)?;
92        } else {
93            if self.endpoint_type != 1 {
94                bail!("A field is set that is not available on the selected protocol version");
95            }
96        }
97        if version >= 2 {
98            types::Boolean.encode(buf, &self.include_fenced_brokers)?;
99        } else {
100            if self.include_fenced_brokers {
101                bail!("A field is set that is not available on the selected protocol version");
102            }
103        }
104        let num_tagged_fields = self.unknown_tagged_fields.len();
105        if num_tagged_fields > std::u32::MAX as usize {
106            bail!(
107                "Too many tagged fields to encode ({} fields)",
108                num_tagged_fields
109            );
110        }
111        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
112
113        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
114        Ok(())
115    }
116    fn compute_size(&self, version: i16) -> Result<usize> {
117        let mut total_size = 0;
118        total_size += types::Boolean.compute_size(&self.include_cluster_authorized_operations)?;
119        if version >= 1 {
120            total_size += types::Int8.compute_size(&self.endpoint_type)?;
121        } else {
122            if self.endpoint_type != 1 {
123                bail!("A field is set that is not available on the selected protocol version");
124            }
125        }
126        if version >= 2 {
127            total_size += types::Boolean.compute_size(&self.include_fenced_brokers)?;
128        } else {
129            if self.include_fenced_brokers {
130                bail!("A field is set that is not available on the selected protocol version");
131            }
132        }
133        let num_tagged_fields = self.unknown_tagged_fields.len();
134        if num_tagged_fields > std::u32::MAX as usize {
135            bail!(
136                "Too many tagged fields to encode ({} fields)",
137                num_tagged_fields
138            );
139        }
140        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
141
142        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
143        Ok(total_size)
144    }
145}
146
147#[cfg(feature = "broker")]
148impl Decodable for DescribeClusterRequest {
149    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
150        if version < 0 || version > 2 {
151            bail!("specified version not supported by this message type");
152        }
153        let include_cluster_authorized_operations = types::Boolean.decode(buf)?;
154        let endpoint_type = if version >= 1 {
155            types::Int8.decode(buf)?
156        } else {
157            1
158        };
159        let include_fenced_brokers = if version >= 2 {
160            types::Boolean.decode(buf)?
161        } else {
162            false
163        };
164        let mut unknown_tagged_fields = BTreeMap::new();
165        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
166        for _ in 0..num_tagged_fields {
167            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
168            let size: u32 = types::UnsignedVarInt.decode(buf)?;
169            let unknown_value = buf.try_get_bytes(size as usize)?;
170            unknown_tagged_fields.insert(tag as i32, unknown_value);
171        }
172        Ok(Self {
173            include_cluster_authorized_operations,
174            endpoint_type,
175            include_fenced_brokers,
176            unknown_tagged_fields,
177        })
178    }
179}
180
181impl Default for DescribeClusterRequest {
182    fn default() -> Self {
183        Self {
184            include_cluster_authorized_operations: false,
185            endpoint_type: 1,
186            include_fenced_brokers: false,
187            unknown_tagged_fields: BTreeMap::new(),
188        }
189    }
190}
191
192impl Message for DescribeClusterRequest {
193    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
194    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
195}
196
197impl HeaderVersion for DescribeClusterRequest {
198    fn header_version(version: i16) -> i16 {
199        2
200    }
201}