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