krabka_protocol/opt/rustwide/workdir/generated/
DescribeAclsResponse.owned.rs1use 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 = 29;
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)]
29pub struct DescribeAclsResponse {
30 pub throttle_time_ms: i32,
31 pub error_code: i16,
32 pub error_message: Option<String>,
33 pub resources: Vec<DescribeAclsResource>,
34 pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Default for DescribeAclsResponse {
37 fn default() -> Self {
38 Self {
39 throttle_time_ms: 0i32,
40 error_code: 0i16,
41 error_message: Some(String::new()),
42 resources: Vec::new(),
43 unknown_tagged_fields: UnknownTaggedFields::default(),
44 }
45 }
46}
47impl Encode for DescribeAclsResponse {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion {
51 api_key: API_KEY,
52 version,
53 });
54 }
55 let flex = is_flexible(version);
56 if version >= 0 {
57 put_i32(buf, self.throttle_time_ms);
58 }
59 if version >= 0 {
60 put_i16(buf, self.error_code);
61 }
62 if version >= 0 {
63 if flex {
64 put_compact_nullable_string(buf, self.error_message.as_deref())?;
65 } else {
66 put_nullable_string(buf, self.error_message.as_deref())?;
67 }
68 }
69 if version >= 0 {
70 {
71 put_array_len(buf, (self.resources).len(), flex)?;
72 for it in &self.resources {
73 it.encode(buf, version)?;
74 }
75 }
76 }
77 if flex {
78 let tagged = WriteTaggedFields::new();
79 tagged.write(buf, &self.unknown_tagged_fields)?;
80 }
81 Ok(())
82 }
83 fn encoded_len(&self, version: i16) -> usize {
84 let flex = is_flexible(version);
85 let mut n: usize = 0;
86 if version >= 0 {
87 n += 4;
88 }
89 if version >= 0 {
90 n += 2;
91 }
92 if version >= 0 {
93 n += if flex {
94 compact_nullable_string_len(self.error_message.as_deref())
95 } else {
96 nullable_string_len(self.error_message.as_deref())
97 };
98 }
99 if version >= 0 {
100 n += {
101 let prefix = 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 = 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_owned());
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 put_compact_string(buf, &self.resource_name)?;
203 } else {
204 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 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 = array_len_prefix_len((self.acls).len(), flex);
243 let body: usize = (self.acls).iter().map(|it| it.encoded_len(version)).sum();
244 prefix + body
245 };
246 }
247 if flex {
248 let known_pairs: Vec<(u32, usize)> = Vec::new();
249 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
250 }
251 n
252 }
253}
254impl Decode<'_> for DescribeAclsResource {
255 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
256 let flex = version >= 2;
257 let mut out = Self::default();
258 if version >= 0 {
259 out.resource_type = get_i8(buf)?;
260 }
261 if version >= 0 {
262 out.resource_name = if flex {
263 get_compact_string_owned(buf)?
264 } else {
265 get_string_owned(buf)?
266 };
267 }
268 if version >= 1 {
269 out.pattern_type = get_i8(buf)?;
270 }
271 if version >= 0 {
272 out.acls = {
273 let n = get_array_len(buf, flex)?;
274 let mut v = Vec::with_capacity(n);
275 for _ in 0..n {
276 v.push(AclDescription::decode(buf, version)?);
277 }
278 v
279 };
280 }
281 if flex {
282 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
283 }
284 Ok(out)
285 }
286}
287#[cfg(test)]
288impl DescribeAclsResource {
289 #[must_use]
290 pub fn populated(version: i16) -> Self {
291 let mut m = Self::default();
292 if version >= 0 {
293 m.resource_type = 1i8;
294 }
295 if version >= 0 {
296 m.resource_name = "x".to_owned();
297 }
298 if version >= 1 {
299 m.pattern_type = 1i8;
300 }
301 if version >= 0 {
302 m.acls = vec![AclDescription::populated(version)];
303 }
304 m
305 }
306}
307#[derive(Debug, Clone, PartialEq, Eq, Default)]
308pub struct AclDescription {
309 pub principal: String,
310 pub host: String,
311 pub operation: i8,
312 pub permission_type: i8,
313 pub unknown_tagged_fields: UnknownTaggedFields,
314}
315impl Encode for AclDescription {
316 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
317 let flex = version >= 2;
318 if version >= 0 {
319 if flex {
320 put_compact_string(buf, &self.principal)?;
321 } else {
322 put_string(buf, &self.principal)?;
323 }
324 }
325 if version >= 0 {
326 if flex {
327 put_compact_string(buf, &self.host)?;
328 } else {
329 put_string(buf, &self.host)?;
330 }
331 }
332 if version >= 0 {
333 put_i8(buf, self.operation);
334 }
335 if version >= 0 {
336 put_i8(buf, self.permission_type);
337 }
338 if flex {
339 let tagged = WriteTaggedFields::new();
340 tagged.write(buf, &self.unknown_tagged_fields)?;
341 }
342 Ok(())
343 }
344 fn encoded_len(&self, version: i16) -> usize {
345 let flex = version >= 2;
346 let mut n: usize = 0;
347 if version >= 0 {
348 n += if flex {
349 compact_string_len(&self.principal)
350 } else {
351 string_len(&self.principal)
352 };
353 }
354 if version >= 0 {
355 n += if flex {
356 compact_string_len(&self.host)
357 } else {
358 string_len(&self.host)
359 };
360 }
361 if version >= 0 {
362 n += 1;
363 }
364 if version >= 0 {
365 n += 1;
366 }
367 if flex {
368 let known_pairs: Vec<(u32, usize)> = Vec::new();
369 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
370 }
371 n
372 }
373}
374impl Decode<'_> for AclDescription {
375 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
376 let flex = version >= 2;
377 let mut out = Self::default();
378 if version >= 0 {
379 out.principal = if flex {
380 get_compact_string_owned(buf)?
381 } else {
382 get_string_owned(buf)?
383 };
384 }
385 if version >= 0 {
386 out.host = if flex {
387 get_compact_string_owned(buf)?
388 } else {
389 get_string_owned(buf)?
390 };
391 }
392 if version >= 0 {
393 out.operation = get_i8(buf)?;
394 }
395 if version >= 0 {
396 out.permission_type = get_i8(buf)?;
397 }
398 if flex {
399 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
400 }
401 Ok(out)
402 }
403}
404#[cfg(test)]
405impl AclDescription {
406 #[must_use]
407 pub fn populated(version: i16) -> Self {
408 let mut m = Self::default();
409 if version >= 0 {
410 m.principal = "x".to_owned();
411 }
412 if version >= 0 {
413 m.host = "x".to_owned();
414 }
415 if version >= 0 {
416 m.operation = 1i8;
417 }
418 if version >= 0 {
419 m.permission_type = 1i8;
420 }
421 m
422 }
423}
424#[must_use]
427#[allow(unused_comparisons)]
428pub fn default_json(_version: i16) -> ::serde_json::Value {
429 let mut obj = ::serde_json::Map::new();
430 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
431 obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
432 obj.insert(
433 "errorMessage".to_owned(),
434 ::serde_json::Value::String(String::new()),
435 );
436 obj.insert("resources".to_owned(), ::serde_json::Value::Array(vec![]));
437 ::serde_json::Value::Object(obj)
438}