Skip to main content

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