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