Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AccessControlEntryRecord.owned.rs

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