crabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenRequest.owned.rs1use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned,
6 put_compact_string, put_string, string_len,
7};
8use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10
11pub const API_KEY: i16 = 41;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 3;
14pub const FLEXIBLE_MIN: i16 = 2;
15
16#[inline]
17fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct DescribeDelegationTokenRequest {
21 pub owners: Option<Vec<DescribeDelegationTokenOwner>>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for DescribeDelegationTokenRequest {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29 }
30 let flex = is_flexible(version);
31 if version >= 0 { { let len = (self.owners).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.owners { for it in v { it.encode(buf, version)?; } } } }
32 if flex {
33 let tagged = WriteTaggedFields::new();
34 tagged.write(buf, &self.unknown_tagged_fields);
35 }
36 Ok(())
37 }
38 fn encoded_len(&self, version: i16) -> usize {
39 let flex = is_flexible(version);
40 let mut n: usize = 0;
41 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.owners).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
42 if flex {
43 let known_pairs: Vec<(u32, usize)> = Vec::new();
44 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
45 }
46 n
47 }
48}
49
50impl<'de> Decode<'de> for DescribeDelegationTokenRequest {
51 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
52 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54 }
55 let flex = is_flexible(version);
56 let mut out = Self::default();
57 if version >= 0 { out.owners = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeDelegationTokenOwner::decode(buf, version)?); } Some(v) } } }; }
58 if flex {
59 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
60 Ok(false)
61 })?;
62 }
63 Ok(out)
64 }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Default)]
68pub struct DescribeDelegationTokenOwner {
69 pub principal_type: String,
70 pub principal_name: String,
71 pub unknown_tagged_fields: UnknownTaggedFields,
72}
73
74impl Encode for DescribeDelegationTokenOwner {
75 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
76 let flex = version >= 2;
77 if version >= 0 { if flex { put_compact_string(buf, &self.principal_type) } else { put_string(buf, &self.principal_type) } }
78 if version >= 0 { if flex { put_compact_string(buf, &self.principal_name) } else { put_string(buf, &self.principal_name) } }
79 if flex {
80 let tagged = WriteTaggedFields::new();
81 tagged.write(buf, &self.unknown_tagged_fields);
82 }
83 Ok(())
84 }
85 fn encoded_len(&self, version: i16) -> usize {
86 let flex = version >= 2;
87 let mut n: usize = 0;
88 if version >= 0 { n += if flex { compact_string_len(&self.principal_type) } else { string_len(&self.principal_type) }; }
89 if version >= 0 { n += if flex { compact_string_len(&self.principal_name) } else { string_len(&self.principal_name) }; }
90 if flex {
91 let known_pairs: Vec<(u32, usize)> = Vec::new();
92 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
93 }
94 n
95 }
96}
97
98impl<'de> Decode<'de> for DescribeDelegationTokenOwner {
99 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
100 let flex = version >= 2;
101 let mut out = Self::default();
102 if version >= 0 { out.principal_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
103 if version >= 0 { out.principal_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
104 if flex {
105 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
106 Ok(false)
107 })?;
108 }
109 Ok(out)
110 }
111}
112
113#[must_use]
116#[allow(unused_comparisons)]
117pub fn default_json(version: i16) -> ::serde_json::Value {
118 let mut obj = ::serde_json::Map::new();
119 obj.insert("owners".to_string(), ::serde_json::Value::Null);
120 ::serde_json::Value::Object(obj)
121}
122
123impl crate::ProtocolRequest for DescribeDelegationTokenRequest {
124 const API_KEY: i16 = API_KEY;
125 const MIN_VERSION: i16 = MIN_VERSION;
126 const MAX_VERSION: i16 = MAX_VERSION;
127 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
128 type Response = super::describe_delegation_token_response::DescribeDelegationTokenResponse;
129}