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