Skip to main content

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