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