kafka_protocol/messages/
controller_registration_request.rs

1//! ControllerRegistrationRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ControllerRegistrationRequest.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 ControllerRegistrationRequest {
24    /// The ID of the controller to register.
25    ///
26    /// Supported API versions: 0
27    pub controller_id: i32,
28
29    /// The controller incarnation ID, which is unique to each process run.
30    ///
31    /// Supported API versions: 0
32    pub incarnation_id: Uuid,
33
34    /// Set if the required configurations for ZK migration are present.
35    ///
36    /// Supported API versions: 0
37    pub zk_migration_ready: bool,
38
39    /// The listeners of this controller
40    ///
41    /// Supported API versions: 0
42    pub listeners: Vec<Listener>,
43
44    /// The features on this controller
45    ///
46    /// Supported API versions: 0
47    pub features: Vec<Feature>,
48
49    /// Other tagged fields
50    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
51}
52
53impl ControllerRegistrationRequest {
54    /// Sets `controller_id` to the passed value.
55    ///
56    /// The ID of the controller to register.
57    ///
58    /// Supported API versions: 0
59    pub fn with_controller_id(mut self, value: i32) -> Self {
60        self.controller_id = value;
61        self
62    }
63    /// Sets `incarnation_id` to the passed value.
64    ///
65    /// The controller incarnation ID, which is unique to each process run.
66    ///
67    /// Supported API versions: 0
68    pub fn with_incarnation_id(mut self, value: Uuid) -> Self {
69        self.incarnation_id = value;
70        self
71    }
72    /// Sets `zk_migration_ready` to the passed value.
73    ///
74    /// Set if the required configurations for ZK migration are present.
75    ///
76    /// Supported API versions: 0
77    pub fn with_zk_migration_ready(mut self, value: bool) -> Self {
78        self.zk_migration_ready = value;
79        self
80    }
81    /// Sets `listeners` to the passed value.
82    ///
83    /// The listeners of this controller
84    ///
85    /// Supported API versions: 0
86    pub fn with_listeners(mut self, value: Vec<Listener>) -> Self {
87        self.listeners = value;
88        self
89    }
90    /// Sets `features` to the passed value.
91    ///
92    /// The features on this controller
93    ///
94    /// Supported API versions: 0
95    pub fn with_features(mut self, value: Vec<Feature>) -> Self {
96        self.features = value;
97        self
98    }
99    /// Sets unknown_tagged_fields to the passed value.
100    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
101        self.unknown_tagged_fields = value;
102        self
103    }
104    /// Inserts an entry into unknown_tagged_fields.
105    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
106        self.unknown_tagged_fields.insert(key, value);
107        self
108    }
109}
110
111#[cfg(feature = "client")]
112impl Encodable for ControllerRegistrationRequest {
113    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
114        types::Int32.encode(buf, &self.controller_id)?;
115        types::Uuid.encode(buf, &self.incarnation_id)?;
116        types::Boolean.encode(buf, &self.zk_migration_ready)?;
117        types::CompactArray(types::Struct { version }).encode(buf, &self.listeners)?;
118        types::CompactArray(types::Struct { version }).encode(buf, &self.features)?;
119        let num_tagged_fields = self.unknown_tagged_fields.len();
120        if num_tagged_fields > std::u32::MAX as usize {
121            bail!(
122                "Too many tagged fields to encode ({} fields)",
123                num_tagged_fields
124            );
125        }
126        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
127
128        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
129        Ok(())
130    }
131    fn compute_size(&self, version: i16) -> Result<usize> {
132        let mut total_size = 0;
133        total_size += types::Int32.compute_size(&self.controller_id)?;
134        total_size += types::Uuid.compute_size(&self.incarnation_id)?;
135        total_size += types::Boolean.compute_size(&self.zk_migration_ready)?;
136        total_size +=
137            types::CompactArray(types::Struct { version }).compute_size(&self.listeners)?;
138        total_size +=
139            types::CompactArray(types::Struct { version }).compute_size(&self.features)?;
140        let num_tagged_fields = self.unknown_tagged_fields.len();
141        if num_tagged_fields > std::u32::MAX as usize {
142            bail!(
143                "Too many tagged fields to encode ({} fields)",
144                num_tagged_fields
145            );
146        }
147        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
148
149        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
150        Ok(total_size)
151    }
152}
153
154#[cfg(feature = "broker")]
155impl Decodable for ControllerRegistrationRequest {
156    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
157        let controller_id = types::Int32.decode(buf)?;
158        let incarnation_id = types::Uuid.decode(buf)?;
159        let zk_migration_ready = types::Boolean.decode(buf)?;
160        let listeners = types::CompactArray(types::Struct { version }).decode(buf)?;
161        let features = types::CompactArray(types::Struct { version }).decode(buf)?;
162        let mut unknown_tagged_fields = BTreeMap::new();
163        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
164        for _ in 0..num_tagged_fields {
165            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
166            let size: u32 = types::UnsignedVarInt.decode(buf)?;
167            let unknown_value = buf.try_get_bytes(size as usize)?;
168            unknown_tagged_fields.insert(tag as i32, unknown_value);
169        }
170        Ok(Self {
171            controller_id,
172            incarnation_id,
173            zk_migration_ready,
174            listeners,
175            features,
176            unknown_tagged_fields,
177        })
178    }
179}
180
181impl Default for ControllerRegistrationRequest {
182    fn default() -> Self {
183        Self {
184            controller_id: 0,
185            incarnation_id: Uuid::nil(),
186            zk_migration_ready: false,
187            listeners: Default::default(),
188            features: Default::default(),
189            unknown_tagged_fields: BTreeMap::new(),
190        }
191    }
192}
193
194impl Message for ControllerRegistrationRequest {
195    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
196    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
197}
198
199/// Valid versions: 0
200#[non_exhaustive]
201#[derive(Debug, Clone, PartialEq)]
202pub struct Feature {
203    /// The feature name.
204    ///
205    /// Supported API versions: 0
206    pub name: StrBytes,
207
208    /// The minimum supported feature level.
209    ///
210    /// Supported API versions: 0
211    pub min_supported_version: i16,
212
213    /// The maximum supported feature level.
214    ///
215    /// Supported API versions: 0
216    pub max_supported_version: i16,
217
218    /// Other tagged fields
219    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
220}
221
222impl Feature {
223    /// Sets `name` to the passed value.
224    ///
225    /// The feature name.
226    ///
227    /// Supported API versions: 0
228    pub fn with_name(mut self, value: StrBytes) -> Self {
229        self.name = value;
230        self
231    }
232    /// Sets `min_supported_version` to the passed value.
233    ///
234    /// The minimum supported feature level.
235    ///
236    /// Supported API versions: 0
237    pub fn with_min_supported_version(mut self, value: i16) -> Self {
238        self.min_supported_version = value;
239        self
240    }
241    /// Sets `max_supported_version` to the passed value.
242    ///
243    /// The maximum supported feature level.
244    ///
245    /// Supported API versions: 0
246    pub fn with_max_supported_version(mut self, value: i16) -> Self {
247        self.max_supported_version = value;
248        self
249    }
250    /// Sets unknown_tagged_fields to the passed value.
251    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
252        self.unknown_tagged_fields = value;
253        self
254    }
255    /// Inserts an entry into unknown_tagged_fields.
256    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
257        self.unknown_tagged_fields.insert(key, value);
258        self
259    }
260}
261
262#[cfg(feature = "client")]
263impl Encodable for Feature {
264    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
265        types::CompactString.encode(buf, &self.name)?;
266        types::Int16.encode(buf, &self.min_supported_version)?;
267        types::Int16.encode(buf, &self.max_supported_version)?;
268        let num_tagged_fields = self.unknown_tagged_fields.len();
269        if num_tagged_fields > std::u32::MAX as usize {
270            bail!(
271                "Too many tagged fields to encode ({} fields)",
272                num_tagged_fields
273            );
274        }
275        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
276
277        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
278        Ok(())
279    }
280    fn compute_size(&self, version: i16) -> Result<usize> {
281        let mut total_size = 0;
282        total_size += types::CompactString.compute_size(&self.name)?;
283        total_size += types::Int16.compute_size(&self.min_supported_version)?;
284        total_size += types::Int16.compute_size(&self.max_supported_version)?;
285        let num_tagged_fields = self.unknown_tagged_fields.len();
286        if num_tagged_fields > std::u32::MAX as usize {
287            bail!(
288                "Too many tagged fields to encode ({} fields)",
289                num_tagged_fields
290            );
291        }
292        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
293
294        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
295        Ok(total_size)
296    }
297}
298
299#[cfg(feature = "broker")]
300impl Decodable for Feature {
301    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
302        let name = types::CompactString.decode(buf)?;
303        let min_supported_version = types::Int16.decode(buf)?;
304        let max_supported_version = types::Int16.decode(buf)?;
305        let mut unknown_tagged_fields = BTreeMap::new();
306        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
307        for _ in 0..num_tagged_fields {
308            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
309            let size: u32 = types::UnsignedVarInt.decode(buf)?;
310            let unknown_value = buf.try_get_bytes(size as usize)?;
311            unknown_tagged_fields.insert(tag as i32, unknown_value);
312        }
313        Ok(Self {
314            name,
315            min_supported_version,
316            max_supported_version,
317            unknown_tagged_fields,
318        })
319    }
320}
321
322impl Default for Feature {
323    fn default() -> Self {
324        Self {
325            name: Default::default(),
326            min_supported_version: 0,
327            max_supported_version: 0,
328            unknown_tagged_fields: BTreeMap::new(),
329        }
330    }
331}
332
333impl Message for Feature {
334    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
335    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
336}
337
338/// Valid versions: 0
339#[non_exhaustive]
340#[derive(Debug, Clone, PartialEq)]
341pub struct Listener {
342    /// The name of the endpoint.
343    ///
344    /// Supported API versions: 0
345    pub name: StrBytes,
346
347    /// The hostname.
348    ///
349    /// Supported API versions: 0
350    pub host: StrBytes,
351
352    /// The port.
353    ///
354    /// Supported API versions: 0
355    pub port: u16,
356
357    /// The security protocol.
358    ///
359    /// Supported API versions: 0
360    pub security_protocol: i16,
361
362    /// Other tagged fields
363    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
364}
365
366impl Listener {
367    /// Sets `name` to the passed value.
368    ///
369    /// The name of the endpoint.
370    ///
371    /// Supported API versions: 0
372    pub fn with_name(mut self, value: StrBytes) -> Self {
373        self.name = value;
374        self
375    }
376    /// Sets `host` to the passed value.
377    ///
378    /// The hostname.
379    ///
380    /// Supported API versions: 0
381    pub fn with_host(mut self, value: StrBytes) -> Self {
382        self.host = value;
383        self
384    }
385    /// Sets `port` to the passed value.
386    ///
387    /// The port.
388    ///
389    /// Supported API versions: 0
390    pub fn with_port(mut self, value: u16) -> Self {
391        self.port = value;
392        self
393    }
394    /// Sets `security_protocol` to the passed value.
395    ///
396    /// The security protocol.
397    ///
398    /// Supported API versions: 0
399    pub fn with_security_protocol(mut self, value: i16) -> Self {
400        self.security_protocol = value;
401        self
402    }
403    /// Sets unknown_tagged_fields to the passed value.
404    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
405        self.unknown_tagged_fields = value;
406        self
407    }
408    /// Inserts an entry into unknown_tagged_fields.
409    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
410        self.unknown_tagged_fields.insert(key, value);
411        self
412    }
413}
414
415#[cfg(feature = "client")]
416impl Encodable for Listener {
417    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
418        types::CompactString.encode(buf, &self.name)?;
419        types::CompactString.encode(buf, &self.host)?;
420        types::UInt16.encode(buf, &self.port)?;
421        types::Int16.encode(buf, &self.security_protocol)?;
422        let num_tagged_fields = self.unknown_tagged_fields.len();
423        if num_tagged_fields > std::u32::MAX as usize {
424            bail!(
425                "Too many tagged fields to encode ({} fields)",
426                num_tagged_fields
427            );
428        }
429        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
430
431        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
432        Ok(())
433    }
434    fn compute_size(&self, version: i16) -> Result<usize> {
435        let mut total_size = 0;
436        total_size += types::CompactString.compute_size(&self.name)?;
437        total_size += types::CompactString.compute_size(&self.host)?;
438        total_size += types::UInt16.compute_size(&self.port)?;
439        total_size += types::Int16.compute_size(&self.security_protocol)?;
440        let num_tagged_fields = self.unknown_tagged_fields.len();
441        if num_tagged_fields > std::u32::MAX as usize {
442            bail!(
443                "Too many tagged fields to encode ({} fields)",
444                num_tagged_fields
445            );
446        }
447        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
448
449        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
450        Ok(total_size)
451    }
452}
453
454#[cfg(feature = "broker")]
455impl Decodable for Listener {
456    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
457        let name = types::CompactString.decode(buf)?;
458        let host = types::CompactString.decode(buf)?;
459        let port = types::UInt16.decode(buf)?;
460        let security_protocol = types::Int16.decode(buf)?;
461        let mut unknown_tagged_fields = BTreeMap::new();
462        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
463        for _ in 0..num_tagged_fields {
464            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
465            let size: u32 = types::UnsignedVarInt.decode(buf)?;
466            let unknown_value = buf.try_get_bytes(size as usize)?;
467            unknown_tagged_fields.insert(tag as i32, unknown_value);
468        }
469        Ok(Self {
470            name,
471            host,
472            port,
473            security_protocol,
474            unknown_tagged_fields,
475        })
476    }
477}
478
479impl Default for Listener {
480    fn default() -> Self {
481        Self {
482            name: Default::default(),
483            host: Default::default(),
484            port: 0,
485            security_protocol: 0,
486            unknown_tagged_fields: BTreeMap::new(),
487        }
488    }
489}
490
491impl Message for Listener {
492    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
493    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
494}
495
496impl HeaderVersion for ControllerRegistrationRequest {
497    fn header_version(version: i16) -> i16 {
498        2
499    }
500}