Skip to main content

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

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