1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
10 string_bytes::{
11 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13 nullable_string_len, put_compact_nullable_string, put_compact_string,
14 put_nullable_string, put_string, string_len,
15 },
16 },
17 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 31;
20pub const MIN_VERSION: i16 = 1;
21pub const MAX_VERSION: i16 = 3;
22pub const FLEXIBLE_MIN: i16 = 2;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct DeleteAclsResponse {
30 pub throttle_time_ms: i32,
31 pub filter_results: Vec<DeleteAclsFilterResult>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for DeleteAclsResponse {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 put_i32(buf, self.throttle_time_ms);
45 }
46 if version >= 0 {
47 {
48 put_array_len(buf, (self.filter_results).len(), flex)?;
49 for it in &self.filter_results {
50 it.encode(buf, version)?;
51 }
52 }
53 }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields)?;
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 if version >= 0 {
64 n += 4;
65 }
66 if version >= 0 {
67 n += {
68 let prefix = array_len_prefix_len((self.filter_results).len(), flex);
69 let body: usize = (self.filter_results)
70 .iter()
71 .map(|it| it.encoded_len(version))
72 .sum();
73 prefix + body
74 };
75 }
76 if flex {
77 let known_pairs: Vec<(u32, usize)> = Vec::new();
78 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79 }
80 n
81 }
82}
83impl Decode<'_> for DeleteAclsResponse {
84 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86 return Err(ProtocolError::UnsupportedVersion {
87 api_key: API_KEY,
88 version,
89 });
90 }
91 let flex = is_flexible(version);
92 let mut out = Self::default();
93 if version >= 0 {
94 out.throttle_time_ms = get_i32(buf)?;
95 }
96 if version >= 0 {
97 out.filter_results = {
98 let n = get_array_len(buf, flex)?;
99 let mut v = Vec::with_capacity(n);
100 for _ in 0..n {
101 v.push(DeleteAclsFilterResult::decode(buf, version)?);
102 }
103 v
104 };
105 }
106 if flex {
107 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
108 }
109 Ok(out)
110 }
111}
112#[cfg(test)]
113impl DeleteAclsResponse {
114 #[must_use]
115 pub fn populated(version: i16) -> Self {
116 let mut m = Self::default();
117 if version >= 0 {
118 m.throttle_time_ms = 1i32;
119 }
120 if version >= 0 {
121 m.filter_results = vec![DeleteAclsFilterResult::populated(version)];
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct DeleteAclsFilterResult {
128 pub error_code: i16,
129 pub error_message: Option<String>,
130 pub matching_acls: Vec<DeleteAclsMatchingAcl>,
131 pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Default for DeleteAclsFilterResult {
134 fn default() -> Self {
135 Self {
136 error_code: 0i16,
137 error_message: Some(String::new()),
138 matching_acls: Vec::new(),
139 unknown_tagged_fields: UnknownTaggedFields::default(),
140 }
141 }
142}
143impl Encode for DeleteAclsFilterResult {
144 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
145 let flex = version >= 2;
146 if version >= 0 {
147 put_i16(buf, self.error_code);
148 }
149 if version >= 0 {
150 if flex {
151 put_compact_nullable_string(buf, self.error_message.as_deref())?;
152 } else {
153 put_nullable_string(buf, self.error_message.as_deref())?;
154 }
155 }
156 if version >= 0 {
157 {
158 put_array_len(buf, (self.matching_acls).len(), flex)?;
159 for it in &self.matching_acls {
160 it.encode(buf, version)?;
161 }
162 }
163 }
164 if flex {
165 let tagged = WriteTaggedFields::new();
166 tagged.write(buf, &self.unknown_tagged_fields)?;
167 }
168 Ok(())
169 }
170 fn encoded_len(&self, version: i16) -> usize {
171 let flex = version >= 2;
172 let mut n: usize = 0;
173 if version >= 0 {
174 n += 2;
175 }
176 if version >= 0 {
177 n += if flex {
178 compact_nullable_string_len(self.error_message.as_deref())
179 } else {
180 nullable_string_len(self.error_message.as_deref())
181 };
182 }
183 if version >= 0 {
184 n += {
185 let prefix = array_len_prefix_len((self.matching_acls).len(), flex);
186 let body: usize = (self.matching_acls)
187 .iter()
188 .map(|it| it.encoded_len(version))
189 .sum();
190 prefix + body
191 };
192 }
193 if flex {
194 let known_pairs: Vec<(u32, usize)> = Vec::new();
195 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196 }
197 n
198 }
199}
200impl Decode<'_> for DeleteAclsFilterResult {
201 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
202 let flex = version >= 2;
203 let mut out = Self::default();
204 if version >= 0 {
205 out.error_code = get_i16(buf)?;
206 }
207 if version >= 0 {
208 out.error_message = if flex {
209 get_compact_nullable_string_owned(buf)?
210 } else {
211 get_nullable_string_owned(buf)?
212 };
213 }
214 if version >= 0 {
215 out.matching_acls = {
216 let n = get_array_len(buf, flex)?;
217 let mut v = Vec::with_capacity(n);
218 for _ in 0..n {
219 v.push(DeleteAclsMatchingAcl::decode(buf, version)?);
220 }
221 v
222 };
223 }
224 if flex {
225 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
226 }
227 Ok(out)
228 }
229}
230#[cfg(test)]
231impl DeleteAclsFilterResult {
232 #[must_use]
233 pub fn populated(version: i16) -> Self {
234 let mut m = Self::default();
235 if version >= 0 {
236 m.error_code = 1i16;
237 }
238 if version >= 0 {
239 m.error_message = Some("x".to_owned());
240 }
241 if version >= 0 {
242 m.matching_acls = vec![DeleteAclsMatchingAcl::populated(version)];
243 }
244 m
245 }
246}
247#[derive(Debug, Clone, PartialEq, Eq)]
248pub struct DeleteAclsMatchingAcl {
249 pub error_code: i16,
250 pub error_message: Option<String>,
251 pub resource_type: i8,
252 pub resource_name: String,
253 pub pattern_type: i8,
254 pub principal: String,
255 pub host: String,
256 pub operation: i8,
257 pub permission_type: i8,
258 pub unknown_tagged_fields: UnknownTaggedFields,
259}
260impl Default for DeleteAclsMatchingAcl {
261 fn default() -> Self {
262 Self {
263 error_code: 0i16,
264 error_message: Some(String::new()),
265 resource_type: 0i8,
266 resource_name: String::new(),
267 pattern_type: 3i8,
268 principal: String::new(),
269 host: String::new(),
270 operation: 0i8,
271 permission_type: 0i8,
272 unknown_tagged_fields: UnknownTaggedFields::default(),
273 }
274 }
275}
276impl DeleteAclsMatchingAcl {
277 fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
278 if version >= 0 {
279 put_i16(buf, self.error_code);
280 }
281 }
282 fn encode_field_1<B: BufMut>(
283 &self,
284 buf: &mut B,
285 version: i16,
286 flex: bool,
287 ) -> Result<(), ProtocolError> {
288 if version >= 0 {
289 if flex {
290 put_compact_nullable_string(buf, self.error_message.as_deref())?;
291 } else {
292 put_nullable_string(buf, self.error_message.as_deref())?;
293 }
294 }
295 Ok(())
296 }
297 fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
298 if version >= 0 {
299 put_i8(buf, self.resource_type);
300 }
301 }
302 fn encode_field_3<B: BufMut>(
303 &self,
304 buf: &mut B,
305 version: i16,
306 flex: bool,
307 ) -> Result<(), ProtocolError> {
308 if version >= 0 {
309 if flex {
310 put_compact_string(buf, &self.resource_name)?;
311 } else {
312 put_string(buf, &self.resource_name)?;
313 }
314 }
315 Ok(())
316 }
317 fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
318 if version >= 1 {
319 put_i8(buf, self.pattern_type);
320 }
321 }
322 fn encode_field_5<B: BufMut>(
323 &self,
324 buf: &mut B,
325 version: i16,
326 flex: bool,
327 ) -> Result<(), ProtocolError> {
328 if version >= 0 {
329 if flex {
330 put_compact_string(buf, &self.principal)?;
331 } else {
332 put_string(buf, &self.principal)?;
333 }
334 }
335 Ok(())
336 }
337 fn encode_field_6<B: BufMut>(
338 &self,
339 buf: &mut B,
340 version: i16,
341 flex: bool,
342 ) -> Result<(), ProtocolError> {
343 if version >= 0 {
344 if flex {
345 put_compact_string(buf, &self.host)?;
346 } else {
347 put_string(buf, &self.host)?;
348 }
349 }
350 Ok(())
351 }
352 fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
353 if version >= 0 {
354 put_i8(buf, self.operation);
355 }
356 }
357 fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
358 if version >= 0 {
359 put_i8(buf, self.permission_type);
360 }
361 }
362 fn encode_tagged_fields<B: BufMut>(
363 &self,
364 buf: &mut B,
365 _version: i16,
366 flex: bool,
367 ) -> Result<(), ProtocolError> {
368 if flex {
369 let tagged = WriteTaggedFields::new();
370 tagged.write(buf, &self.unknown_tagged_fields)?;
371 }
372 Ok(())
373 }
374 fn decode_field_0<B: Buf>(
375 out: &mut Self,
376 buf: &mut B,
377 version: i16,
378 _flex: bool,
379 ) -> Result<(), ProtocolError> {
380 if version >= 0 {
381 out.error_code = get_i16(buf)?;
382 }
383 Ok(())
384 }
385 fn decode_field_1<B: Buf>(
386 out: &mut Self,
387 buf: &mut B,
388 version: i16,
389 flex: bool,
390 ) -> Result<(), ProtocolError> {
391 if version >= 0 {
392 out.error_message = if flex {
393 get_compact_nullable_string_owned(buf)?
394 } else {
395 get_nullable_string_owned(buf)?
396 };
397 }
398 Ok(())
399 }
400 fn decode_field_2<B: Buf>(
401 out: &mut Self,
402 buf: &mut B,
403 version: i16,
404 _flex: bool,
405 ) -> Result<(), ProtocolError> {
406 if version >= 0 {
407 out.resource_type = get_i8(buf)?;
408 }
409 Ok(())
410 }
411 fn decode_field_3<B: Buf>(
412 out: &mut Self,
413 buf: &mut B,
414 version: i16,
415 flex: bool,
416 ) -> Result<(), ProtocolError> {
417 if version >= 0 {
418 out.resource_name = if flex {
419 get_compact_string_owned(buf)?
420 } else {
421 get_string_owned(buf)?
422 };
423 }
424 Ok(())
425 }
426 fn decode_field_4<B: Buf>(
427 out: &mut Self,
428 buf: &mut B,
429 version: i16,
430 _flex: bool,
431 ) -> Result<(), ProtocolError> {
432 if version >= 1 {
433 out.pattern_type = get_i8(buf)?;
434 }
435 Ok(())
436 }
437 fn decode_field_5<B: Buf>(
438 out: &mut Self,
439 buf: &mut B,
440 version: i16,
441 flex: bool,
442 ) -> Result<(), ProtocolError> {
443 if version >= 0 {
444 out.principal = if flex {
445 get_compact_string_owned(buf)?
446 } else {
447 get_string_owned(buf)?
448 };
449 }
450 Ok(())
451 }
452 fn decode_field_6<B: Buf>(
453 out: &mut Self,
454 buf: &mut B,
455 version: i16,
456 flex: bool,
457 ) -> Result<(), ProtocolError> {
458 if version >= 0 {
459 out.host = if flex {
460 get_compact_string_owned(buf)?
461 } else {
462 get_string_owned(buf)?
463 };
464 }
465 Ok(())
466 }
467 fn decode_field_7<B: Buf>(
468 out: &mut Self,
469 buf: &mut B,
470 version: i16,
471 _flex: bool,
472 ) -> Result<(), ProtocolError> {
473 if version >= 0 {
474 out.operation = get_i8(buf)?;
475 }
476 Ok(())
477 }
478 fn decode_field_8<B: Buf>(
479 out: &mut Self,
480 buf: &mut B,
481 version: i16,
482 _flex: bool,
483 ) -> Result<(), ProtocolError> {
484 if version >= 0 {
485 out.permission_type = get_i8(buf)?;
486 }
487 Ok(())
488 }
489 fn decode_tagged_fields<B: Buf>(
490 out: &mut Self,
491 buf: &mut B,
492 _version: i16,
493 flex: bool,
494 ) -> Result<(), ProtocolError> {
495 if flex {
496 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
497 }
498 Ok(())
499 }
500}
501impl Encode for DeleteAclsMatchingAcl {
502 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
503 let flex = version >= 2;
504 self.encode_field_0(buf, version, flex);
505 self.encode_field_1(buf, version, flex)?;
506 self.encode_field_2(buf, version, flex);
507 self.encode_field_3(buf, version, flex)?;
508 self.encode_field_4(buf, version, flex);
509 self.encode_field_5(buf, version, flex)?;
510 self.encode_field_6(buf, version, flex)?;
511 self.encode_field_7(buf, version, flex);
512 self.encode_field_8(buf, version, flex);
513 self.encode_tagged_fields(buf, version, flex)?;
514 Ok(())
515 }
516 fn encoded_len(&self, version: i16) -> usize {
517 let flex = version >= 2;
518 let mut n: usize = 0;
519 if version >= 0 {
520 n += 2;
521 }
522 if version >= 0 {
523 n += if flex {
524 compact_nullable_string_len(self.error_message.as_deref())
525 } else {
526 nullable_string_len(self.error_message.as_deref())
527 };
528 }
529 if version >= 0 {
530 n += 1;
531 }
532 if version >= 0 {
533 n += if flex {
534 compact_string_len(&self.resource_name)
535 } else {
536 string_len(&self.resource_name)
537 };
538 }
539 if version >= 1 {
540 n += 1;
541 }
542 if version >= 0 {
543 n += if flex {
544 compact_string_len(&self.principal)
545 } else {
546 string_len(&self.principal)
547 };
548 }
549 if version >= 0 {
550 n += if flex {
551 compact_string_len(&self.host)
552 } else {
553 string_len(&self.host)
554 };
555 }
556 if version >= 0 {
557 n += 1;
558 }
559 if version >= 0 {
560 n += 1;
561 }
562 if flex {
563 let known_pairs: Vec<(u32, usize)> = Vec::new();
564 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
565 }
566 n
567 }
568}
569impl Decode<'_> for DeleteAclsMatchingAcl {
570 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
571 let flex = version >= 2;
572 let mut out = Self::default();
573 Self::decode_field_0(&mut out, buf, version, flex)?;
574 Self::decode_field_1(&mut out, buf, version, flex)?;
575 Self::decode_field_2(&mut out, buf, version, flex)?;
576 Self::decode_field_3(&mut out, buf, version, flex)?;
577 Self::decode_field_4(&mut out, buf, version, flex)?;
578 Self::decode_field_5(&mut out, buf, version, flex)?;
579 Self::decode_field_6(&mut out, buf, version, flex)?;
580 Self::decode_field_7(&mut out, buf, version, flex)?;
581 Self::decode_field_8(&mut out, buf, version, flex)?;
582 Self::decode_tagged_fields(&mut out, buf, version, flex)?;
583 Ok(out)
584 }
585}
586#[cfg(test)]
587impl DeleteAclsMatchingAcl {
588 #[must_use]
589 pub fn populated(version: i16) -> Self {
590 let mut m = Self::default();
591 if version >= 0 {
592 m.error_code = 1i16;
593 }
594 if version >= 0 {
595 m.error_message = Some("x".to_owned());
596 }
597 if version >= 0 {
598 m.resource_type = 1i8;
599 }
600 if version >= 0 {
601 m.resource_name = "x".to_owned();
602 }
603 if version >= 1 {
604 m.pattern_type = 1i8;
605 }
606 if version >= 0 {
607 m.principal = "x".to_owned();
608 }
609 if version >= 0 {
610 m.host = "x".to_owned();
611 }
612 if version >= 0 {
613 m.operation = 1i8;
614 }
615 if version >= 0 {
616 m.permission_type = 1i8;
617 }
618 m
619 }
620}
621#[must_use]
624#[allow(unused_comparisons)]
625pub fn default_json(_version: i16) -> ::serde_json::Value {
626 let mut obj = ::serde_json::Map::new();
627 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
628 obj.insert(
629 "filterResults".to_owned(),
630 ::serde_json::Value::Array(vec![]),
631 );
632 ::serde_json::Value::Object(obj)
633}