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