Skip to main content

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