crabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenResponse.borrowed.rs1use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
3use crate::primitives::string_bytes::{
4 compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes::{put_bytes, put_compact_bytes};
7use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
8use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{BufMut, Bytes};
12pub const API_KEY: i16 = 41;
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 DescribeDelegationTokenResponse<'a> {
22 pub error_code: i16,
23 pub tokens: Vec<DescribedDelegationToken<'a>>,
24 pub throttle_time_ms: i32,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl DescribeDelegationTokenResponse<'_> {
28 pub fn to_owned(
29 &self,
30 ) -> crate::owned::describe_delegation_token_response::DescribeDelegationTokenResponse {
31 crate::owned::describe_delegation_token_response::DescribeDelegationTokenResponse {
32 error_code: (self.error_code),
33 tokens: (self.tokens)
34 .iter()
35 .map(DescribedDelegationToken::to_owned)
36 .collect(),
37 throttle_time_ms: (self.throttle_time_ms),
38 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
39 }
40 }
41}
42impl Encode for DescribeDelegationTokenResponse<'_> {
43 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45 return Err(ProtocolError::UnsupportedVersion {
46 api_key: API_KEY,
47 version,
48 });
49 }
50 let flex = is_flexible(version);
51 if version >= 0 {
52 put_i16(buf, self.error_code);
53 }
54 if version >= 0 {
55 {
56 crate::primitives::array::put_array_len(buf, (self.tokens).len(), flex);
57 for it in &self.tokens {
58 it.encode(buf, version)?;
59 }
60 }
61 }
62 if version >= 0 {
63 put_i32(buf, self.throttle_time_ms);
64 }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields);
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 0 {
75 n += 2;
76 }
77 if version >= 0 {
78 n += {
79 let prefix =
80 crate::primitives::array::array_len_prefix_len((self.tokens).len(), flex);
81 let body: usize = (self.tokens).iter().map(|it| it.encoded_len(version)).sum();
82 prefix + body
83 };
84 }
85 if version >= 0 {
86 n += 4;
87 }
88 if flex {
89 let known_pairs: Vec<(u32, usize)> = Vec::new();
90 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91 }
92 n
93 }
94}
95impl<'de> DecodeBorrow<'de> for DescribeDelegationTokenResponse<'de> {
96 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
97 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98 return Err(ProtocolError::UnsupportedVersion {
99 api_key: API_KEY,
100 version,
101 });
102 }
103 let flex = is_flexible(version);
104 let mut out = Self::default();
105 if version >= 0 {
106 out.error_code = get_i16(buf)?;
107 }
108 if version >= 0 {
109 out.tokens = {
110 let n = crate::primitives::array::get_array_len(buf, flex)?;
111 let mut v = Vec::with_capacity(n);
112 for _ in 0..n {
113 v.push(DescribedDelegationToken::decode_borrow(buf, version)?);
114 }
115 v
116 };
117 }
118 if version >= 0 {
119 out.throttle_time_ms = get_i32(buf)?;
120 }
121 if flex {
122 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
123 }
124 Ok(out)
125 }
126}
127#[cfg(test)]
128impl DescribeDelegationTokenResponse<'_> {
129 #[must_use]
130 pub fn populated(version: i16) -> Self {
131 let mut m = Self::default();
132 if version >= 0 {
133 m.error_code = 1i16;
134 }
135 if version >= 0 {
136 m.tokens = vec![DescribedDelegationToken::populated(version)];
137 }
138 if version >= 0 {
139 m.throttle_time_ms = 1i32;
140 }
141 m
142 }
143}
144#[derive(Debug, Clone, PartialEq, Eq, Default)]
145pub struct DescribedDelegationToken<'a> {
146 pub principal_type: &'a str,
147 pub principal_name: &'a str,
148 pub token_requester_principal_type: &'a str,
149 pub token_requester_principal_name: &'a str,
150 pub issue_timestamp: i64,
151 pub expiry_timestamp: i64,
152 pub max_timestamp: i64,
153 pub token_id: &'a str,
154 pub hmac: &'a [u8],
155 pub renewers: Vec<DescribedDelegationTokenRenewer<'a>>,
156 pub unknown_tagged_fields: UnknownTaggedFields,
157}
158impl DescribedDelegationToken<'_> {
159 pub fn to_owned(
160 &self,
161 ) -> crate::owned::describe_delegation_token_response::DescribedDelegationToken {
162 crate::owned::describe_delegation_token_response::DescribedDelegationToken {
163 principal_type: (self.principal_type).to_string(),
164 principal_name: (self.principal_name).to_string(),
165 token_requester_principal_type: (self.token_requester_principal_type).to_string(),
166 token_requester_principal_name: (self.token_requester_principal_name).to_string(),
167 issue_timestamp: (self.issue_timestamp),
168 expiry_timestamp: (self.expiry_timestamp),
169 max_timestamp: (self.max_timestamp),
170 token_id: (self.token_id).to_string(),
171 hmac: Bytes::copy_from_slice(self.hmac),
172 renewers: (self.renewers)
173 .iter()
174 .map(DescribedDelegationTokenRenewer::to_owned)
175 .collect(),
176 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
177 }
178 }
179}
180impl Encode for DescribedDelegationToken<'_> {
181 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
182 let flex = version >= 2;
183 if version >= 0 {
184 if flex {
185 put_compact_string(buf, self.principal_type);
186 } else {
187 put_string(buf, self.principal_type);
188 }
189 }
190 if version >= 0 {
191 if flex {
192 put_compact_string(buf, self.principal_name);
193 } else {
194 put_string(buf, self.principal_name);
195 }
196 }
197 if version >= 3 {
198 if flex {
199 put_compact_string(buf, self.token_requester_principal_type);
200 } else {
201 put_string(buf, self.token_requester_principal_type);
202 }
203 }
204 if version >= 3 {
205 if flex {
206 put_compact_string(buf, self.token_requester_principal_name);
207 } else {
208 put_string(buf, self.token_requester_principal_name);
209 }
210 }
211 if version >= 0 {
212 put_i64(buf, self.issue_timestamp);
213 }
214 if version >= 0 {
215 put_i64(buf, self.expiry_timestamp);
216 }
217 if version >= 0 {
218 put_i64(buf, self.max_timestamp);
219 }
220 if version >= 0 {
221 if flex {
222 put_compact_string(buf, self.token_id);
223 } else {
224 put_string(buf, self.token_id);
225 }
226 }
227 if version >= 0 {
228 if flex {
229 put_compact_bytes(buf, self.hmac);
230 } else {
231 put_bytes(buf, self.hmac);
232 }
233 }
234 if version >= 0 {
235 {
236 crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex);
237 for it in &self.renewers {
238 it.encode(buf, version)?;
239 }
240 }
241 }
242 if flex {
243 let tagged = WriteTaggedFields::new();
244 tagged.write(buf, &self.unknown_tagged_fields);
245 }
246 Ok(())
247 }
248 fn encoded_len(&self, version: i16) -> usize {
249 let flex = version >= 2;
250 let mut n: usize = 0;
251 if version >= 0 {
252 n += if flex {
253 compact_string_len(self.principal_type)
254 } else {
255 string_len(self.principal_type)
256 };
257 }
258 if version >= 0 {
259 n += if flex {
260 compact_string_len(self.principal_name)
261 } else {
262 string_len(self.principal_name)
263 };
264 }
265 if version >= 3 {
266 n += if flex {
267 compact_string_len(self.token_requester_principal_type)
268 } else {
269 string_len(self.token_requester_principal_type)
270 };
271 }
272 if version >= 3 {
273 n += if flex {
274 compact_string_len(self.token_requester_principal_name)
275 } else {
276 string_len(self.token_requester_principal_name)
277 };
278 }
279 if version >= 0 {
280 n += 8;
281 }
282 if version >= 0 {
283 n += 8;
284 }
285 if version >= 0 {
286 n += 8;
287 }
288 if version >= 0 {
289 n += if flex {
290 compact_string_len(self.token_id)
291 } else {
292 string_len(self.token_id)
293 };
294 }
295 if version >= 0 {
296 n += if flex {
297 crate::primitives::varint::uvarint_len(
298 u32::try_from((self.hmac).len() + 1).unwrap(),
299 ) + (self.hmac).len()
300 } else {
301 4 + (self.hmac).len()
302 };
303 }
304 if version >= 0 {
305 n += {
306 let prefix =
307 crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex);
308 let body: usize = (self.renewers)
309 .iter()
310 .map(|it| it.encoded_len(version))
311 .sum();
312 prefix + body
313 };
314 }
315 if flex {
316 let known_pairs: Vec<(u32, usize)> = Vec::new();
317 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
318 }
319 n
320 }
321}
322impl<'de> DecodeBorrow<'de> for DescribedDelegationToken<'de> {
323 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
324 let flex = version >= 2;
325 let mut out = Self::default();
326 if version >= 0 {
327 out.principal_type = if flex {
328 get_compact_string_borrowed(buf)?
329 } else {
330 get_string_borrowed(buf)?
331 };
332 }
333 if version >= 0 {
334 out.principal_name = if flex {
335 get_compact_string_borrowed(buf)?
336 } else {
337 get_string_borrowed(buf)?
338 };
339 }
340 if version >= 3 {
341 out.token_requester_principal_type = if flex {
342 get_compact_string_borrowed(buf)?
343 } else {
344 get_string_borrowed(buf)?
345 };
346 }
347 if version >= 3 {
348 out.token_requester_principal_name = if flex {
349 get_compact_string_borrowed(buf)?
350 } else {
351 get_string_borrowed(buf)?
352 };
353 }
354 if version >= 0 {
355 out.issue_timestamp = get_i64(buf)?;
356 }
357 if version >= 0 {
358 out.expiry_timestamp = get_i64(buf)?;
359 }
360 if version >= 0 {
361 out.max_timestamp = get_i64(buf)?;
362 }
363 if version >= 0 {
364 out.token_id = if flex {
365 get_compact_string_borrowed(buf)?
366 } else {
367 get_string_borrowed(buf)?
368 };
369 }
370 if version >= 0 {
371 out.hmac = if flex {
372 get_compact_bytes_borrowed(buf)?
373 } else {
374 get_bytes_borrowed(buf)?
375 };
376 }
377 if version >= 0 {
378 out.renewers = {
379 let n = crate::primitives::array::get_array_len(buf, flex)?;
380 let mut v = Vec::with_capacity(n);
381 for _ in 0..n {
382 v.push(DescribedDelegationTokenRenewer::decode_borrow(
383 buf, version,
384 )?);
385 }
386 v
387 };
388 }
389 if flex {
390 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
391 }
392 Ok(out)
393 }
394}
395#[cfg(test)]
396impl DescribedDelegationToken<'_> {
397 #[must_use]
398 pub fn populated(version: i16) -> Self {
399 let mut m = Self::default();
400 if version >= 0 {
401 m.principal_type = "x";
402 }
403 if version >= 0 {
404 m.principal_name = "x";
405 }
406 if version >= 3 {
407 m.token_requester_principal_type = "x";
408 }
409 if version >= 3 {
410 m.token_requester_principal_name = "x";
411 }
412 if version >= 0 {
413 m.issue_timestamp = 1i64;
414 }
415 if version >= 0 {
416 m.expiry_timestamp = 1i64;
417 }
418 if version >= 0 {
419 m.max_timestamp = 1i64;
420 }
421 if version >= 0 {
422 m.token_id = "x";
423 }
424 if version >= 0 {
425 m.hmac = &b"x"[..];
426 }
427 if version >= 0 {
428 m.renewers = vec![DescribedDelegationTokenRenewer::populated(version)];
429 }
430 m
431 }
432}
433#[derive(Debug, Clone, PartialEq, Eq, Default)]
434pub struct DescribedDelegationTokenRenewer<'a> {
435 pub principal_type: &'a str,
436 pub principal_name: &'a str,
437 pub unknown_tagged_fields: UnknownTaggedFields,
438}
439impl DescribedDelegationTokenRenewer<'_> {
440 pub fn to_owned(
441 &self,
442 ) -> crate::owned::describe_delegation_token_response::DescribedDelegationTokenRenewer {
443 crate::owned::describe_delegation_token_response::DescribedDelegationTokenRenewer {
444 principal_type: (self.principal_type).to_string(),
445 principal_name: (self.principal_name).to_string(),
446 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
447 }
448 }
449}
450impl Encode for DescribedDelegationTokenRenewer<'_> {
451 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
452 let flex = version >= 2;
453 if version >= 0 {
454 if flex {
455 put_compact_string(buf, self.principal_type);
456 } else {
457 put_string(buf, self.principal_type);
458 }
459 }
460 if version >= 0 {
461 if flex {
462 put_compact_string(buf, self.principal_name);
463 } else {
464 put_string(buf, self.principal_name);
465 }
466 }
467 if flex {
468 let tagged = WriteTaggedFields::new();
469 tagged.write(buf, &self.unknown_tagged_fields);
470 }
471 Ok(())
472 }
473 fn encoded_len(&self, version: i16) -> usize {
474 let flex = version >= 2;
475 let mut n: usize = 0;
476 if version >= 0 {
477 n += if flex {
478 compact_string_len(self.principal_type)
479 } else {
480 string_len(self.principal_type)
481 };
482 }
483 if version >= 0 {
484 n += if flex {
485 compact_string_len(self.principal_name)
486 } else {
487 string_len(self.principal_name)
488 };
489 }
490 if flex {
491 let known_pairs: Vec<(u32, usize)> = Vec::new();
492 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
493 }
494 n
495 }
496}
497impl<'de> DecodeBorrow<'de> for DescribedDelegationTokenRenewer<'de> {
498 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
499 let flex = version >= 2;
500 let mut out = Self::default();
501 if version >= 0 {
502 out.principal_type = if flex {
503 get_compact_string_borrowed(buf)?
504 } else {
505 get_string_borrowed(buf)?
506 };
507 }
508 if version >= 0 {
509 out.principal_name = if flex {
510 get_compact_string_borrowed(buf)?
511 } else {
512 get_string_borrowed(buf)?
513 };
514 }
515 if flex {
516 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
517 }
518 Ok(out)
519 }
520}
521#[cfg(test)]
522impl DescribedDelegationTokenRenewer<'_> {
523 #[must_use]
524 pub fn populated(version: i16) -> Self {
525 let mut m = Self::default();
526 if version >= 0 {
527 m.principal_type = "x";
528 }
529 if version >= 0 {
530 m.principal_name = "x";
531 }
532 m
533 }
534}