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