krabka_protocol/opt/rustwide/workdir/generated/
ControllerRegistrationRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_bool, get_i16, get_i32, get_u16, put_bool, put_i16, put_i32, put_u16},
8 string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9 string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10 },
11 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 70;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const LATEST_STABLE_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ControllerRegistrationRequest<'a> {
25 pub controller_id: i32,
26 pub incarnation_id: crate::primitives::uuid::Uuid,
27 pub zk_migration_ready: bool,
28 pub listeners: Vec<Listener<'a>>,
29 pub features: Vec<Feature<'a>>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl ControllerRegistrationRequest<'_> {
33 #[must_use]
37 pub fn to_owned(
38 &self,
39 ) -> crate::owned::controller_registration_request::ControllerRegistrationRequest {
40 crate::owned::controller_registration_request::ControllerRegistrationRequest {
41 controller_id: (self.controller_id),
42 incarnation_id: (self.incarnation_id),
43 zk_migration_ready: (self.zk_migration_ready),
44 listeners: (self.listeners).iter().map(Listener::to_owned).collect(),
45 features: (self.features).iter().map(Feature::to_owned).collect(),
46 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
47 }
48 }
49}
50impl Encode for ControllerRegistrationRequest<'_> {
51 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53 return Err(ProtocolError::UnsupportedVersion {
54 api_key: API_KEY,
55 version,
56 });
57 }
58 let flex = is_flexible(version);
59 if version >= 0 {
60 put_i32(buf, self.controller_id);
61 }
62 if version >= 0 {
63 crate::primitives::uuid::put_uuid(buf, self.incarnation_id);
64 }
65 if version >= 0 {
66 put_bool(buf, self.zk_migration_ready);
67 }
68 if version >= 0 {
69 {
70 crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex);
71 for it in &self.listeners {
72 it.encode(buf, version)?;
73 }
74 };
75 }
76 if version >= 0 {
77 {
78 crate::primitives::array::put_array_len(buf, (self.features).len(), flex);
79 for it in &self.features {
80 it.encode(buf, version)?;
81 }
82 };
83 }
84 if flex {
85 let tagged = WriteTaggedFields::new();
86 tagged.write(buf, &self.unknown_tagged_fields);
87 }
88 Ok(())
89 }
90 fn encoded_len(&self, version: i16) -> usize {
91 let flex = is_flexible(version);
92 let mut n: usize = 0;
93 if version >= 0 {
94 n += 4;
95 }
96 if version >= 0 {
97 n += 16;
98 }
99 if version >= 0 {
100 n += 1;
101 }
102 if version >= 0 {
103 n += {
104 let prefix =
105 crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex);
106 let body: usize = (self.listeners)
107 .iter()
108 .map(|it| it.encoded_len(version))
109 .sum();
110 prefix + body
111 };
112 }
113 if version >= 0 {
114 n += {
115 let prefix =
116 crate::primitives::array::array_len_prefix_len((self.features).len(), flex);
117 let body: usize = (self.features)
118 .iter()
119 .map(|it| it.encoded_len(version))
120 .sum();
121 prefix + body
122 };
123 }
124 if flex {
125 let known_pairs: Vec<(u32, usize)> = Vec::new();
126 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
127 }
128 n
129 }
130}
131impl<'de> DecodeBorrow<'de> for ControllerRegistrationRequest<'de> {
132 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
133 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
134 return Err(ProtocolError::UnsupportedVersion {
135 api_key: API_KEY,
136 version,
137 });
138 }
139 let flex = is_flexible(version);
140 let mut out = Self::default();
141 if version >= 0 {
142 out.controller_id = get_i32(buf)?;
143 }
144 if version >= 0 {
145 out.incarnation_id = crate::primitives::uuid::get_uuid(buf)?;
146 }
147 if version >= 0 {
148 out.zk_migration_ready = get_bool(buf)?;
149 }
150 if version >= 0 {
151 out.listeners = {
152 let n = crate::primitives::array::get_array_len(buf, flex)?;
153 let mut v = Vec::with_capacity(n);
154 for _ in 0..n {
155 v.push(Listener::decode_borrow(buf, version)?);
156 }
157 v
158 };
159 }
160 if version >= 0 {
161 out.features = {
162 let n = crate::primitives::array::get_array_len(buf, flex)?;
163 let mut v = Vec::with_capacity(n);
164 for _ in 0..n {
165 v.push(Feature::decode_borrow(buf, version)?);
166 }
167 v
168 };
169 }
170 if flex {
171 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
172 }
173 Ok(out)
174 }
175}
176#[cfg(test)]
177impl ControllerRegistrationRequest<'_> {
178 #[must_use]
179 pub fn populated(version: i16) -> Self {
180 let mut m = Self::default();
181 if version >= 0 {
182 m.controller_id = 1i32;
183 }
184 if version >= 0 {
185 m.incarnation_id = crate::primitives::uuid::Uuid([1u8; 16]);
186 }
187 if version >= 0 {
188 m.zk_migration_ready = true;
189 }
190 if version >= 0 {
191 m.listeners = vec![Listener::populated(version)];
192 }
193 if version >= 0 {
194 m.features = vec![Feature::populated(version)];
195 }
196 m
197 }
198}
199#[derive(Debug, Clone, PartialEq, Eq, Default)]
200pub struct Listener<'a> {
201 pub name: &'a str,
202 pub host: &'a str,
203 pub port: u16,
204 pub security_protocol: i16,
205 pub unknown_tagged_fields: UnknownTaggedFields,
206}
207impl Listener<'_> {
208 #[must_use]
212 pub fn to_owned(&self) -> crate::owned::controller_registration_request::Listener {
213 crate::owned::controller_registration_request::Listener {
214 name: (self.name).to_string(),
215 host: (self.host).to_string(),
216 port: (self.port),
217 security_protocol: (self.security_protocol),
218 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
219 }
220 }
221}
222impl Encode for Listener<'_> {
223 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
224 let flex = version >= 0;
225 if version >= 0 {
226 if flex {
227 let () = put_compact_string(buf, self.name);
228 } else {
229 let () = put_string(buf, self.name);
230 }
231 }
232 if version >= 0 {
233 if flex {
234 let () = put_compact_string(buf, self.host);
235 } else {
236 let () = put_string(buf, self.host);
237 }
238 }
239 if version >= 0 {
240 put_u16(buf, self.port);
241 }
242 if version >= 0 {
243 put_i16(buf, self.security_protocol);
244 }
245 if flex {
246 let tagged = WriteTaggedFields::new();
247 tagged.write(buf, &self.unknown_tagged_fields);
248 }
249 Ok(())
250 }
251 fn encoded_len(&self, version: i16) -> usize {
252 let flex = version >= 0;
253 let mut n: usize = 0;
254 if version >= 0 {
255 n += if flex {
256 compact_string_len(self.name)
257 } else {
258 string_len(self.name)
259 };
260 }
261 if version >= 0 {
262 n += if flex {
263 compact_string_len(self.host)
264 } else {
265 string_len(self.host)
266 };
267 }
268 if version >= 0 {
269 n += 2;
270 }
271 if version >= 0 {
272 n += 2;
273 }
274 if flex {
275 let known_pairs: Vec<(u32, usize)> = Vec::new();
276 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
277 }
278 n
279 }
280}
281impl<'de> DecodeBorrow<'de> for Listener<'de> {
282 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
283 let flex = version >= 0;
284 let mut out = Self::default();
285 if version >= 0 {
286 out.name = if flex {
287 get_compact_string_borrowed(buf)?
288 } else {
289 get_string_borrowed(buf)?
290 };
291 }
292 if version >= 0 {
293 out.host = if flex {
294 get_compact_string_borrowed(buf)?
295 } else {
296 get_string_borrowed(buf)?
297 };
298 }
299 if version >= 0 {
300 out.port = get_u16(buf)?;
301 }
302 if version >= 0 {
303 out.security_protocol = get_i16(buf)?;
304 }
305 if flex {
306 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
307 }
308 Ok(out)
309 }
310}
311#[cfg(test)]
312impl Listener<'_> {
313 #[must_use]
314 pub fn populated(version: i16) -> Self {
315 let mut m = Self::default();
316 if version >= 0 {
317 m.name = "x";
318 }
319 if version >= 0 {
320 m.host = "x";
321 }
322 if version >= 0 {
323 m.port = 1u16;
324 }
325 if version >= 0 {
326 m.security_protocol = 1i16;
327 }
328 m
329 }
330}
331#[derive(Debug, Clone, PartialEq, Eq, Default)]
332pub struct Feature<'a> {
333 pub name: &'a str,
334 pub min_supported_version: i16,
335 pub max_supported_version: i16,
336 pub unknown_tagged_fields: UnknownTaggedFields,
337}
338impl Feature<'_> {
339 #[must_use]
343 pub fn to_owned(&self) -> crate::owned::controller_registration_request::Feature {
344 crate::owned::controller_registration_request::Feature {
345 name: (self.name).to_string(),
346 min_supported_version: (self.min_supported_version),
347 max_supported_version: (self.max_supported_version),
348 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
349 }
350 }
351}
352impl Encode for Feature<'_> {
353 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
354 let flex = version >= 0;
355 if version >= 0 {
356 if flex {
357 let () = put_compact_string(buf, self.name);
358 } else {
359 let () = put_string(buf, self.name);
360 }
361 }
362 if version >= 0 {
363 put_i16(buf, self.min_supported_version);
364 }
365 if version >= 0 {
366 put_i16(buf, self.max_supported_version);
367 }
368 if flex {
369 let tagged = WriteTaggedFields::new();
370 tagged.write(buf, &self.unknown_tagged_fields);
371 }
372 Ok(())
373 }
374 fn encoded_len(&self, version: i16) -> usize {
375 let flex = version >= 0;
376 let mut n: usize = 0;
377 if version >= 0 {
378 n += if flex {
379 compact_string_len(self.name)
380 } else {
381 string_len(self.name)
382 };
383 }
384 if version >= 0 {
385 n += 2;
386 }
387 if version >= 0 {
388 n += 2;
389 }
390 if flex {
391 let known_pairs: Vec<(u32, usize)> = Vec::new();
392 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
393 }
394 n
395 }
396}
397impl<'de> DecodeBorrow<'de> for Feature<'de> {
398 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
399 let flex = version >= 0;
400 let mut out = Self::default();
401 if version >= 0 {
402 out.name = if flex {
403 get_compact_string_borrowed(buf)?
404 } else {
405 get_string_borrowed(buf)?
406 };
407 }
408 if version >= 0 {
409 out.min_supported_version = get_i16(buf)?;
410 }
411 if version >= 0 {
412 out.max_supported_version = 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 Feature<'_> {
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.min_supported_version = 1i16;
430 }
431 if version >= 0 {
432 m.max_supported_version = 1i16;
433 }
434 m
435 }
436}