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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i64, get_u16, put_bool, put_i16, put_i32, put_i64, put_u16};
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,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 62;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 4;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct BrokerRegistrationRequest {
25    pub broker_id: i32,
26    pub cluster_id: String,
27    pub incarnation_id: crate::primitives::uuid::Uuid,
28    pub listeners: Vec<Listener>,
29    pub features: Vec<Feature>,
30    pub rack: Option<String>,
31    pub is_migrating_zk_broker: bool,
32    pub log_dirs: Vec<crate::primitives::uuid::Uuid>,
33    pub previous_broker_epoch: i64,
34    pub unknown_tagged_fields: UnknownTaggedFields,
35}
36
37impl Default for BrokerRegistrationRequest {
38    fn default() -> Self {
39        Self {
40            broker_id: 0i32,
41            cluster_id: String::new(),
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}
53
54impl Encode for BrokerRegistrationRequest {
55    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
56        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
58        }
59        let flex = is_flexible(version);
60        if version >= 0 { put_i32(buf, self.broker_id) }
61        if version >= 0 { if flex { put_compact_string(buf, &self.cluster_id) } else { put_string(buf, &self.cluster_id) } }
62        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.incarnation_id) }
63        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex); for it in &self.listeners { it.encode(buf, version)?; } } }
64        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.features).len(), flex); for it in &self.features { it.encode(buf, version)?; } } }
65        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack.as_deref()) } else { put_nullable_string(buf, self.rack.as_deref()) } }
66        if version >= 1 { put_bool(buf, self.is_migrating_zk_broker) }
67        if version >= 2 { { crate::primitives::array::put_array_len(buf, (self.log_dirs).len(), flex); for it in &self.log_dirs { crate::primitives::uuid::put_uuid(buf, *it); } } }
68        if version >= 3 { put_i64(buf, self.previous_broker_epoch) }
69        if flex {
70            let tagged = WriteTaggedFields::new();
71            tagged.write(buf, &self.unknown_tagged_fields);
72        }
73        Ok(())
74    }
75    fn encoded_len(&self, version: i16) -> usize {
76        let flex = is_flexible(version);
77        let mut n: usize = 0;
78        if version >= 0 { n += 4; }
79        if version >= 0 { n += if flex { compact_string_len(&self.cluster_id) } else { string_len(&self.cluster_id) }; }
80        if version >= 0 { n += 16; }
81        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex); let body: usize = (self.listeners).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
82        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.features).len(), flex); let body: usize = (self.features).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
83        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack.as_deref()) } else { nullable_string_len(self.rack.as_deref()) }; }
84        if version >= 1 { n += 1; }
85        if version >= 2 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.log_dirs).len(), flex); let body: usize = (self.log_dirs).iter().map(|_| 16).sum(); prefix + body }; }
86        if version >= 3 { n += 8; }
87        if flex {
88            let known_pairs: Vec<(u32, usize)> = Vec::new();
89            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
90        }
91        n
92    }
93}
94
95impl<'de> Decode<'de> for BrokerRegistrationRequest {
96    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
97        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
99        }
100        let flex = is_flexible(version);
101        let mut out = Self::default();
102        if version >= 0 { out.broker_id = get_i32(buf)?; }
103        if version >= 0 { out.cluster_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
104        if version >= 0 { out.incarnation_id = crate::primitives::uuid::get_uuid(buf)?; }
105        if version >= 0 { out.listeners = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Listener::decode(buf, version)?); } v }; }
106        if version >= 0 { out.features = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Feature::decode(buf, version)?); } v }; }
107        if version >= 0 { out.rack = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
108        if version >= 1 { out.is_migrating_zk_broker = get_bool(buf)?; }
109        if version >= 2 { out.log_dirs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(crate::primitives::uuid::get_uuid(buf)?); } v }; }
110        if version >= 3 { out.previous_broker_epoch = get_i64(buf)?; }
111        if flex {
112            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
113                Ok(false)
114            })?;
115        }
116        Ok(out)
117    }
118}
119
120#[derive(Debug, Clone, PartialEq, Eq, Default)]
121pub struct Listener {
122    pub name: String,
123    pub host: String,
124    pub port: u16,
125    pub security_protocol: i16,
126    pub unknown_tagged_fields: UnknownTaggedFields,
127}
128
129impl Encode for Listener {
130    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
131        let flex = version >= 0;
132        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
133        if version >= 0 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
134        if version >= 0 { put_u16(buf, self.port) }
135        if version >= 0 { put_i16(buf, self.security_protocol) }
136        if flex {
137            let tagged = WriteTaggedFields::new();
138            tagged.write(buf, &self.unknown_tagged_fields);
139        }
140        Ok(())
141    }
142    fn encoded_len(&self, version: i16) -> usize {
143        let flex = version >= 0;
144        let mut n: usize = 0;
145        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
146        if version >= 0 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
147        if version >= 0 { n += 2; }
148        if version >= 0 { n += 2; }
149        if flex {
150            let known_pairs: Vec<(u32, usize)> = Vec::new();
151            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
152        }
153        n
154    }
155}
156
157impl<'de> Decode<'de> for Listener {
158    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
159        let flex = version >= 0;
160        let mut out = Self::default();
161        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
162        if version >= 0 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
163        if version >= 0 { out.port = get_u16(buf)?; }
164        if version >= 0 { out.security_protocol = get_i16(buf)?; }
165        if flex {
166            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
167                Ok(false)
168            })?;
169        }
170        Ok(out)
171    }
172}
173
174#[derive(Debug, Clone, PartialEq, Eq, Default)]
175pub struct Feature {
176    pub name: String,
177    pub min_supported_version: i16,
178    pub max_supported_version: i16,
179    pub unknown_tagged_fields: UnknownTaggedFields,
180}
181
182impl Encode for Feature {
183    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184        let flex = version >= 0;
185        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
186        if version >= 0 { put_i16(buf, self.min_supported_version) }
187        if version >= 0 { put_i16(buf, self.max_supported_version) }
188        if flex {
189            let tagged = WriteTaggedFields::new();
190            tagged.write(buf, &self.unknown_tagged_fields);
191        }
192        Ok(())
193    }
194    fn encoded_len(&self, version: i16) -> usize {
195        let flex = version >= 0;
196        let mut n: usize = 0;
197        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
198        if version >= 0 { n += 2; }
199        if version >= 0 { n += 2; }
200        if flex {
201            let known_pairs: Vec<(u32, usize)> = Vec::new();
202            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
203        }
204        n
205    }
206}
207
208impl<'de> Decode<'de> for Feature {
209    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
210        let flex = version >= 0;
211        let mut out = Self::default();
212        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
213        if version >= 0 { out.min_supported_version = get_i16(buf)?; }
214        if version >= 0 { out.max_supported_version = get_i16(buf)?; }
215        if flex {
216            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
217                Ok(false)
218            })?;
219        }
220        Ok(out)
221    }
222}
223
224/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
225/// Only includes fields valid for the given version.
226#[must_use]
227#[allow(unused_comparisons)]
228pub fn default_json(version: i16) -> ::serde_json::Value {
229    let mut obj = ::serde_json::Map::new();
230    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
231    obj.insert("clusterId".to_string(), ::serde_json::Value::String(String::new()));
232    obj.insert("incarnationId".to_string(), ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()));
233    obj.insert("listeners".to_string(), ::serde_json::Value::Array(vec![]));
234    obj.insert("features".to_string(), ::serde_json::Value::Array(vec![]));
235    obj.insert("rack".to_string(), ::serde_json::Value::Null);
236    if version >= 1 {
237        obj.insert("isMigratingZkBroker".to_string(), ::serde_json::Value::Bool(false));
238    }
239    if version >= 2 {
240        obj.insert("logDirs".to_string(), ::serde_json::Value::Array(vec![]));
241    }
242    if version >= 3 {
243        obj.insert("previousBrokerEpoch".to_string(), ::serde_json::json!(-1));
244    }
245    ::serde_json::Value::Object(obj)
246}
247
248impl crate::ProtocolRequest for BrokerRegistrationRequest {
249    const API_KEY: i16 = API_KEY;
250    const MIN_VERSION: i16 = MIN_VERSION;
251    const MAX_VERSION: i16 = MAX_VERSION;
252    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
253    type Response = super::broker_registration_response::BrokerRegistrationResponse;
254}