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