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