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