kafka_wire_protocol/schema/broker_registration_request/
v3.rs

1// This file was generated. Do not edit.
2
3use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7#[cfg(test)] use proptest_derive::Arbitrary;
8
9use crate::arrays::{read_array, write_array};
10use crate::markers::{ApiMessage, Request};
11use crate::readable_writable::{Readable, Writable};
12use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
13#[cfg(test)] use crate::test_utils::proptest_strategies;
14
15/// BrokerRegistrationRequest, version 3.
16#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17#[cfg_attr(test, derive(Arbitrary))]
18pub struct BrokerRegistrationRequest {
19    /// The broker ID.
20    pub broker_id: i32,
21    /// The cluster id of the broker process.
22    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
23    pub cluster_id: String,
24    /// The incarnation id of the broker process.
25    #[cfg_attr(test, proptest(strategy = "proptest_strategies::uuid()"))]
26    pub incarnation_id: Uuid,
27    /// The listeners of this broker.
28    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
29    pub listeners: Vec<Listener>,
30    /// The features on this broker. Note: in v0-v3, features with MinSupportedVersion = 0 are omitted.
31    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
32    pub features: Vec<Feature>,
33    /// The rack which this broker is in.
34    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
35    pub rack: Option<String>,
36    /// If the required configurations for ZK migration are present, this value is set to true.
37    pub is_migrating_zk_broker: bool,
38    /// Log directories configured in this broker which are available.
39    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec_elem::<Uuid>(proptest_strategies::uuid())"))]
40    pub log_dirs: Vec<Uuid>,
41    /// The epoch before a clean shutdown.
42    pub previous_broker_epoch: i64,
43    /// Unknown tagged fields.
44    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
45    pub _unknown_tagged_fields: Vec<RawTaggedField>,
46}
47
48impl ApiMessage for BrokerRegistrationRequest {
49    fn api_key(&self) -> i16 {
50        62
51    }
52    
53    fn version(&self) -> i16 {
54        3
55    }
56}
57
58impl Request for BrokerRegistrationRequest { }
59
60impl Default for BrokerRegistrationRequest {
61    fn default() -> Self {
62        BrokerRegistrationRequest {
63            broker_id: 0_i32,
64            cluster_id: String::from(""),
65            incarnation_id: Uuid::nil(),
66            listeners: Vec::<Listener>::new(),
67            features: Vec::<Feature>::new(),
68            rack: Some(String::from("")),
69            is_migrating_zk_broker: false,
70            log_dirs: Vec::<Uuid>::new(),
71            previous_broker_epoch: -1_i64,
72            _unknown_tagged_fields: Vec::new(),
73        }
74    }
75}
76
77impl BrokerRegistrationRequest {
78    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(broker_id: i32, cluster_id: S1, incarnation_id: Uuid, listeners: Vec<Listener>, features: Vec<Feature>, rack: Option<S2>, is_migrating_zk_broker: bool, log_dirs: Vec<Uuid>, previous_broker_epoch: i64) -> Self {
79        Self {
80            broker_id,
81            cluster_id: cluster_id.as_ref().to_string(),
82            incarnation_id,
83            listeners,
84            features,
85            rack: rack.map(|s| s.as_ref().to_string()),
86            is_migrating_zk_broker,
87            log_dirs,
88            previous_broker_epoch,
89            _unknown_tagged_fields: vec![],
90        }
91    }
92}
93
94#[cfg(test)]
95mod tests_broker_registration_request_new_and_default {
96    use super::*;
97    
98    #[test]
99    fn test() {
100        let d = BrokerRegistrationRequest::new(
101            0_i32,
102            String::from(""),
103            Uuid::nil(),
104            Vec::<Listener>::new(),
105            Vec::<Feature>::new(),
106            Some(String::from("")),
107            false,
108            Vec::<Uuid>::new(),
109            -1_i64,
110        );
111        assert_eq!(d, BrokerRegistrationRequest::default());
112    }
113}
114
115impl Readable for BrokerRegistrationRequest {
116    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
117        let broker_id = i32::read(input)?;
118        let cluster_id = String::read_ext(input, "cluster_id", true)?;
119        let incarnation_id = Uuid::read(input)?;
120        let listeners = read_array::<Listener>(input, "listeners", true)?;
121        let features = read_array::<Feature>(input, "features", true)?;
122        let rack = Option::<String>::read_ext(input, "rack", true)?;
123        let is_migrating_zk_broker = bool::read(input)?;
124        let log_dirs = read_array::<Uuid>(input, "log_dirs", true)?;
125        let previous_broker_epoch = i64::read(input)?;
126        let tagged_fields_callback = |tag: i32, _: &[u8]| {
127            match tag {
128                _ => Ok(false)
129            }
130        };
131        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
132        Ok(BrokerRegistrationRequest {
133            broker_id, cluster_id, incarnation_id, listeners, features, rack, is_migrating_zk_broker, log_dirs, previous_broker_epoch, _unknown_tagged_fields
134        })
135    }
136}
137
138impl Writable for BrokerRegistrationRequest {
139    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
140        self.broker_id.write(output)?;
141        self.cluster_id.write_ext(output, "self.cluster_id", true)?;
142        self.incarnation_id.write(output)?;
143        write_array(output, "self.listeners", &self.listeners, true)?;
144        write_array(output, "self.features", &self.features, true)?;
145        self.rack.write_ext(output, "self.rack", true)?;
146        self.is_migrating_zk_broker.write(output)?;
147        write_array(output, "self.log_dirs", &self.log_dirs, true)?;
148        self.previous_broker_epoch.write(output)?;
149        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
150        Ok(())
151    }
152}
153
154/// Listener, version 3.
155#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
156#[cfg_attr(test, derive(Arbitrary))]
157pub struct Listener {
158    /// The name of the endpoint.
159    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
160    pub name: String,
161    /// The hostname.
162    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
163    pub host: String,
164    /// The port.
165    pub port: u16,
166    /// The security protocol.
167    pub security_protocol: i16,
168    /// Unknown tagged fields.
169    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
170    pub _unknown_tagged_fields: Vec<RawTaggedField>,
171}
172
173impl Default for Listener {
174    fn default() -> Self {
175        Listener {
176            name: String::from(""),
177            host: String::from(""),
178            port: 0_u16,
179            security_protocol: 0_i16,
180            _unknown_tagged_fields: Vec::new(),
181        }
182    }
183}
184
185impl Listener {
186    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(name: S1, host: S2, port: u16, security_protocol: i16) -> Self {
187        Self {
188            name: name.as_ref().to_string(),
189            host: host.as_ref().to_string(),
190            port,
191            security_protocol,
192            _unknown_tagged_fields: vec![],
193        }
194    }
195}
196
197#[cfg(test)]
198mod tests_listener_new_and_default {
199    use super::*;
200    
201    #[test]
202    fn test() {
203        let d = Listener::new(
204            String::from(""),
205            String::from(""),
206            0_u16,
207            0_i16,
208        );
209        assert_eq!(d, Listener::default());
210    }
211}
212
213impl Readable for Listener {
214    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
215        let name = String::read_ext(input, "name", true)?;
216        let host = String::read_ext(input, "host", true)?;
217        let port = u16::read(input)?;
218        let security_protocol = i16::read(input)?;
219        let tagged_fields_callback = |tag: i32, _: &[u8]| {
220            match tag {
221                _ => Ok(false)
222            }
223        };
224        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
225        Ok(Listener {
226            name, host, port, security_protocol, _unknown_tagged_fields
227        })
228    }
229}
230
231impl Writable for Listener {
232    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
233        self.name.write_ext(output, "self.name", true)?;
234        self.host.write_ext(output, "self.host", true)?;
235        self.port.write(output)?;
236        self.security_protocol.write(output)?;
237        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
238        Ok(())
239    }
240}
241
242/// Feature, version 3.
243#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
244#[cfg_attr(test, derive(Arbitrary))]
245pub struct Feature {
246    /// The feature name.
247    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
248    pub name: String,
249    /// The minimum supported feature level.
250    pub min_supported_version: i16,
251    /// The maximum supported feature level.
252    pub max_supported_version: i16,
253    /// Unknown tagged fields.
254    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
255    pub _unknown_tagged_fields: Vec<RawTaggedField>,
256}
257
258impl Default for Feature {
259    fn default() -> Self {
260        Feature {
261            name: String::from(""),
262            min_supported_version: 0_i16,
263            max_supported_version: 0_i16,
264            _unknown_tagged_fields: Vec::new(),
265        }
266    }
267}
268
269impl Feature {
270    pub fn new<S1: AsRef<str>>(name: S1, min_supported_version: i16, max_supported_version: i16) -> Self {
271        Self {
272            name: name.as_ref().to_string(),
273            min_supported_version,
274            max_supported_version,
275            _unknown_tagged_fields: vec![],
276        }
277    }
278}
279
280#[cfg(test)]
281mod tests_feature_new_and_default {
282    use super::*;
283    
284    #[test]
285    fn test() {
286        let d = Feature::new(
287            String::from(""),
288            0_i16,
289            0_i16,
290        );
291        assert_eq!(d, Feature::default());
292    }
293}
294
295impl Readable for Feature {
296    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
297        let name = String::read_ext(input, "name", true)?;
298        let min_supported_version = i16::read(input)?;
299        let max_supported_version = i16::read(input)?;
300        let tagged_fields_callback = |tag: i32, _: &[u8]| {
301            match tag {
302                _ => Ok(false)
303            }
304        };
305        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
306        Ok(Feature {
307            name, min_supported_version, max_supported_version, _unknown_tagged_fields
308        })
309    }
310}
311
312impl Writable for Feature {
313    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
314        self.name.write_ext(output, "self.name", true)?;
315        self.min_supported_version.write(output)?;
316        self.max_supported_version.write(output)?;
317        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
318        Ok(())
319    }
320}
321
322#[cfg(test)]
323mod tests {
324    use super::*;
325    use proptest::prelude::*;
326    
327    #[test]
328    fn test_java_default() {
329        crate::test_utils::test_java_default::<BrokerRegistrationRequest>("BrokerRegistrationRequest", 3);
330    }
331    
332    proptest! {
333        #[test]
334        fn test_serde(data: BrokerRegistrationRequest) {
335            crate::test_utils::test_serde(&data)?;
336        }
337    }
338    
339    proptest! {
340        #[test]
341        fn test_java_arbitrary(data: BrokerRegistrationRequest) {
342            crate::test_utils::test_java_arbitrary(&data, "BrokerRegistrationRequest", 3);
343        }
344    }
345}