Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RegisterControllerRecord.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_bool, get_i16, get_i32, get_u16, put_bool, put_i16, put_i32, put_u16},
10        string_bytes::{
11            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12            put_string, string_len,
13        },
14        uuid::{Uuid, get_uuid, put_uuid},
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_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 RegisterControllerRecord {
28    pub controller_id: i32,
29    pub incarnation_id: Uuid,
30    pub zk_migration_ready: bool,
31    pub end_points: Vec<ControllerEndpoint>,
32    pub features: Vec<ControllerFeature>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for RegisterControllerRecord {
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::SchemaMismatch(
39                "RegisterControllerRecord version out of range",
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            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                put_array_len(buf, (self.end_points).len(), flex)?;
55                for it in &self.end_points {
56                    it.encode(buf, version)?;
57                }
58            }
59        }
60        if version >= 0 {
61            {
62                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 = array_len_prefix_len((self.end_points).len(), flex);
89                let body: usize = (self.end_points)
90                    .iter()
91                    .map(|it| it.encoded_len(version))
92                    .sum();
93                prefix + body
94            };
95        }
96        if version >= 0 {
97            n += {
98                let prefix = 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 = 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 = 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 = 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 = 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                put_compact_string(buf, &self.name)?;
194            } else {
195                put_string(buf, &self.name)?;
196            }
197        }
198        if version >= 0 {
199            if flex {
200                put_compact_string(buf, &self.host)?;
201            } else {
202                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_owned();
284        }
285        if version >= 0 {
286            m.host = "x".to_owned();
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                put_compact_string(buf, &self.name)?;
310            } else {
311                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_owned();
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/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
390/// Only includes fields valid for the given version.
391#[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_owned(), ::serde_json::json!(0));
396    obj.insert(
397        "incarnationId".to_owned(),
398        ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_owned()),
399    );
400    obj.insert(
401        "zkMigrationReady".to_owned(),
402        ::serde_json::Value::Bool(false),
403    );
404    obj.insert("endPoints".to_owned(), ::serde_json::Value::Array(vec![]));
405    obj.insert("features".to_owned(), ::serde_json::Value::Array(vec![]));
406    ::serde_json::Value::Object(obj)
407}