Skip to main content

kacrab_protocol/generated/
broker_registration_request.rs

1//! Generated from BrokerRegistrationRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct BrokerRegistrationRequestData {
17    /// The broker ID.
18    pub broker_id: i32,
19    /// The cluster id of the broker process.
20    pub cluster_id: KafkaString,
21    /// The incarnation id of the broker process.
22    pub incarnation_id: KafkaUuid,
23    /// The listeners of this broker.
24    pub listeners: Vec<Listener>,
25    /// The features on this broker. Note: in v0-v3, features with MinSupportedVersion = 0 are
26    /// omitted.
27    pub features: Vec<Feature>,
28    /// The rack which this broker is in.
29    pub rack: Option<KafkaString>,
30    /// If the required configurations for ZK migration are present, this value is set to true.
31    pub is_migrating_zk_broker: bool,
32    /// Log directories configured in this broker which are available.
33    pub log_dirs: Vec<KafkaUuid>,
34    /// The epoch before a clean shutdown.
35    pub previous_broker_epoch: i64,
36    pub _unknown_tagged_fields: Vec<RawTaggedField>,
37}
38impl Default for BrokerRegistrationRequestData {
39    fn default() -> Self {
40        Self {
41            broker_id: 0_i32,
42            cluster_id: KafkaString::default(),
43            incarnation_id: KafkaUuid::ZERO,
44            listeners: Vec::new(),
45            features: Vec::new(),
46            rack: None,
47            is_migrating_zk_broker: false,
48            log_dirs: Vec::new(),
49            previous_broker_epoch: -1i64,
50            _unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54impl BrokerRegistrationRequestData {
55    pub fn with_broker_id(mut self, value: i32) -> Self {
56        self.broker_id = value;
57        self
58    }
59    pub fn with_cluster_id(mut self, value: KafkaString) -> Self {
60        self.cluster_id = value;
61        self
62    }
63    pub fn with_incarnation_id(mut self, value: KafkaUuid) -> Self {
64        self.incarnation_id = value;
65        self
66    }
67    pub fn with_listeners(mut self, value: Vec<Listener>) -> Self {
68        self.listeners = value;
69        self
70    }
71    pub fn with_features(mut self, value: Vec<Feature>) -> Self {
72        self.features = value;
73        self
74    }
75    pub fn with_rack(mut self, value: Option<KafkaString>) -> Self {
76        self.rack = value;
77        self
78    }
79    pub fn with_is_migrating_zk_broker(mut self, value: bool) -> Self {
80        self.is_migrating_zk_broker = value;
81        self
82    }
83    pub fn with_log_dirs(mut self, value: Vec<KafkaUuid>) -> Self {
84        self.log_dirs = value;
85        self
86    }
87    pub fn with_previous_broker_epoch(mut self, value: i64) -> Self {
88        self.previous_broker_epoch = value;
89        self
90    }
91    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
92        if version < 0 || version > 4 {
93            return Err(UnsupportedVersion::new(62, version).into());
94        }
95        let broker_id;
96        let cluster_id;
97        let incarnation_id;
98        let listeners;
99        let features;
100        let rack;
101        let mut is_migrating_zk_broker = false;
102        let mut log_dirs = Vec::new();
103        let mut previous_broker_epoch = -1i64;
104        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
105        broker_id = read_i32(buf)?;
106        cluster_id = read_compact_string(buf)?;
107        incarnation_id = read_uuid(buf)?;
108        listeners = {
109            let len = read_compact_array_length(buf)?;
110            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
111            for _ in 0..len {
112                arr.push(Listener::read(buf, version)?);
113            }
114            arr
115        };
116        features = {
117            let len = read_compact_array_length(buf)?;
118            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
119            for _ in 0..len {
120                arr.push(Feature::read(buf, version)?);
121            }
122            arr
123        };
124        rack = read_compact_nullable_string(buf)?;
125        if version >= 1 {
126            is_migrating_zk_broker = read_bool(buf)?;
127        }
128        if version >= 2 {
129            log_dirs = {
130                let len = read_compact_array_length(buf)?;
131                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
132                for _ in 0..len {
133                    arr.push(read_uuid(buf)?);
134                }
135                arr
136            };
137        }
138        if version >= 3 {
139            previous_broker_epoch = read_i64(buf)?;
140        }
141        let tagged_fields = read_tagged_fields(buf)?;
142        for field in &tagged_fields {
143            match field.tag {
144                _ => {
145                    _unknown_tagged_fields.push(field.clone());
146                },
147            }
148        }
149        Ok(Self {
150            broker_id,
151            cluster_id,
152            incarnation_id,
153            listeners,
154            features,
155            rack,
156            is_migrating_zk_broker,
157            log_dirs,
158            previous_broker_epoch,
159            _unknown_tagged_fields,
160        })
161    }
162    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
163        if version < 0 || version > 4 {
164            return Err(UnsupportedVersion::new(62, version).into());
165        }
166        write_i32(buf, self.broker_id);
167        write_compact_string(buf, &self.cluster_id)?;
168        write_uuid(buf, &self.incarnation_id);
169        write_compact_array_length(buf, self.listeners.len() as i32);
170        for el in &self.listeners {
171            el.write(buf, version)?;
172        }
173        write_compact_array_length(buf, self.features.len() as i32);
174        for el in &self.features {
175            el.write(buf, version)?;
176        }
177        write_compact_nullable_string(buf, self.rack.as_ref())?;
178        if version >= 1 {
179            write_bool(buf, self.is_migrating_zk_broker);
180        } else if self.is_migrating_zk_broker != false {
181            return Err(UnsupportedFieldVersion::new(62, "is_migrating_zk_broker", version).into());
182        }
183        if version >= 2 {
184            write_compact_array_length(buf, self.log_dirs.len() as i32);
185            for el in &self.log_dirs {
186                write_uuid(buf, el);
187            }
188        } else if self.log_dirs != Vec::new() {
189            return Err(UnsupportedFieldVersion::new(62, "log_dirs", version).into());
190        }
191        if version >= 3 {
192            write_i64(buf, self.previous_broker_epoch);
193        } else if self.previous_broker_epoch != -1i64 {
194            return Err(UnsupportedFieldVersion::new(62, "previous_broker_epoch", version).into());
195        }
196        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
197        all_tags.sort_by_key(|f| f.tag);
198        write_tagged_fields(buf, &all_tags)?;
199        Ok(())
200    }
201    pub fn encoded_len(&self, version: i16) -> Result<usize> {
202        if version < 0 || version > 4 {
203            return Err(UnsupportedVersion::new(62, version).into());
204        }
205        let mut len: usize = 0;
206        len += 4;
207        len += compact_string_len(&self.cluster_id)?;
208        len += 16;
209        len += compact_array_length_len(self.listeners.len() as i32);
210        for el in &self.listeners {
211            len += el.encoded_len(version)?;
212        }
213        len += compact_array_length_len(self.features.len() as i32);
214        for el in &self.features {
215            len += el.encoded_len(version)?;
216        }
217        len += compact_nullable_string_len(self.rack.as_ref())?;
218        if version >= 1 {
219            len += 1;
220        } else if self.is_migrating_zk_broker != false {
221            return Err(UnsupportedFieldVersion::new(62, "is_migrating_zk_broker", version).into());
222        }
223        if version >= 2 {
224            len += compact_array_length_len(self.log_dirs.len() as i32);
225            len += self.log_dirs.len() * 16usize;
226        } else if self.log_dirs != Vec::new() {
227            return Err(UnsupportedFieldVersion::new(62, "log_dirs", version).into());
228        }
229        if version >= 3 {
230            len += 8;
231        } else if self.previous_broker_epoch != -1i64 {
232            return Err(UnsupportedFieldVersion::new(62, "previous_broker_epoch", version).into());
233        }
234        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
235        all_tags.sort_by_key(|f| f.tag);
236        len += tagged_fields_len(&all_tags)?;
237        Ok(len)
238    }
239}
240#[derive(Debug, Clone, PartialEq)]
241pub struct Listener {
242    /// The name of the endpoint.
243    pub name: KafkaString,
244    /// The hostname.
245    pub host: KafkaString,
246    /// The port.
247    pub port: u16,
248    /// The security protocol.
249    pub security_protocol: i16,
250    pub _unknown_tagged_fields: Vec<RawTaggedField>,
251}
252impl Default for Listener {
253    fn default() -> Self {
254        Self {
255            name: KafkaString::default(),
256            host: KafkaString::default(),
257            port: 0_u16,
258            security_protocol: 0_i16,
259            _unknown_tagged_fields: Vec::new(),
260        }
261    }
262}
263impl Listener {
264    pub fn with_name(mut self, value: KafkaString) -> Self {
265        self.name = value;
266        self
267    }
268    pub fn with_host(mut self, value: KafkaString) -> Self {
269        self.host = value;
270        self
271    }
272    pub fn with_port(mut self, value: u16) -> Self {
273        self.port = value;
274        self
275    }
276    pub fn with_security_protocol(mut self, value: i16) -> Self {
277        self.security_protocol = value;
278        self
279    }
280    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
281        let name;
282        let host;
283        let port;
284        let security_protocol;
285        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
286        name = read_compact_string(buf)?;
287        host = read_compact_string(buf)?;
288        port = read_u16(buf)?;
289        security_protocol = read_i16(buf)?;
290        let tagged_fields = read_tagged_fields(buf)?;
291        for field in &tagged_fields {
292            match field.tag {
293                _ => {
294                    _unknown_tagged_fields.push(field.clone());
295                },
296            }
297        }
298        Ok(Self {
299            name,
300            host,
301            port,
302            security_protocol,
303            _unknown_tagged_fields,
304        })
305    }
306    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
307        write_compact_string(buf, &self.name)?;
308        write_compact_string(buf, &self.host)?;
309        write_u16(buf, self.port);
310        write_i16(buf, self.security_protocol);
311        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
312        all_tags.sort_by_key(|f| f.tag);
313        write_tagged_fields(buf, &all_tags)?;
314        Ok(())
315    }
316    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
317        let mut len: usize = 0;
318        len += compact_string_len(&self.name)?;
319        len += compact_string_len(&self.host)?;
320        len += 2;
321        len += 2;
322        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
323        all_tags.sort_by_key(|f| f.tag);
324        len += tagged_fields_len(&all_tags)?;
325        Ok(len)
326    }
327}
328#[derive(Debug, Clone, PartialEq)]
329pub struct Feature {
330    /// The feature name.
331    pub name: KafkaString,
332    /// The minimum supported feature level.
333    pub min_supported_version: i16,
334    /// The maximum supported feature level.
335    pub max_supported_version: i16,
336    pub _unknown_tagged_fields: Vec<RawTaggedField>,
337}
338impl Default for Feature {
339    fn default() -> Self {
340        Self {
341            name: KafkaString::default(),
342            min_supported_version: 0_i16,
343            max_supported_version: 0_i16,
344            _unknown_tagged_fields: Vec::new(),
345        }
346    }
347}
348impl Feature {
349    pub fn with_name(mut self, value: KafkaString) -> Self {
350        self.name = value;
351        self
352    }
353    pub fn with_min_supported_version(mut self, value: i16) -> Self {
354        self.min_supported_version = value;
355        self
356    }
357    pub fn with_max_supported_version(mut self, value: i16) -> Self {
358        self.max_supported_version = value;
359        self
360    }
361    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
362        let name;
363        let min_supported_version;
364        let max_supported_version;
365        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
366        name = read_compact_string(buf)?;
367        min_supported_version = read_i16(buf)?;
368        max_supported_version = read_i16(buf)?;
369        let tagged_fields = read_tagged_fields(buf)?;
370        for field in &tagged_fields {
371            match field.tag {
372                _ => {
373                    _unknown_tagged_fields.push(field.clone());
374                },
375            }
376        }
377        Ok(Self {
378            name,
379            min_supported_version,
380            max_supported_version,
381            _unknown_tagged_fields,
382        })
383    }
384    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
385        write_compact_string(buf, &self.name)?;
386        write_i16(buf, self.min_supported_version);
387        write_i16(buf, self.max_supported_version);
388        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
389        all_tags.sort_by_key(|f| f.tag);
390        write_tagged_fields(buf, &all_tags)?;
391        Ok(())
392    }
393    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
394        let mut len: usize = 0;
395        len += compact_string_len(&self.name)?;
396        len += 2;
397        len += 2;
398        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
399        all_tags.sort_by_key(|f| f.tag);
400        len += tagged_fields_len(&all_tags)?;
401        Ok(len)
402    }
403}