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