Skip to main content

kacrab_protocol/generated/
controller_registration_request.rs

1//! Generated from ControllerRegistrationRequest.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 ControllerRegistrationRequestData {
17    /// The ID of the controller to register.
18    pub controller_id: i32,
19    /// The controller incarnation ID, which is unique to each process run.
20    pub incarnation_id: KafkaUuid,
21    /// Set if the required configurations for ZK migration are present.
22    pub zk_migration_ready: bool,
23    /// The listeners of this controller.
24    pub listeners: Vec<Listener>,
25    /// The features on this controller.
26    pub features: Vec<Feature>,
27    pub _unknown_tagged_fields: Vec<RawTaggedField>,
28}
29impl Default for ControllerRegistrationRequestData {
30    fn default() -> Self {
31        Self {
32            controller_id: 0_i32,
33            incarnation_id: KafkaUuid::ZERO,
34            zk_migration_ready: false,
35            listeners: Vec::new(),
36            features: Vec::new(),
37            _unknown_tagged_fields: Vec::new(),
38        }
39    }
40}
41impl ControllerRegistrationRequestData {
42    pub fn with_controller_id(mut self, value: i32) -> Self {
43        self.controller_id = value;
44        self
45    }
46    pub fn with_incarnation_id(mut self, value: KafkaUuid) -> Self {
47        self.incarnation_id = value;
48        self
49    }
50    pub fn with_zk_migration_ready(mut self, value: bool) -> Self {
51        self.zk_migration_ready = value;
52        self
53    }
54    pub fn with_listeners(mut self, value: Vec<Listener>) -> Self {
55        self.listeners = value;
56        self
57    }
58    pub fn with_features(mut self, value: Vec<Feature>) -> Self {
59        self.features = value;
60        self
61    }
62    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
63        if version < 0 || version > 0 {
64            return Err(UnsupportedVersion::new(70, version).into());
65        }
66        let controller_id;
67        let incarnation_id;
68        let zk_migration_ready;
69        let listeners;
70        let features;
71        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
72        controller_id = read_i32(buf)?;
73        incarnation_id = read_uuid(buf)?;
74        zk_migration_ready = read_bool(buf)?;
75        listeners = {
76            let len = read_compact_array_length(buf)?;
77            let mut arr = Vec::with_capacity(len.max(0) as usize);
78            for _ in 0..len {
79                arr.push(Listener::read(buf, version)?);
80            }
81            arr
82        };
83        features = {
84            let len = read_compact_array_length(buf)?;
85            let mut arr = Vec::with_capacity(len.max(0) as usize);
86            for _ in 0..len {
87                arr.push(Feature::read(buf, version)?);
88            }
89            arr
90        };
91        let tagged_fields = read_tagged_fields(buf)?;
92        for field in &tagged_fields {
93            match field.tag {
94                _ => {
95                    _unknown_tagged_fields.push(field.clone());
96                },
97            }
98        }
99        Ok(Self {
100            controller_id,
101            incarnation_id,
102            zk_migration_ready,
103            listeners,
104            features,
105            _unknown_tagged_fields,
106        })
107    }
108    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
109        if version < 0 || version > 0 {
110            return Err(UnsupportedVersion::new(70, version).into());
111        }
112        write_i32(buf, self.controller_id);
113        write_uuid(buf, &self.incarnation_id);
114        write_bool(buf, self.zk_migration_ready);
115        write_compact_array_length(buf, self.listeners.len() as i32);
116        for el in &self.listeners {
117            el.write(buf, version)?;
118        }
119        write_compact_array_length(buf, self.features.len() as i32);
120        for el in &self.features {
121            el.write(buf, version)?;
122        }
123        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
124        all_tags.sort_by_key(|f| f.tag);
125        write_tagged_fields(buf, &all_tags)?;
126        Ok(())
127    }
128    pub fn encoded_len(&self, version: i16) -> Result<usize> {
129        if version < 0 || version > 0 {
130            return Err(UnsupportedVersion::new(70, version).into());
131        }
132        let mut len: usize = 0;
133        len += 4;
134        len += 16;
135        len += 1;
136        len += compact_array_length_len(self.listeners.len() as i32);
137        for el in &self.listeners {
138            len += el.encoded_len(version)?;
139        }
140        len += compact_array_length_len(self.features.len() as i32);
141        for el in &self.features {
142            len += el.encoded_len(version)?;
143        }
144        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
145        all_tags.sort_by_key(|f| f.tag);
146        len += tagged_fields_len(&all_tags)?;
147        Ok(len)
148    }
149}
150#[derive(Debug, Clone, PartialEq)]
151pub struct Listener {
152    /// The name of the endpoint.
153    pub name: KafkaString,
154    /// The hostname.
155    pub host: KafkaString,
156    /// The port.
157    pub port: u16,
158    /// The security protocol.
159    pub security_protocol: i16,
160    pub _unknown_tagged_fields: Vec<RawTaggedField>,
161}
162impl Default for Listener {
163    fn default() -> Self {
164        Self {
165            name: KafkaString::default(),
166            host: KafkaString::default(),
167            port: 0_u16,
168            security_protocol: 0_i16,
169            _unknown_tagged_fields: Vec::new(),
170        }
171    }
172}
173impl Listener {
174    pub fn with_name(mut self, value: KafkaString) -> Self {
175        self.name = value;
176        self
177    }
178    pub fn with_host(mut self, value: KafkaString) -> Self {
179        self.host = value;
180        self
181    }
182    pub fn with_port(mut self, value: u16) -> Self {
183        self.port = value;
184        self
185    }
186    pub fn with_security_protocol(mut self, value: i16) -> Self {
187        self.security_protocol = value;
188        self
189    }
190    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
191        let name;
192        let host;
193        let port;
194        let security_protocol;
195        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
196        name = read_compact_string(buf)?;
197        host = read_compact_string(buf)?;
198        port = read_u16(buf)?;
199        security_protocol = read_i16(buf)?;
200        let tagged_fields = read_tagged_fields(buf)?;
201        for field in &tagged_fields {
202            match field.tag {
203                _ => {
204                    _unknown_tagged_fields.push(field.clone());
205                },
206            }
207        }
208        Ok(Self {
209            name,
210            host,
211            port,
212            security_protocol,
213            _unknown_tagged_fields,
214        })
215    }
216    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
217        write_compact_string(buf, &self.name)?;
218        write_compact_string(buf, &self.host)?;
219        write_u16(buf, self.port);
220        write_i16(buf, self.security_protocol);
221        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
222        all_tags.sort_by_key(|f| f.tag);
223        write_tagged_fields(buf, &all_tags)?;
224        Ok(())
225    }
226    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
227        let mut len: usize = 0;
228        len += compact_string_len(&self.name)?;
229        len += compact_string_len(&self.host)?;
230        len += 2;
231        len += 2;
232        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
233        all_tags.sort_by_key(|f| f.tag);
234        len += tagged_fields_len(&all_tags)?;
235        Ok(len)
236    }
237}
238#[derive(Debug, Clone, PartialEq)]
239pub struct Feature {
240    /// The feature name.
241    pub name: KafkaString,
242    /// The minimum supported feature level.
243    pub min_supported_version: i16,
244    /// The maximum supported feature level.
245    pub max_supported_version: i16,
246    pub _unknown_tagged_fields: Vec<RawTaggedField>,
247}
248impl Default for Feature {
249    fn default() -> Self {
250        Self {
251            name: KafkaString::default(),
252            min_supported_version: 0_i16,
253            max_supported_version: 0_i16,
254            _unknown_tagged_fields: Vec::new(),
255        }
256    }
257}
258impl Feature {
259    pub fn with_name(mut self, value: KafkaString) -> Self {
260        self.name = value;
261        self
262    }
263    pub fn with_min_supported_version(mut self, value: i16) -> Self {
264        self.min_supported_version = value;
265        self
266    }
267    pub fn with_max_supported_version(mut self, value: i16) -> Self {
268        self.max_supported_version = value;
269        self
270    }
271    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
272        let name;
273        let min_supported_version;
274        let max_supported_version;
275        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
276        name = read_compact_string(buf)?;
277        min_supported_version = read_i16(buf)?;
278        max_supported_version = read_i16(buf)?;
279        let tagged_fields = read_tagged_fields(buf)?;
280        for field in &tagged_fields {
281            match field.tag {
282                _ => {
283                    _unknown_tagged_fields.push(field.clone());
284                },
285            }
286        }
287        Ok(Self {
288            name,
289            min_supported_version,
290            max_supported_version,
291            _unknown_tagged_fields,
292        })
293    }
294    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
295        write_compact_string(buf, &self.name)?;
296        write_i16(buf, self.min_supported_version);
297        write_i16(buf, self.max_supported_version);
298        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
299        all_tags.sort_by_key(|f| f.tag);
300        write_tagged_fields(buf, &all_tags)?;
301        Ok(())
302    }
303    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
304        let mut len: usize = 0;
305        len += compact_string_len(&self.name)?;
306        len += 2;
307        len += 2;
308        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
309        all_tags.sort_by_key(|f| f.tag);
310        len += tagged_fields_len(&all_tags)?;
311        Ok(len)
312    }
313}