Skip to main content

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

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