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