Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteAclsRequest.owned.rs

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