Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeAclsResponse.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, get_i16, get_i32, put_i8, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 29;
21pub const MIN_VERSION: i16 = 1;
22pub const MAX_VERSION: i16 = 3;
23pub const FLEXIBLE_MIN: i16 = 2;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct DescribeAclsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub error_code: i16,
33    pub error_message: Option<&'a str>,
34    pub resources: Vec<DescribeAclsResource<'a>>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for DescribeAclsResponse<'_> {
38    fn default() -> Self {
39        Self {
40            throttle_time_ms: 0i32,
41            error_code: 0i16,
42            error_message: Some(""),
43            resources: Vec::new(),
44            unknown_tagged_fields: UnknownTaggedFields::default(),
45        }
46    }
47}
48impl DescribeAclsResponse<'_> {
49    /// # Panics
50    ///
51    /// Panics if a records field contains an invalid encoded record batch.
52    #[must_use]
53    pub fn to_owned(&self) -> crate::owned::describe_acls_response::DescribeAclsResponse {
54        crate::owned::describe_acls_response::DescribeAclsResponse {
55            throttle_time_ms: (self.throttle_time_ms),
56            error_code: (self.error_code),
57            error_message: (self.error_message).map(std::string::ToString::to_string),
58            resources: (self.resources)
59                .iter()
60                .map(DescribeAclsResource::to_owned)
61                .collect(),
62            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
63        }
64    }
65}
66impl Encode for DescribeAclsResponse<'_> {
67    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
68        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69            return Err(ProtocolError::UnsupportedVersion {
70                api_key: API_KEY,
71                version,
72            });
73        }
74        let flex = is_flexible(version);
75        if version >= 0 {
76            put_i32(buf, self.throttle_time_ms);
77        }
78        if version >= 0 {
79            put_i16(buf, self.error_code);
80        }
81        if version >= 0 {
82            if flex {
83                let () = put_compact_nullable_string(buf, self.error_message);
84            } else {
85                let () = put_nullable_string(buf, self.error_message);
86            }
87        }
88        if version >= 0 {
89            {
90                crate::primitives::array::put_array_len(buf, (self.resources).len(), flex);
91                for it in &self.resources {
92                    it.encode(buf, version)?;
93                }
94            };
95        }
96        if flex {
97            let tagged = WriteTaggedFields::new();
98            tagged.write(buf, &self.unknown_tagged_fields);
99        }
100        Ok(())
101    }
102    fn encoded_len(&self, version: i16) -> usize {
103        let flex = is_flexible(version);
104        let mut n: usize = 0;
105        if version >= 0 {
106            n += 4;
107        }
108        if version >= 0 {
109            n += 2;
110        }
111        if version >= 0 {
112            n += if flex {
113                compact_nullable_string_len(self.error_message)
114            } else {
115                nullable_string_len(self.error_message)
116            };
117        }
118        if version >= 0 {
119            n += {
120                let prefix =
121                    crate::primitives::array::array_len_prefix_len((self.resources).len(), flex);
122                let body: usize = (self.resources)
123                    .iter()
124                    .map(|it| it.encoded_len(version))
125                    .sum();
126                prefix + body
127            };
128        }
129        if flex {
130            let known_pairs: Vec<(u32, usize)> = Vec::new();
131            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
132        }
133        n
134    }
135}
136impl<'de> DecodeBorrow<'de> for DescribeAclsResponse<'de> {
137    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
138        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
139            return Err(ProtocolError::UnsupportedVersion {
140                api_key: API_KEY,
141                version,
142            });
143        }
144        let flex = is_flexible(version);
145        let mut out = Self::default();
146        if version >= 0 {
147            out.throttle_time_ms = get_i32(buf)?;
148        }
149        if version >= 0 {
150            out.error_code = get_i16(buf)?;
151        }
152        if version >= 0 {
153            out.error_message = if flex {
154                get_compact_nullable_string_borrowed(buf)?
155            } else {
156                get_nullable_string_borrowed(buf)?
157            };
158        }
159        if version >= 0 {
160            out.resources = {
161                let n = crate::primitives::array::get_array_len(buf, flex)?;
162                let mut v = Vec::with_capacity(n);
163                for _ in 0..n {
164                    v.push(DescribeAclsResource::decode_borrow(buf, version)?);
165                }
166                v
167            };
168        }
169        if flex {
170            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
171        }
172        Ok(out)
173    }
174}
175#[cfg(test)]
176impl DescribeAclsResponse<'_> {
177    #[must_use]
178    pub fn populated(version: i16) -> Self {
179        let mut m = Self::default();
180        if version >= 0 {
181            m.throttle_time_ms = 1i32;
182        }
183        if version >= 0 {
184            m.error_code = 1i16;
185        }
186        if version >= 0 {
187            m.error_message = Some("x");
188        }
189        if version >= 0 {
190            m.resources = vec![DescribeAclsResource::populated(version)];
191        }
192        m
193    }
194}
195#[derive(Debug, Clone, PartialEq, Eq)]
196pub struct DescribeAclsResource<'a> {
197    pub resource_type: i8,
198    pub resource_name: &'a str,
199    pub pattern_type: i8,
200    pub acls: Vec<AclDescription<'a>>,
201    pub unknown_tagged_fields: UnknownTaggedFields,
202}
203impl Default for DescribeAclsResource<'_> {
204    fn default() -> Self {
205        Self {
206            resource_type: 0i8,
207            resource_name: "",
208            pattern_type: 3i8,
209            acls: Vec::new(),
210            unknown_tagged_fields: UnknownTaggedFields::default(),
211        }
212    }
213}
214impl DescribeAclsResource<'_> {
215    /// # Panics
216    ///
217    /// Panics if a records field contains an invalid encoded record batch.
218    #[must_use]
219    pub fn to_owned(&self) -> crate::owned::describe_acls_response::DescribeAclsResource {
220        crate::owned::describe_acls_response::DescribeAclsResource {
221            resource_type: (self.resource_type),
222            resource_name: (self.resource_name).to_string(),
223            pattern_type: (self.pattern_type),
224            acls: (self.acls).iter().map(AclDescription::to_owned).collect(),
225            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
226        }
227    }
228}
229impl Encode for DescribeAclsResource<'_> {
230    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
231        let flex = version >= 2;
232        if version >= 0 {
233            put_i8(buf, self.resource_type);
234        }
235        if version >= 0 {
236            if flex {
237                let () = put_compact_string(buf, self.resource_name);
238            } else {
239                let () = put_string(buf, self.resource_name);
240            }
241        }
242        if version >= 1 {
243            put_i8(buf, self.pattern_type);
244        }
245        if version >= 0 {
246            {
247                crate::primitives::array::put_array_len(buf, (self.acls).len(), flex);
248                for it in &self.acls {
249                    it.encode(buf, version)?;
250                }
251            };
252        }
253        if flex {
254            let tagged = WriteTaggedFields::new();
255            tagged.write(buf, &self.unknown_tagged_fields);
256        }
257        Ok(())
258    }
259    fn encoded_len(&self, version: i16) -> usize {
260        let flex = version >= 2;
261        let mut n: usize = 0;
262        if version >= 0 {
263            n += 1;
264        }
265        if version >= 0 {
266            n += if flex {
267                compact_string_len(self.resource_name)
268            } else {
269                string_len(self.resource_name)
270            };
271        }
272        if version >= 1 {
273            n += 1;
274        }
275        if version >= 0 {
276            n += {
277                let prefix =
278                    crate::primitives::array::array_len_prefix_len((self.acls).len(), flex);
279                let body: usize = (self.acls).iter().map(|it| it.encoded_len(version)).sum();
280                prefix + body
281            };
282        }
283        if flex {
284            let known_pairs: Vec<(u32, usize)> = Vec::new();
285            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
286        }
287        n
288    }
289}
290impl<'de> DecodeBorrow<'de> for DescribeAclsResource<'de> {
291    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
292        let flex = version >= 2;
293        let mut out = Self::default();
294        if version >= 0 {
295            out.resource_type = get_i8(buf)?;
296        }
297        if version >= 0 {
298            out.resource_name = if flex {
299                get_compact_string_borrowed(buf)?
300            } else {
301                get_string_borrowed(buf)?
302            };
303        }
304        if version >= 1 {
305            out.pattern_type = get_i8(buf)?;
306        }
307        if version >= 0 {
308            out.acls = {
309                let n = crate::primitives::array::get_array_len(buf, flex)?;
310                let mut v = Vec::with_capacity(n);
311                for _ in 0..n {
312                    v.push(AclDescription::decode_borrow(buf, version)?);
313                }
314                v
315            };
316        }
317        if flex {
318            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
319        }
320        Ok(out)
321    }
322}
323#[cfg(test)]
324impl DescribeAclsResource<'_> {
325    #[must_use]
326    pub fn populated(version: i16) -> Self {
327        let mut m = Self::default();
328        if version >= 0 {
329            m.resource_type = 1i8;
330        }
331        if version >= 0 {
332            m.resource_name = "x";
333        }
334        if version >= 1 {
335            m.pattern_type = 1i8;
336        }
337        if version >= 0 {
338            m.acls = vec![AclDescription::populated(version)];
339        }
340        m
341    }
342}
343#[derive(Debug, Clone, PartialEq, Eq, Default)]
344pub struct AclDescription<'a> {
345    pub principal: &'a str,
346    pub host: &'a str,
347    pub operation: i8,
348    pub permission_type: i8,
349    pub unknown_tagged_fields: UnknownTaggedFields,
350}
351impl AclDescription<'_> {
352    /// # Panics
353    ///
354    /// Panics if a records field contains an invalid encoded record batch.
355    #[must_use]
356    pub fn to_owned(&self) -> crate::owned::describe_acls_response::AclDescription {
357        crate::owned::describe_acls_response::AclDescription {
358            principal: (self.principal).to_string(),
359            host: (self.host).to_string(),
360            operation: (self.operation),
361            permission_type: (self.permission_type),
362            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
363        }
364    }
365}
366impl Encode for AclDescription<'_> {
367    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
368        let flex = version >= 2;
369        if version >= 0 {
370            if flex {
371                let () = put_compact_string(buf, self.principal);
372            } else {
373                let () = put_string(buf, self.principal);
374            }
375        }
376        if version >= 0 {
377            if flex {
378                let () = put_compact_string(buf, self.host);
379            } else {
380                let () = put_string(buf, self.host);
381            }
382        }
383        if version >= 0 {
384            put_i8(buf, self.operation);
385        }
386        if version >= 0 {
387            put_i8(buf, self.permission_type);
388        }
389        if flex {
390            let tagged = WriteTaggedFields::new();
391            tagged.write(buf, &self.unknown_tagged_fields);
392        }
393        Ok(())
394    }
395    fn encoded_len(&self, version: i16) -> usize {
396        let flex = version >= 2;
397        let mut n: usize = 0;
398        if version >= 0 {
399            n += if flex {
400                compact_string_len(self.principal)
401            } else {
402                string_len(self.principal)
403            };
404        }
405        if version >= 0 {
406            n += if flex {
407                compact_string_len(self.host)
408            } else {
409                string_len(self.host)
410            };
411        }
412        if version >= 0 {
413            n += 1;
414        }
415        if version >= 0 {
416            n += 1;
417        }
418        if flex {
419            let known_pairs: Vec<(u32, usize)> = Vec::new();
420            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
421        }
422        n
423    }
424}
425impl<'de> DecodeBorrow<'de> for AclDescription<'de> {
426    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
427        let flex = version >= 2;
428        let mut out = Self::default();
429        if version >= 0 {
430            out.principal = if flex {
431                get_compact_string_borrowed(buf)?
432            } else {
433                get_string_borrowed(buf)?
434            };
435        }
436        if version >= 0 {
437            out.host = if flex {
438                get_compact_string_borrowed(buf)?
439            } else {
440                get_string_borrowed(buf)?
441            };
442        }
443        if version >= 0 {
444            out.operation = get_i8(buf)?;
445        }
446        if version >= 0 {
447            out.permission_type = get_i8(buf)?;
448        }
449        if flex {
450            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
451        }
452        Ok(out)
453    }
454}
455#[cfg(test)]
456impl AclDescription<'_> {
457    #[must_use]
458    pub fn populated(version: i16) -> Self {
459        let mut m = Self::default();
460        if version >= 0 {
461            m.principal = "x";
462        }
463        if version >= 0 {
464            m.host = "x";
465        }
466        if version >= 0 {
467            m.operation = 1i8;
468        }
469        if version >= 0 {
470            m.permission_type = 1i8;
471        }
472        m
473    }
474}