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