Skip to main content

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

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