crabka_protocol/opt/rustwide/workdir/generated/
AccessControlEntryRecord.owned.rs1use crate::primitives::fixed::{get_i8, put_i8};
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 AccessControlEntryRecord {
20 pub id: crate::primitives::uuid::Uuid,
21 pub resource_type: i8,
22 pub resource_name: String,
23 pub pattern_type: i8,
24 pub principal: String,
25 pub host: String,
26 pub operation: i8,
27 pub permission_type: i8,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for AccessControlEntryRecord {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::SchemaMismatch(
34 "AccessControlEntryRecord version out of range",
35 ));
36 }
37 let flex = is_flexible(version);
38 if version >= 0 {
39 crate::primitives::uuid::put_uuid(buf, self.id);
40 }
41 if version >= 0 {
42 put_i8(buf, self.resource_type);
43 }
44 if version >= 0 {
45 if flex {
46 put_compact_string(buf, &self.resource_name);
47 } else {
48 put_string(buf, &self.resource_name);
49 }
50 }
51 if version >= 0 {
52 put_i8(buf, self.pattern_type);
53 }
54 if version >= 0 {
55 if flex {
56 put_compact_string(buf, &self.principal);
57 } else {
58 put_string(buf, &self.principal);
59 }
60 }
61 if version >= 0 {
62 if flex {
63 put_compact_string(buf, &self.host);
64 } else {
65 put_string(buf, &self.host);
66 }
67 }
68 if version >= 0 {
69 put_i8(buf, self.operation);
70 }
71 if version >= 0 {
72 put_i8(buf, self.permission_type);
73 }
74 if flex {
75 let tagged = WriteTaggedFields::new();
76 tagged.write(buf, &self.unknown_tagged_fields);
77 }
78 Ok(())
79 }
80 fn encoded_len(&self, version: i16) -> usize {
81 let flex = is_flexible(version);
82 let mut n: usize = 0;
83 if version >= 0 {
84 n += 16;
85 }
86 if version >= 0 {
87 n += 1;
88 }
89 if version >= 0 {
90 n += if flex {
91 compact_string_len(&self.resource_name)
92 } else {
93 string_len(&self.resource_name)
94 };
95 }
96 if version >= 0 {
97 n += 1;
98 }
99 if version >= 0 {
100 n += if flex {
101 compact_string_len(&self.principal)
102 } else {
103 string_len(&self.principal)
104 };
105 }
106 if version >= 0 {
107 n += if flex {
108 compact_string_len(&self.host)
109 } else {
110 string_len(&self.host)
111 };
112 }
113 if version >= 0 {
114 n += 1;
115 }
116 if version >= 0 {
117 n += 1;
118 }
119 if flex {
120 let known_pairs: Vec<(u32, usize)> = Vec::new();
121 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
122 }
123 n
124 }
125}
126impl Decode<'_> for AccessControlEntryRecord {
127 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
128 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
129 return Err(ProtocolError::SchemaMismatch(
130 "AccessControlEntryRecord version out of range",
131 ));
132 }
133 let flex = is_flexible(version);
134 let mut out = Self::default();
135 if version >= 0 {
136 out.id = crate::primitives::uuid::get_uuid(buf)?;
137 }
138 if version >= 0 {
139 out.resource_type = get_i8(buf)?;
140 }
141 if version >= 0 {
142 out.resource_name = if flex {
143 get_compact_string_owned(buf)?
144 } else {
145 get_string_owned(buf)?
146 };
147 }
148 if version >= 0 {
149 out.pattern_type = get_i8(buf)?;
150 }
151 if version >= 0 {
152 out.principal = if flex {
153 get_compact_string_owned(buf)?
154 } else {
155 get_string_owned(buf)?
156 };
157 }
158 if version >= 0 {
159 out.host = if flex {
160 get_compact_string_owned(buf)?
161 } else {
162 get_string_owned(buf)?
163 };
164 }
165 if version >= 0 {
166 out.operation = get_i8(buf)?;
167 }
168 if version >= 0 {
169 out.permission_type = get_i8(buf)?;
170 }
171 if flex {
172 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
173 }
174 Ok(out)
175 }
176}
177#[cfg(test)]
178impl AccessControlEntryRecord {
179 #[must_use]
180 pub fn populated(version: i16) -> Self {
181 let mut m = Self::default();
182 if version >= 0 {
183 m.id = crate::primitives::uuid::Uuid([1u8; 16]);
184 }
185 if version >= 0 {
186 m.resource_type = 1i8;
187 }
188 if version >= 0 {
189 m.resource_name = "x".to_string();
190 }
191 if version >= 0 {
192 m.pattern_type = 1i8;
193 }
194 if version >= 0 {
195 m.principal = "x".to_string();
196 }
197 if version >= 0 {
198 m.host = "x".to_string();
199 }
200 if version >= 0 {
201 m.operation = 1i8;
202 }
203 if version >= 0 {
204 m.permission_type = 1i8;
205 }
206 m
207 }
208}
209#[must_use]
212#[allow(unused_comparisons)]
213pub fn default_json(version: i16) -> ::serde_json::Value {
214 let mut obj = ::serde_json::Map::new();
215 obj.insert(
216 "id".to_string(),
217 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
218 );
219 obj.insert("resourceType".to_string(), ::serde_json::json!(0));
220 obj.insert(
221 "resourceName".to_string(),
222 ::serde_json::Value::String(String::new()),
223 );
224 obj.insert("patternType".to_string(), ::serde_json::json!(0));
225 obj.insert(
226 "principal".to_string(),
227 ::serde_json::Value::String(String::new()),
228 );
229 obj.insert(
230 "host".to_string(),
231 ::serde_json::Value::String(String::new()),
232 );
233 obj.insert("operation".to_string(), ::serde_json::json!(0));
234 obj.insert("permissionType".to_string(), ::serde_json::json!(0));
235 ::serde_json::Value::Object(obj)
236}