krabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::string_bytes::{
8 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
9 put_string, string_len,
10 },
11 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 41;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 3;
16pub const LATEST_STABLE_VERSION: i16 = 3;
17pub const FLEXIBLE_MIN: i16 = 2;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeDelegationTokenRequest {
25 pub owners: Option<Vec<DescribeDelegationTokenOwner>>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Default for DescribeDelegationTokenRequest {
29 fn default() -> Self {
30 Self {
31 owners: Some(Vec::new()),
32 unknown_tagged_fields: UnknownTaggedFields::default(),
33 }
34 }
35}
36impl Encode for DescribeDelegationTokenRequest {
37 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39 return Err(ProtocolError::UnsupportedVersion {
40 api_key: API_KEY,
41 version,
42 });
43 }
44 let flex = is_flexible(version);
45 if version >= 0 {
46 {
47 let len = (self.owners).as_ref().map(Vec::len);
48 crate::primitives::array::put_nullable_array_len(buf, len, flex);
49 if let Some(v) = &self.owners {
50 for it in v {
51 it.encode(buf, version)?;
52 }
53 }
54 };
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 += {
67 let opt: Option<&Vec<_>> = (self.owners).as_ref();
68 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
69 opt.map(std::vec::Vec::len),
70 flex,
71 );
72 let body: usize =
73 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
74 prefix + body
75 };
76 }
77 if flex {
78 let known_pairs: Vec<(u32, usize)> = Vec::new();
79 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80 }
81 n
82 }
83}
84impl Decode<'_> for DescribeDelegationTokenRequest {
85 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
86 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87 return Err(ProtocolError::UnsupportedVersion {
88 api_key: API_KEY,
89 version,
90 });
91 }
92 let flex = is_flexible(version);
93 let mut out = Self::default();
94 if version >= 0 {
95 out.owners = {
96 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
97 match opt {
98 None => None,
99 Some(n) => {
100 let mut v = Vec::with_capacity(n);
101 for _ in 0..n {
102 v.push(DescribeDelegationTokenOwner::decode(buf, version)?);
103 }
104 Some(v)
105 }
106 }
107 };
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 DescribeDelegationTokenRequest {
117 #[must_use]
118 pub fn populated(version: i16) -> Self {
119 let mut m = Self::default();
120 if version >= 0 {
121 m.owners = Some(vec![DescribeDelegationTokenOwner::populated(version)]);
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq, Default)]
127pub struct DescribeDelegationTokenOwner {
128 pub principal_type: String,
129 pub principal_name: String,
130 pub unknown_tagged_fields: UnknownTaggedFields,
131}
132impl Encode for DescribeDelegationTokenOwner {
133 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134 let flex = version >= 2;
135 if version >= 0 {
136 if flex {
137 let () = put_compact_string(buf, &self.principal_type);
138 } else {
139 let () = put_string(buf, &self.principal_type);
140 }
141 }
142 if version >= 0 {
143 if flex {
144 let () = put_compact_string(buf, &self.principal_name);
145 } else {
146 let () = put_string(buf, &self.principal_name);
147 }
148 }
149 if flex {
150 let tagged = WriteTaggedFields::new();
151 tagged.write(buf, &self.unknown_tagged_fields);
152 }
153 Ok(())
154 }
155 fn encoded_len(&self, version: i16) -> usize {
156 let flex = version >= 2;
157 let mut n: usize = 0;
158 if version >= 0 {
159 n += if flex {
160 compact_string_len(&self.principal_type)
161 } else {
162 string_len(&self.principal_type)
163 };
164 }
165 if version >= 0 {
166 n += if flex {
167 compact_string_len(&self.principal_name)
168 } else {
169 string_len(&self.principal_name)
170 };
171 }
172 if flex {
173 let known_pairs: Vec<(u32, usize)> = Vec::new();
174 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175 }
176 n
177 }
178}
179impl Decode<'_> for DescribeDelegationTokenOwner {
180 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181 let flex = version >= 2;
182 let mut out = Self::default();
183 if version >= 0 {
184 out.principal_type = if flex {
185 get_compact_string_owned(buf)?
186 } else {
187 get_string_owned(buf)?
188 };
189 }
190 if version >= 0 {
191 out.principal_name = if flex {
192 get_compact_string_owned(buf)?
193 } else {
194 get_string_owned(buf)?
195 };
196 }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199 }
200 Ok(out)
201 }
202}
203#[cfg(test)]
204impl DescribeDelegationTokenOwner {
205 #[must_use]
206 pub fn populated(version: i16) -> Self {
207 let mut m = Self::default();
208 if version >= 0 {
209 m.principal_type = "x".to_string();
210 }
211 if version >= 0 {
212 m.principal_name = "x".to_string();
213 }
214 m
215 }
216}
217#[must_use]
220#[allow(unused_comparisons)]
221pub fn default_json(_version: i16) -> ::serde_json::Value {
222 let mut obj = ::serde_json::Map::new();
223 obj.insert("owners".to_string(), ::serde_json::Value::Array(vec![]));
224 ::serde_json::Value::Object(obj)
225}
226impl crate::ProtocolRequest for DescribeDelegationTokenRequest {
227 const API_KEY: i16 = API_KEY;
228 const MIN_VERSION: i16 = MIN_VERSION;
229 const MAX_VERSION: i16 = MAX_VERSION;
230 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
231 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
232 type Response = super::describe_delegation_token_response::DescribeDelegationTokenResponse;
233}