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