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