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