crabka_protocol/opt/rustwide/workdir/generated/
ControllerRegistrationRequest.owned.rs1use crate::primitives::fixed::{
4 get_bool, get_i16, get_i32, get_u16, put_bool, put_i16, put_i32, put_u16,
5};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8 string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12use bytes::{Buf, BufMut};
13pub const API_KEY: i16 = 70;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17#[inline]
18fn is_flexible(version: i16) -> bool {
19 version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ControllerRegistrationRequest {
23 pub controller_id: i32,
24 pub incarnation_id: crate::primitives::uuid::Uuid,
25 pub zk_migration_ready: bool,
26 pub listeners: Vec<Listener>,
27 pub features: Vec<Feature>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for ControllerRegistrationRequest {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion {
34 api_key: API_KEY,
35 version,
36 });
37 }
38 let flex = is_flexible(version);
39 if version >= 0 {
40 put_i32(buf, self.controller_id);
41 }
42 if version >= 0 {
43 crate::primitives::uuid::put_uuid(buf, self.incarnation_id);
44 }
45 if version >= 0 {
46 put_bool(buf, self.zk_migration_ready);
47 }
48 if version >= 0 {
49 {
50 crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex);
51 for it in &self.listeners {
52 it.encode(buf, version)?;
53 }
54 }
55 }
56 if version >= 0 {
57 {
58 crate::primitives::array::put_array_len(buf, (self.features).len(), flex);
59 for it in &self.features {
60 it.encode(buf, version)?;
61 }
62 }
63 }
64 if flex {
65 let tagged = WriteTaggedFields::new();
66 tagged.write(buf, &self.unknown_tagged_fields);
67 }
68 Ok(())
69 }
70 fn encoded_len(&self, version: i16) -> usize {
71 let flex = is_flexible(version);
72 let mut n: usize = 0;
73 if version >= 0 {
74 n += 4;
75 }
76 if version >= 0 {
77 n += 16;
78 }
79 if version >= 0 {
80 n += 1;
81 }
82 if version >= 0 {
83 n += {
84 let prefix =
85 crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex);
86 let body: usize = (self.listeners)
87 .iter()
88 .map(|it| it.encoded_len(version))
89 .sum();
90 prefix + body
91 };
92 }
93 if version >= 0 {
94 n += {
95 let prefix =
96 crate::primitives::array::array_len_prefix_len((self.features).len(), flex);
97 let body: usize = (self.features)
98 .iter()
99 .map(|it| it.encoded_len(version))
100 .sum();
101 prefix + body
102 };
103 }
104 if flex {
105 let known_pairs: Vec<(u32, usize)> = Vec::new();
106 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107 }
108 n
109 }
110}
111impl Decode<'_> for ControllerRegistrationRequest {
112 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
113 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
114 return Err(ProtocolError::UnsupportedVersion {
115 api_key: API_KEY,
116 version,
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.listeners = {
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(Listener::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(Feature::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 ControllerRegistrationRequest {
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.listeners = vec![Listener::populated(version)];
172 }
173 if version >= 0 {
174 m.features = vec![Feature::populated(version)];
175 }
176 m
177 }
178}
179#[derive(Debug, Clone, PartialEq, Eq, Default)]
180pub struct Listener {
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 Listener {
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 Listener {
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 Listener {
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 Feature {
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 Feature {
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 Feature {
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 Feature {
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#[must_use]
391#[allow(unused_comparisons)]
392pub fn default_json(version: i16) -> ::serde_json::Value {
393 let mut obj = ::serde_json::Map::new();
394 obj.insert("controllerId".to_string(), ::serde_json::json!(0));
395 obj.insert(
396 "incarnationId".to_string(),
397 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
398 );
399 obj.insert(
400 "zkMigrationReady".to_string(),
401 ::serde_json::Value::Bool(false),
402 );
403 obj.insert("listeners".to_string(), ::serde_json::Value::Array(vec![]));
404 obj.insert("features".to_string(), ::serde_json::Value::Array(vec![]));
405 ::serde_json::Value::Object(obj)
406}
407impl crate::ProtocolRequest for ControllerRegistrationRequest {
408 const API_KEY: i16 = API_KEY;
409 const MIN_VERSION: i16 = MIN_VERSION;
410 const MAX_VERSION: i16 = MAX_VERSION;
411 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
412 type Response = super::controller_registration_response::ControllerRegistrationResponse;
413}