Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
BrokerRegistrationRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{
3    get_bool, get_i16, get_i32, get_i64, get_u16, put_bool, put_i16, put_i32, put_i64, put_u16,
4};
5use crate::primitives::string_bytes::{
6    compact_nullable_string_len, compact_string_len, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
11    get_nullable_string_borrowed, get_string_borrowed,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
15use bytes::BufMut;
16pub const API_KEY: i16 = 62;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 4;
19pub const FLEXIBLE_MIN: i16 = 0;
20#[inline]
21fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct BrokerRegistrationRequest<'a> {
26    pub broker_id: i32,
27    pub cluster_id: &'a str,
28    pub incarnation_id: crate::primitives::uuid::Uuid,
29    pub listeners: Vec<Listener<'a>>,
30    pub features: Vec<Feature<'a>>,
31    pub rack: Option<&'a str>,
32    pub is_migrating_zk_broker: bool,
33    pub log_dirs: Vec<crate::primitives::uuid::Uuid>,
34    pub previous_broker_epoch: i64,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for BrokerRegistrationRequest<'_> {
38    fn default() -> Self {
39        Self {
40            broker_id: 0i32,
41            cluster_id: "",
42            incarnation_id: Default::default(),
43            listeners: Vec::new(),
44            features: Vec::new(),
45            rack: None,
46            is_migrating_zk_broker: false,
47            log_dirs: Vec::new(),
48            previous_broker_epoch: -1i64,
49            unknown_tagged_fields: Default::default(),
50        }
51    }
52}
53impl BrokerRegistrationRequest<'_> {
54    pub fn to_owned(&self) -> crate::owned::broker_registration_request::BrokerRegistrationRequest {
55        crate::owned::broker_registration_request::BrokerRegistrationRequest {
56            broker_id: (self.broker_id),
57            cluster_id: (self.cluster_id).to_string(),
58            incarnation_id: (self.incarnation_id),
59            listeners: (self.listeners).iter().map(Listener::to_owned).collect(),
60            features: (self.features).iter().map(Feature::to_owned).collect(),
61            rack: (self.rack).map(std::string::ToString::to_string),
62            is_migrating_zk_broker: (self.is_migrating_zk_broker),
63            log_dirs: (self.log_dirs).clone(),
64            previous_broker_epoch: (self.previous_broker_epoch),
65            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
66        }
67    }
68}
69impl Encode for BrokerRegistrationRequest<'_> {
70    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
71        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
72            return Err(ProtocolError::UnsupportedVersion {
73                api_key: API_KEY,
74                version,
75            });
76        }
77        let flex = is_flexible(version);
78        if version >= 0 {
79            put_i32(buf, self.broker_id);
80        }
81        if version >= 0 {
82            if flex {
83                put_compact_string(buf, self.cluster_id);
84            } else {
85                put_string(buf, self.cluster_id);
86            }
87        }
88        if version >= 0 {
89            crate::primitives::uuid::put_uuid(buf, self.incarnation_id);
90        }
91        if version >= 0 {
92            {
93                crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex);
94                for it in &self.listeners {
95                    it.encode(buf, version)?;
96                }
97            }
98        }
99        if version >= 0 {
100            {
101                crate::primitives::array::put_array_len(buf, (self.features).len(), flex);
102                for it in &self.features {
103                    it.encode(buf, version)?;
104                }
105            }
106        }
107        if version >= 0 {
108            if flex {
109                put_compact_nullable_string(buf, self.rack);
110            } else {
111                put_nullable_string(buf, self.rack);
112            }
113        }
114        if version >= 1 {
115            put_bool(buf, self.is_migrating_zk_broker);
116        }
117        if version >= 2 {
118            {
119                crate::primitives::array::put_array_len(buf, (self.log_dirs).len(), flex);
120                for it in &self.log_dirs {
121                    crate::primitives::uuid::put_uuid(buf, *it);
122                }
123            }
124        }
125        if version >= 3 {
126            put_i64(buf, self.previous_broker_epoch);
127        }
128        if flex {
129            let tagged = WriteTaggedFields::new();
130            tagged.write(buf, &self.unknown_tagged_fields);
131        }
132        Ok(())
133    }
134    fn encoded_len(&self, version: i16) -> usize {
135        let flex = is_flexible(version);
136        let mut n: usize = 0;
137        if version >= 0 {
138            n += 4;
139        }
140        if version >= 0 {
141            n += if flex {
142                compact_string_len(self.cluster_id)
143            } else {
144                string_len(self.cluster_id)
145            };
146        }
147        if version >= 0 {
148            n += 16;
149        }
150        if version >= 0 {
151            n += {
152                let prefix =
153                    crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex);
154                let body: usize = (self.listeners)
155                    .iter()
156                    .map(|it| it.encoded_len(version))
157                    .sum();
158                prefix + body
159            };
160        }
161        if version >= 0 {
162            n += {
163                let prefix =
164                    crate::primitives::array::array_len_prefix_len((self.features).len(), flex);
165                let body: usize = (self.features)
166                    .iter()
167                    .map(|it| it.encoded_len(version))
168                    .sum();
169                prefix + body
170            };
171        }
172        if version >= 0 {
173            n += if flex {
174                compact_nullable_string_len(self.rack)
175            } else {
176                nullable_string_len(self.rack)
177            };
178        }
179        if version >= 1 {
180            n += 1;
181        }
182        if version >= 2 {
183            n += {
184                let prefix =
185                    crate::primitives::array::array_len_prefix_len((self.log_dirs).len(), flex);
186                let body: usize = (self.log_dirs).iter().map(|_| 16).sum();
187                prefix + body
188            };
189        }
190        if version >= 3 {
191            n += 8;
192        }
193        if flex {
194            let known_pairs: Vec<(u32, usize)> = Vec::new();
195            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196        }
197        n
198    }
199}
200impl<'de> DecodeBorrow<'de> for BrokerRegistrationRequest<'de> {
201    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
202        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
203            return Err(ProtocolError::UnsupportedVersion {
204                api_key: API_KEY,
205                version,
206            });
207        }
208        let flex = is_flexible(version);
209        let mut out = Self::default();
210        if version >= 0 {
211            out.broker_id = get_i32(buf)?;
212        }
213        if version >= 0 {
214            out.cluster_id = if flex {
215                get_compact_string_borrowed(buf)?
216            } else {
217                get_string_borrowed(buf)?
218            };
219        }
220        if version >= 0 {
221            out.incarnation_id = crate::primitives::uuid::get_uuid(buf)?;
222        }
223        if version >= 0 {
224            out.listeners = {
225                let n = crate::primitives::array::get_array_len(buf, flex)?;
226                let mut v = Vec::with_capacity(n);
227                for _ in 0..n {
228                    v.push(Listener::decode_borrow(buf, version)?);
229                }
230                v
231            };
232        }
233        if version >= 0 {
234            out.features = {
235                let n = crate::primitives::array::get_array_len(buf, flex)?;
236                let mut v = Vec::with_capacity(n);
237                for _ in 0..n {
238                    v.push(Feature::decode_borrow(buf, version)?);
239                }
240                v
241            };
242        }
243        if version >= 0 {
244            out.rack = if flex {
245                get_compact_nullable_string_borrowed(buf)?
246            } else {
247                get_nullable_string_borrowed(buf)?
248            };
249        }
250        if version >= 1 {
251            out.is_migrating_zk_broker = get_bool(buf)?;
252        }
253        if version >= 2 {
254            out.log_dirs = {
255                let n = crate::primitives::array::get_array_len(buf, flex)?;
256                let mut v = Vec::with_capacity(n);
257                for _ in 0..n {
258                    v.push(crate::primitives::uuid::get_uuid(buf)?);
259                }
260                v
261            };
262        }
263        if version >= 3 {
264            out.previous_broker_epoch = get_i64(buf)?;
265        }
266        if flex {
267            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
268        }
269        Ok(out)
270    }
271}
272#[cfg(test)]
273impl BrokerRegistrationRequest<'_> {
274    #[must_use]
275    pub fn populated(version: i16) -> Self {
276        let mut m = Self::default();
277        if version >= 0 {
278            m.broker_id = 1i32;
279        }
280        if version >= 0 {
281            m.cluster_id = "x";
282        }
283        if version >= 0 {
284            m.incarnation_id = crate::primitives::uuid::Uuid([1u8; 16]);
285        }
286        if version >= 0 {
287            m.listeners = vec![Listener::populated(version)];
288        }
289        if version >= 0 {
290            m.features = vec![Feature::populated(version)];
291        }
292        if version >= 0 {
293            m.rack = Some("x");
294        }
295        if version >= 1 {
296            m.is_migrating_zk_broker = true;
297        }
298        if version >= 2 {
299            m.log_dirs = vec![crate::primitives::uuid::Uuid([1u8; 16])];
300        }
301        if version >= 3 {
302            m.previous_broker_epoch = 1i64;
303        }
304        m
305    }
306}
307#[derive(Debug, Clone, PartialEq, Eq, Default)]
308pub struct Listener<'a> {
309    pub name: &'a str,
310    pub host: &'a str,
311    pub port: u16,
312    pub security_protocol: i16,
313    pub unknown_tagged_fields: UnknownTaggedFields,
314}
315impl Listener<'_> {
316    pub fn to_owned(&self) -> crate::owned::broker_registration_request::Listener {
317        crate::owned::broker_registration_request::Listener {
318            name: (self.name).to_string(),
319            host: (self.host).to_string(),
320            port: (self.port),
321            security_protocol: (self.security_protocol),
322            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
323        }
324    }
325}
326impl Encode for Listener<'_> {
327    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
328        let flex = version >= 0;
329        if version >= 0 {
330            if flex {
331                put_compact_string(buf, self.name);
332            } else {
333                put_string(buf, self.name);
334            }
335        }
336        if version >= 0 {
337            if flex {
338                put_compact_string(buf, self.host);
339            } else {
340                put_string(buf, self.host);
341            }
342        }
343        if version >= 0 {
344            put_u16(buf, self.port);
345        }
346        if version >= 0 {
347            put_i16(buf, self.security_protocol);
348        }
349        if flex {
350            let tagged = WriteTaggedFields::new();
351            tagged.write(buf, &self.unknown_tagged_fields);
352        }
353        Ok(())
354    }
355    fn encoded_len(&self, version: i16) -> usize {
356        let flex = version >= 0;
357        let mut n: usize = 0;
358        if version >= 0 {
359            n += if flex {
360                compact_string_len(self.name)
361            } else {
362                string_len(self.name)
363            };
364        }
365        if version >= 0 {
366            n += if flex {
367                compact_string_len(self.host)
368            } else {
369                string_len(self.host)
370            };
371        }
372        if version >= 0 {
373            n += 2;
374        }
375        if version >= 0 {
376            n += 2;
377        }
378        if flex {
379            let known_pairs: Vec<(u32, usize)> = Vec::new();
380            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
381        }
382        n
383    }
384}
385impl<'de> DecodeBorrow<'de> for Listener<'de> {
386    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
387        let flex = version >= 0;
388        let mut out = Self::default();
389        if version >= 0 {
390            out.name = if flex {
391                get_compact_string_borrowed(buf)?
392            } else {
393                get_string_borrowed(buf)?
394            };
395        }
396        if version >= 0 {
397            out.host = if flex {
398                get_compact_string_borrowed(buf)?
399            } else {
400                get_string_borrowed(buf)?
401            };
402        }
403        if version >= 0 {
404            out.port = get_u16(buf)?;
405        }
406        if version >= 0 {
407            out.security_protocol = get_i16(buf)?;
408        }
409        if flex {
410            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
411        }
412        Ok(out)
413    }
414}
415#[cfg(test)]
416impl Listener<'_> {
417    #[must_use]
418    pub fn populated(version: i16) -> Self {
419        let mut m = Self::default();
420        if version >= 0 {
421            m.name = "x";
422        }
423        if version >= 0 {
424            m.host = "x";
425        }
426        if version >= 0 {
427            m.port = 1u16;
428        }
429        if version >= 0 {
430            m.security_protocol = 1i16;
431        }
432        m
433    }
434}
435#[derive(Debug, Clone, PartialEq, Eq, Default)]
436pub struct Feature<'a> {
437    pub name: &'a str,
438    pub min_supported_version: i16,
439    pub max_supported_version: i16,
440    pub unknown_tagged_fields: UnknownTaggedFields,
441}
442impl Feature<'_> {
443    pub fn to_owned(&self) -> crate::owned::broker_registration_request::Feature {
444        crate::owned::broker_registration_request::Feature {
445            name: (self.name).to_string(),
446            min_supported_version: (self.min_supported_version),
447            max_supported_version: (self.max_supported_version),
448            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
449        }
450    }
451}
452impl Encode for Feature<'_> {
453    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
454        let flex = version >= 0;
455        if version >= 0 {
456            if flex {
457                put_compact_string(buf, self.name);
458            } else {
459                put_string(buf, self.name);
460            }
461        }
462        if version >= 0 {
463            put_i16(buf, self.min_supported_version);
464        }
465        if version >= 0 {
466            put_i16(buf, self.max_supported_version);
467        }
468        if flex {
469            let tagged = WriteTaggedFields::new();
470            tagged.write(buf, &self.unknown_tagged_fields);
471        }
472        Ok(())
473    }
474    fn encoded_len(&self, version: i16) -> usize {
475        let flex = version >= 0;
476        let mut n: usize = 0;
477        if version >= 0 {
478            n += if flex {
479                compact_string_len(self.name)
480            } else {
481                string_len(self.name)
482            };
483        }
484        if version >= 0 {
485            n += 2;
486        }
487        if version >= 0 {
488            n += 2;
489        }
490        if flex {
491            let known_pairs: Vec<(u32, usize)> = Vec::new();
492            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
493        }
494        n
495    }
496}
497impl<'de> DecodeBorrow<'de> for Feature<'de> {
498    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
499        let flex = version >= 0;
500        let mut out = Self::default();
501        if version >= 0 {
502            out.name = if flex {
503                get_compact_string_borrowed(buf)?
504            } else {
505                get_string_borrowed(buf)?
506            };
507        }
508        if version >= 0 {
509            out.min_supported_version = get_i16(buf)?;
510        }
511        if version >= 0 {
512            out.max_supported_version = get_i16(buf)?;
513        }
514        if flex {
515            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
516        }
517        Ok(out)
518    }
519}
520#[cfg(test)]
521impl Feature<'_> {
522    #[must_use]
523    pub fn populated(version: i16) -> Self {
524        let mut m = Self::default();
525        if version >= 0 {
526            m.name = "x";
527        }
528        if version >= 0 {
529            m.min_supported_version = 1i16;
530        }
531        if version >= 0 {
532            m.max_supported_version = 1i16;
533        }
534        m
535    }
536}