Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_bool, put_bool};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6    string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct DefaultPrincipalData {
20    pub type_: String,
21    pub name: String,
22    pub token_authenticated: bool,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for DefaultPrincipalData {
26    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28            return Err(ProtocolError::SchemaMismatch(
29                "DefaultPrincipalData version out of range",
30            ));
31        }
32        let flex = is_flexible(version);
33        if version >= 0 {
34            if flex {
35                put_compact_string(buf, &self.type_);
36            } else {
37                put_string(buf, &self.type_);
38            }
39        }
40        if version >= 0 {
41            if flex {
42                put_compact_string(buf, &self.name);
43            } else {
44                put_string(buf, &self.name);
45            }
46        }
47        if version >= 0 {
48            put_bool(buf, self.token_authenticated);
49        }
50        if flex {
51            let tagged = WriteTaggedFields::new();
52            tagged.write(buf, &self.unknown_tagged_fields);
53        }
54        Ok(())
55    }
56    fn encoded_len(&self, version: i16) -> usize {
57        let flex = is_flexible(version);
58        let mut n: usize = 0;
59        if version >= 0 {
60            n += if flex {
61                compact_string_len(&self.type_)
62            } else {
63                string_len(&self.type_)
64            };
65        }
66        if version >= 0 {
67            n += if flex {
68                compact_string_len(&self.name)
69            } else {
70                string_len(&self.name)
71            };
72        }
73        if version >= 0 {
74            n += 1;
75        }
76        if flex {
77            let known_pairs: Vec<(u32, usize)> = Vec::new();
78            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79        }
80        n
81    }
82}
83impl Decode<'_> for DefaultPrincipalData {
84    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86            return Err(ProtocolError::SchemaMismatch(
87                "DefaultPrincipalData version out of range",
88            ));
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 {
93            out.type_ = if flex {
94                get_compact_string_owned(buf)?
95            } else {
96                get_string_owned(buf)?
97            };
98        }
99        if version >= 0 {
100            out.name = if flex {
101                get_compact_string_owned(buf)?
102            } else {
103                get_string_owned(buf)?
104            };
105        }
106        if version >= 0 {
107            out.token_authenticated = get_bool(buf)?;
108        }
109        if flex {
110            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
111        }
112        Ok(out)
113    }
114}
115#[cfg(test)]
116impl DefaultPrincipalData {
117    #[must_use]
118    pub fn populated(version: i16) -> Self {
119        let mut m = Self::default();
120        if version >= 0 {
121            m.type_ = "x".to_string();
122        }
123        if version >= 0 {
124            m.name = "x".to_string();
125        }
126        if version >= 0 {
127            m.token_authenticated = true;
128        }
129        m
130    }
131}
132/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
133/// Only includes fields valid for the given version.
134#[must_use]
135#[allow(unused_comparisons)]
136pub fn default_json(version: i16) -> ::serde_json::Value {
137    let mut obj = ::serde_json::Map::new();
138    obj.insert(
139        "type".to_string(),
140        ::serde_json::Value::String(String::new()),
141    );
142    obj.insert(
143        "name".to_string(),
144        ::serde_json::Value::String(String::new()),
145    );
146    obj.insert(
147        "tokenAuthenticated".to_string(),
148        ::serde_json::Value::Bool(false),
149    );
150    ::serde_json::Value::Object(obj)
151}