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