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