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