Skip to main content

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

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