krabka_protocol/opt/rustwide/workdir/generated/
UnregisterControllerRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::fixed::{get_i32, put_i32},
8 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13#[inline]
14#[must_use]
15pub fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct UnregisterControllerRecord {
20 pub controller_id: i32,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for UnregisterControllerRecord {
24 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
25 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
26 return Err(ProtocolError::SchemaMismatch(
27 "UnregisterControllerRecord version out of range",
28 ));
29 }
30 let flex = is_flexible(version);
31 if version >= 0 {
32 put_i32(buf, self.controller_id);
33 }
34 if flex {
35 let tagged = WriteTaggedFields::new();
36 tagged.write(buf, &self.unknown_tagged_fields);
37 }
38 Ok(())
39 }
40 fn encoded_len(&self, version: i16) -> usize {
41 let flex = is_flexible(version);
42 let mut n: usize = 0;
43 if version >= 0 {
44 n += 4;
45 }
46 if flex {
47 let known_pairs: Vec<(u32, usize)> = Vec::new();
48 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49 }
50 n
51 }
52}
53impl Decode<'_> for UnregisterControllerRecord {
54 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::SchemaMismatch(
57 "UnregisterControllerRecord version out of range",
58 ));
59 }
60 let flex = is_flexible(version);
61 let mut out = Self::default();
62 if version >= 0 {
63 out.controller_id = get_i32(buf)?;
64 }
65 if flex {
66 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
67 }
68 Ok(out)
69 }
70}
71#[cfg(test)]
72impl UnregisterControllerRecord {
73 #[must_use]
74 pub fn populated(version: i16) -> Self {
75 let mut m = Self::default();
76 if version >= 0 {
77 m.controller_id = 1i32;
78 }
79 m
80 }
81}
82#[must_use]
85#[allow(unused_comparisons)]
86pub fn default_json(_version: i16) -> ::serde_json::Value {
87 let mut obj = ::serde_json::Map::new();
88 obj.insert("controllerId".to_string(), ::serde_json::json!(0));
89 ::serde_json::Value::Object(obj)
90}