Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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 API_KEY: i16 = 30;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 3;
14pub const FLEXIBLE_MIN: i16 = 2;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct CreateAclsRequest {
21    pub creations: Vec<AclCreation>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for CreateAclsRequest {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::UnsupportedVersion {
28                api_key: API_KEY,
29                version,
30            });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 {
34            {
35                crate::primitives::array::put_array_len(buf, (self.creations).len(), flex);
36                for it in &self.creations {
37                    it.encode(buf, version)?;
38                }
39            }
40        }
41        if flex {
42            let tagged = WriteTaggedFields::new();
43            tagged.write(buf, &self.unknown_tagged_fields);
44        }
45        Ok(())
46    }
47    fn encoded_len(&self, version: i16) -> usize {
48        let flex = is_flexible(version);
49        let mut n: usize = 0;
50        if version >= 0 {
51            n += {
52                let prefix =
53                    crate::primitives::array::array_len_prefix_len((self.creations).len(), flex);
54                let body: usize = (self.creations)
55                    .iter()
56                    .map(|it| it.encoded_len(version))
57                    .sum();
58                prefix + body
59            };
60        }
61        if flex {
62            let known_pairs: Vec<(u32, usize)> = Vec::new();
63            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64        }
65        n
66    }
67}
68impl Decode<'_> for CreateAclsRequest {
69    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
70        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71            return Err(ProtocolError::UnsupportedVersion {
72                api_key: API_KEY,
73                version,
74            });
75        }
76        let flex = is_flexible(version);
77        let mut out = Self::default();
78        if version >= 0 {
79            out.creations = {
80                let n = crate::primitives::array::get_array_len(buf, flex)?;
81                let mut v = Vec::with_capacity(n);
82                for _ in 0..n {
83                    v.push(AclCreation::decode(buf, version)?);
84                }
85                v
86            };
87        }
88        if flex {
89            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90        }
91        Ok(out)
92    }
93}
94#[cfg(test)]
95impl CreateAclsRequest {
96    #[must_use]
97    pub fn populated(version: i16) -> Self {
98        let mut m = Self::default();
99        if version >= 0 {
100            m.creations = vec![AclCreation::populated(version)];
101        }
102        m
103    }
104}
105#[derive(Debug, Clone, PartialEq, Eq)]
106pub struct AclCreation {
107    pub resource_type: i8,
108    pub resource_name: String,
109    pub resource_pattern_type: i8,
110    pub principal: String,
111    pub host: String,
112    pub operation: i8,
113    pub permission_type: i8,
114    pub unknown_tagged_fields: UnknownTaggedFields,
115}
116impl Default for AclCreation {
117    fn default() -> Self {
118        Self {
119            resource_type: 0i8,
120            resource_name: String::new(),
121            resource_pattern_type: 3i8,
122            principal: String::new(),
123            host: String::new(),
124            operation: 0i8,
125            permission_type: 0i8,
126            unknown_tagged_fields: Default::default(),
127        }
128    }
129}
130impl Encode for AclCreation {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 2;
133        if version >= 0 {
134            put_i8(buf, self.resource_type);
135        }
136        if version >= 0 {
137            if flex {
138                put_compact_string(buf, &self.resource_name);
139            } else {
140                put_string(buf, &self.resource_name);
141            }
142        }
143        if version >= 1 {
144            put_i8(buf, self.resource_pattern_type);
145        }
146        if version >= 0 {
147            if flex {
148                put_compact_string(buf, &self.principal);
149            } else {
150                put_string(buf, &self.principal);
151            }
152        }
153        if version >= 0 {
154            if flex {
155                put_compact_string(buf, &self.host);
156            } else {
157                put_string(buf, &self.host);
158            }
159        }
160        if version >= 0 {
161            put_i8(buf, self.operation);
162        }
163        if version >= 0 {
164            put_i8(buf, self.permission_type);
165        }
166        if flex {
167            let tagged = WriteTaggedFields::new();
168            tagged.write(buf, &self.unknown_tagged_fields);
169        }
170        Ok(())
171    }
172    fn encoded_len(&self, version: i16) -> usize {
173        let flex = version >= 2;
174        let mut n: usize = 0;
175        if version >= 0 {
176            n += 1;
177        }
178        if version >= 0 {
179            n += if flex {
180                compact_string_len(&self.resource_name)
181            } else {
182                string_len(&self.resource_name)
183            };
184        }
185        if version >= 1 {
186            n += 1;
187        }
188        if version >= 0 {
189            n += if flex {
190                compact_string_len(&self.principal)
191            } else {
192                string_len(&self.principal)
193            };
194        }
195        if version >= 0 {
196            n += if flex {
197                compact_string_len(&self.host)
198            } else {
199                string_len(&self.host)
200            };
201        }
202        if version >= 0 {
203            n += 1;
204        }
205        if version >= 0 {
206            n += 1;
207        }
208        if flex {
209            let known_pairs: Vec<(u32, usize)> = Vec::new();
210            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
211        }
212        n
213    }
214}
215impl Decode<'_> for AclCreation {
216    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
217        let flex = version >= 2;
218        let mut out = Self::default();
219        if version >= 0 {
220            out.resource_type = get_i8(buf)?;
221        }
222        if version >= 0 {
223            out.resource_name = if flex {
224                get_compact_string_owned(buf)?
225            } else {
226                get_string_owned(buf)?
227            };
228        }
229        if version >= 1 {
230            out.resource_pattern_type = get_i8(buf)?;
231        }
232        if version >= 0 {
233            out.principal = if flex {
234                get_compact_string_owned(buf)?
235            } else {
236                get_string_owned(buf)?
237            };
238        }
239        if version >= 0 {
240            out.host = if flex {
241                get_compact_string_owned(buf)?
242            } else {
243                get_string_owned(buf)?
244            };
245        }
246        if version >= 0 {
247            out.operation = get_i8(buf)?;
248        }
249        if version >= 0 {
250            out.permission_type = get_i8(buf)?;
251        }
252        if flex {
253            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
254        }
255        Ok(out)
256    }
257}
258#[cfg(test)]
259impl AclCreation {
260    #[must_use]
261    pub fn populated(version: i16) -> Self {
262        let mut m = Self::default();
263        if version >= 0 {
264            m.resource_type = 1i8;
265        }
266        if version >= 0 {
267            m.resource_name = "x".to_string();
268        }
269        if version >= 1 {
270            m.resource_pattern_type = 1i8;
271        }
272        if version >= 0 {
273            m.principal = "x".to_string();
274        }
275        if version >= 0 {
276            m.host = "x".to_string();
277        }
278        if version >= 0 {
279            m.operation = 1i8;
280        }
281        if version >= 0 {
282            m.permission_type = 1i8;
283        }
284        m
285    }
286}
287/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
288/// Only includes fields valid for the given version.
289#[must_use]
290#[allow(unused_comparisons)]
291pub fn default_json(version: i16) -> ::serde_json::Value {
292    let mut obj = ::serde_json::Map::new();
293    obj.insert("creations".to_string(), ::serde_json::Value::Array(vec![]));
294    ::serde_json::Value::Object(obj)
295}
296impl crate::ProtocolRequest for CreateAclsRequest {
297    const API_KEY: i16 = API_KEY;
298    const MIN_VERSION: i16 = MIN_VERSION;
299    const MAX_VERSION: i16 = MAX_VERSION;
300    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
301    type Response = super::create_acls_response::CreateAclsResponse;
302}