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