Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
9        string_bytes::{
10            bytes_len, compact_bytes_len, compact_string_len, get_bytes_owned,
11            get_compact_bytes_owned, get_compact_string_owned, get_string_owned, put_bytes,
12            put_compact_bytes, put_compact_string, put_string, string_len,
13        },
14    },
15    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
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#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct DescribeDelegationTokenResponse {
28    pub error_code: i16,
29    pub tokens: Vec<DescribedDelegationToken>,
30    pub throttle_time_ms: i32,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DescribeDelegationTokenResponse {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion {
37                api_key: API_KEY,
38                version,
39            });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            put_i16(buf, self.error_code);
44        }
45        if version >= 0 {
46            {
47                crate::primitives::array::put_array_len(buf, (self.tokens).len(), flex);
48                for it in &self.tokens {
49                    it.encode(buf, version)?;
50                }
51            };
52        }
53        if version >= 0 {
54            put_i32(buf, self.throttle_time_ms);
55        }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields);
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 {
66            n += 2;
67        }
68        if version >= 0 {
69            n += {
70                let prefix =
71                    crate::primitives::array::array_len_prefix_len((self.tokens).len(), flex);
72                let body: usize = (self.tokens).iter().map(|it| it.encoded_len(version)).sum();
73                prefix + body
74            };
75        }
76        if version >= 0 {
77            n += 4;
78        }
79        if flex {
80            let known_pairs: Vec<(u32, usize)> = Vec::new();
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86impl Decode<'_> for DescribeDelegationTokenResponse {
87    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
88        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
89            return Err(ProtocolError::UnsupportedVersion {
90                api_key: API_KEY,
91                version,
92            });
93        }
94        let flex = is_flexible(version);
95        let mut out = Self::default();
96        if version >= 0 {
97            out.error_code = get_i16(buf)?;
98        }
99        if version >= 0 {
100            out.tokens = {
101                let n = crate::primitives::array::get_array_len(buf, flex)?;
102                let mut v = Vec::with_capacity(n);
103                for _ in 0..n {
104                    v.push(DescribedDelegationToken::decode(buf, version)?);
105                }
106                v
107            };
108        }
109        if version >= 0 {
110            out.throttle_time_ms = get_i32(buf)?;
111        }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
114        }
115        Ok(out)
116    }
117}
118#[cfg(test)]
119impl DescribeDelegationTokenResponse {
120    #[must_use]
121    pub fn populated(version: i16) -> Self {
122        let mut m = Self::default();
123        if version >= 0 {
124            m.error_code = 1i16;
125        }
126        if version >= 0 {
127            m.tokens = vec![DescribedDelegationToken::populated(version)];
128        }
129        if version >= 0 {
130            m.throttle_time_ms = 1i32;
131        }
132        m
133    }
134}
135#[derive(Debug, Clone, PartialEq, Eq, Default)]
136pub struct DescribedDelegationToken {
137    pub principal_type: String,
138    pub principal_name: String,
139    pub token_requester_principal_type: String,
140    pub token_requester_principal_name: String,
141    pub issue_timestamp: i64,
142    pub expiry_timestamp: i64,
143    pub max_timestamp: i64,
144    pub token_id: String,
145    pub hmac: ::bytes::Bytes,
146    pub renewers: Vec<DescribedDelegationTokenRenewer>,
147    pub unknown_tagged_fields: UnknownTaggedFields,
148}
149impl DescribedDelegationToken {
150    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
151        if version >= 0 {
152            if flex {
153                let () = put_compact_string(buf, &self.principal_type);
154            } else {
155                let () = put_string(buf, &self.principal_type);
156            }
157        }
158    }
159    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
160        if version >= 0 {
161            if flex {
162                let () = put_compact_string(buf, &self.principal_name);
163            } else {
164                let () = put_string(buf, &self.principal_name);
165            }
166        }
167    }
168    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
169        if version >= 3 {
170            if flex {
171                let () = put_compact_string(buf, &self.token_requester_principal_type);
172            } else {
173                let () = put_string(buf, &self.token_requester_principal_type);
174            }
175        }
176    }
177    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
178        if version >= 3 {
179            if flex {
180                let () = put_compact_string(buf, &self.token_requester_principal_name);
181            } else {
182                let () = put_string(buf, &self.token_requester_principal_name);
183            }
184        }
185    }
186    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
187        if version >= 0 {
188            put_i64(buf, self.issue_timestamp);
189        }
190    }
191    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
192        if version >= 0 {
193            put_i64(buf, self.expiry_timestamp);
194        }
195    }
196    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
197        if version >= 0 {
198            put_i64(buf, self.max_timestamp);
199        }
200    }
201    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
202        if version >= 0 {
203            if flex {
204                let () = put_compact_string(buf, &self.token_id);
205            } else {
206                let () = put_string(buf, &self.token_id);
207            }
208        }
209    }
210    fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
211        if version >= 0 {
212            if flex {
213                let () = put_compact_bytes(buf, &self.hmac);
214            } else {
215                let () = put_bytes(buf, &self.hmac);
216            }
217        }
218    }
219    fn encode_field_9<B: BufMut>(
220        &self,
221        buf: &mut B,
222        version: i16,
223        flex: bool,
224    ) -> Result<(), ProtocolError> {
225        if version >= 0 {
226            {
227                crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex);
228                for it in &self.renewers {
229                    it.encode(buf, version)?;
230                }
231            };
232        }
233        Ok(())
234    }
235    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
236        if flex {
237            let tagged = WriteTaggedFields::new();
238            tagged.write(buf, &self.unknown_tagged_fields);
239        }
240    }
241    fn decode_field_0<B: Buf>(
242        out: &mut Self,
243        buf: &mut B,
244        version: i16,
245        flex: bool,
246    ) -> Result<(), ProtocolError> {
247        if version >= 0 {
248            out.principal_type = if flex {
249                get_compact_string_owned(buf)?
250            } else {
251                get_string_owned(buf)?
252            };
253        }
254        Ok(())
255    }
256    fn decode_field_1<B: Buf>(
257        out: &mut Self,
258        buf: &mut B,
259        version: i16,
260        flex: bool,
261    ) -> Result<(), ProtocolError> {
262        if version >= 0 {
263            out.principal_name = if flex {
264                get_compact_string_owned(buf)?
265            } else {
266                get_string_owned(buf)?
267            };
268        }
269        Ok(())
270    }
271    fn decode_field_2<B: Buf>(
272        out: &mut Self,
273        buf: &mut B,
274        version: i16,
275        flex: bool,
276    ) -> Result<(), ProtocolError> {
277        if version >= 3 {
278            out.token_requester_principal_type = if flex {
279                get_compact_string_owned(buf)?
280            } else {
281                get_string_owned(buf)?
282            };
283        }
284        Ok(())
285    }
286    fn decode_field_3<B: Buf>(
287        out: &mut Self,
288        buf: &mut B,
289        version: i16,
290        flex: bool,
291    ) -> Result<(), ProtocolError> {
292        if version >= 3 {
293            out.token_requester_principal_name = if flex {
294                get_compact_string_owned(buf)?
295            } else {
296                get_string_owned(buf)?
297            };
298        }
299        Ok(())
300    }
301    fn decode_field_4<B: Buf>(
302        out: &mut Self,
303        buf: &mut B,
304        version: i16,
305        _flex: bool,
306    ) -> Result<(), ProtocolError> {
307        if version >= 0 {
308            out.issue_timestamp = get_i64(buf)?;
309        }
310        Ok(())
311    }
312    fn decode_field_5<B: Buf>(
313        out: &mut Self,
314        buf: &mut B,
315        version: i16,
316        _flex: bool,
317    ) -> Result<(), ProtocolError> {
318        if version >= 0 {
319            out.expiry_timestamp = get_i64(buf)?;
320        }
321        Ok(())
322    }
323    fn decode_field_6<B: Buf>(
324        out: &mut Self,
325        buf: &mut B,
326        version: i16,
327        _flex: bool,
328    ) -> Result<(), ProtocolError> {
329        if version >= 0 {
330            out.max_timestamp = get_i64(buf)?;
331        }
332        Ok(())
333    }
334    fn decode_field_7<B: Buf>(
335        out: &mut Self,
336        buf: &mut B,
337        version: i16,
338        flex: bool,
339    ) -> Result<(), ProtocolError> {
340        if version >= 0 {
341            out.token_id = if flex {
342                get_compact_string_owned(buf)?
343            } else {
344                get_string_owned(buf)?
345            };
346        }
347        Ok(())
348    }
349    fn decode_field_8<B: Buf>(
350        out: &mut Self,
351        buf: &mut B,
352        version: i16,
353        flex: bool,
354    ) -> Result<(), ProtocolError> {
355        if version >= 0 {
356            out.hmac = if flex {
357                get_compact_bytes_owned(buf)?
358            } else {
359                get_bytes_owned(buf)?
360            };
361        }
362        Ok(())
363    }
364    fn decode_field_9<B: Buf>(
365        out: &mut Self,
366        buf: &mut B,
367        version: i16,
368        flex: bool,
369    ) -> Result<(), ProtocolError> {
370        if version >= 0 {
371            out.renewers = {
372                let n = crate::primitives::array::get_array_len(buf, flex)?;
373                let mut v = Vec::with_capacity(n);
374                for _ in 0..n {
375                    v.push(DescribedDelegationTokenRenewer::decode(buf, version)?);
376                }
377                v
378            };
379        }
380        Ok(())
381    }
382    fn decode_tagged_fields<B: Buf>(
383        out: &mut Self,
384        buf: &mut B,
385        _version: i16,
386        flex: bool,
387    ) -> Result<(), ProtocolError> {
388        if flex {
389            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
390        }
391        Ok(())
392    }
393}
394impl Encode for DescribedDelegationToken {
395    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
396        let flex = version >= 2;
397        self.encode_field_0(buf, version, flex);
398        self.encode_field_1(buf, version, flex);
399        self.encode_field_2(buf, version, flex);
400        self.encode_field_3(buf, version, flex);
401        self.encode_field_4(buf, version, flex);
402        self.encode_field_5(buf, version, flex);
403        self.encode_field_6(buf, version, flex);
404        self.encode_field_7(buf, version, flex);
405        self.encode_field_8(buf, version, flex);
406        self.encode_field_9(buf, version, flex)?;
407        self.encode_tagged_fields(buf, version, flex);
408        Ok(())
409    }
410    fn encoded_len(&self, version: i16) -> usize {
411        let flex = version >= 2;
412        let mut n: usize = 0;
413        if version >= 0 {
414            n += if flex {
415                compact_string_len(&self.principal_type)
416            } else {
417                string_len(&self.principal_type)
418            };
419        }
420        if version >= 0 {
421            n += if flex {
422                compact_string_len(&self.principal_name)
423            } else {
424                string_len(&self.principal_name)
425            };
426        }
427        if version >= 3 {
428            n += if flex {
429                compact_string_len(&self.token_requester_principal_type)
430            } else {
431                string_len(&self.token_requester_principal_type)
432            };
433        }
434        if version >= 3 {
435            n += if flex {
436                compact_string_len(&self.token_requester_principal_name)
437            } else {
438                string_len(&self.token_requester_principal_name)
439            };
440        }
441        if version >= 0 {
442            n += 8;
443        }
444        if version >= 0 {
445            n += 8;
446        }
447        if version >= 0 {
448            n += 8;
449        }
450        if version >= 0 {
451            n += if flex {
452                compact_string_len(&self.token_id)
453            } else {
454                string_len(&self.token_id)
455            };
456        }
457        if version >= 0 {
458            n += if flex {
459                compact_bytes_len(&self.hmac)
460            } else {
461                bytes_len(&self.hmac)
462            };
463        }
464        if version >= 0 {
465            n += {
466                let prefix =
467                    crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex);
468                let body: usize = (self.renewers)
469                    .iter()
470                    .map(|it| it.encoded_len(version))
471                    .sum();
472                prefix + body
473            };
474        }
475        if flex {
476            let known_pairs: Vec<(u32, usize)> = Vec::new();
477            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
478        }
479        n
480    }
481}
482impl Decode<'_> for DescribedDelegationToken {
483    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
484        let flex = version >= 2;
485        let mut out = Self::default();
486        Self::decode_field_0(&mut out, buf, version, flex)?;
487        Self::decode_field_1(&mut out, buf, version, flex)?;
488        Self::decode_field_2(&mut out, buf, version, flex)?;
489        Self::decode_field_3(&mut out, buf, version, flex)?;
490        Self::decode_field_4(&mut out, buf, version, flex)?;
491        Self::decode_field_5(&mut out, buf, version, flex)?;
492        Self::decode_field_6(&mut out, buf, version, flex)?;
493        Self::decode_field_7(&mut out, buf, version, flex)?;
494        Self::decode_field_8(&mut out, buf, version, flex)?;
495        Self::decode_field_9(&mut out, buf, version, flex)?;
496        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
497        Ok(out)
498    }
499}
500#[cfg(test)]
501impl DescribedDelegationToken {
502    #[must_use]
503    pub fn populated(version: i16) -> Self {
504        let mut m = Self::default();
505        if version >= 0 {
506            m.principal_type = "x".to_string();
507        }
508        if version >= 0 {
509            m.principal_name = "x".to_string();
510        }
511        if version >= 3 {
512            m.token_requester_principal_type = "x".to_string();
513        }
514        if version >= 3 {
515            m.token_requester_principal_name = "x".to_string();
516        }
517        if version >= 0 {
518            m.issue_timestamp = 1i64;
519        }
520        if version >= 0 {
521            m.expiry_timestamp = 1i64;
522        }
523        if version >= 0 {
524            m.max_timestamp = 1i64;
525        }
526        if version >= 0 {
527            m.token_id = "x".to_string();
528        }
529        if version >= 0 {
530            m.hmac = ::bytes::Bytes::from_static(b"x");
531        }
532        if version >= 0 {
533            m.renewers = vec![DescribedDelegationTokenRenewer::populated(version)];
534        }
535        m
536    }
537}
538#[derive(Debug, Clone, PartialEq, Eq, Default)]
539pub struct DescribedDelegationTokenRenewer {
540    pub principal_type: String,
541    pub principal_name: String,
542    pub unknown_tagged_fields: UnknownTaggedFields,
543}
544impl Encode for DescribedDelegationTokenRenewer {
545    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
546        let flex = version >= 2;
547        if version >= 0 {
548            if flex {
549                let () = put_compact_string(buf, &self.principal_type);
550            } else {
551                let () = put_string(buf, &self.principal_type);
552            }
553        }
554        if version >= 0 {
555            if flex {
556                let () = put_compact_string(buf, &self.principal_name);
557            } else {
558                let () = put_string(buf, &self.principal_name);
559            }
560        }
561        if flex {
562            let tagged = WriteTaggedFields::new();
563            tagged.write(buf, &self.unknown_tagged_fields);
564        }
565        Ok(())
566    }
567    fn encoded_len(&self, version: i16) -> usize {
568        let flex = version >= 2;
569        let mut n: usize = 0;
570        if version >= 0 {
571            n += if flex {
572                compact_string_len(&self.principal_type)
573            } else {
574                string_len(&self.principal_type)
575            };
576        }
577        if version >= 0 {
578            n += if flex {
579                compact_string_len(&self.principal_name)
580            } else {
581                string_len(&self.principal_name)
582            };
583        }
584        if flex {
585            let known_pairs: Vec<(u32, usize)> = Vec::new();
586            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
587        }
588        n
589    }
590}
591impl Decode<'_> for DescribedDelegationTokenRenewer {
592    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
593        let flex = version >= 2;
594        let mut out = Self::default();
595        if version >= 0 {
596            out.principal_type = if flex {
597                get_compact_string_owned(buf)?
598            } else {
599                get_string_owned(buf)?
600            };
601        }
602        if version >= 0 {
603            out.principal_name = if flex {
604                get_compact_string_owned(buf)?
605            } else {
606                get_string_owned(buf)?
607            };
608        }
609        if flex {
610            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
611        }
612        Ok(out)
613    }
614}
615#[cfg(test)]
616impl DescribedDelegationTokenRenewer {
617    #[must_use]
618    pub fn populated(version: i16) -> Self {
619        let mut m = Self::default();
620        if version >= 0 {
621            m.principal_type = "x".to_string();
622        }
623        if version >= 0 {
624            m.principal_name = "x".to_string();
625        }
626        m
627    }
628}
629/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
630/// Only includes fields valid for the given version.
631#[must_use]
632#[allow(unused_comparisons)]
633pub fn default_json(_version: i16) -> ::serde_json::Value {
634    let mut obj = ::serde_json::Map::new();
635    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
636    obj.insert("tokens".to_string(), ::serde_json::Value::Array(vec![]));
637    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
638    ::serde_json::Value::Object(obj)
639}