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