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