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