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