crabka_protocol/opt/rustwide/workdir/generated/
CreateDelegationTokenRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i64, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 38;
15pub const MIN_VERSION: i16 = 1;
16pub const MAX_VERSION: i16 = 3;
17pub const FLEXIBLE_MIN: i16 = 2;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct CreateDelegationTokenRequest {
26 pub owner_principal_type: Option<String>,
27 pub owner_principal_name: Option<String>,
28 pub renewers: Vec<CreatableRenewers>,
29 pub max_lifetime_ms: i64,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for CreateDelegationTokenRequest {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 3 {
42 if flex {
43 put_compact_nullable_string(buf, self.owner_principal_type.as_deref());
44 } else {
45 put_nullable_string(buf, self.owner_principal_type.as_deref());
46 }
47 }
48 if version >= 3 {
49 if flex {
50 put_compact_nullable_string(buf, self.owner_principal_name.as_deref());
51 } else {
52 put_nullable_string(buf, self.owner_principal_name.as_deref());
53 }
54 }
55 if version >= 0 {
56 {
57 crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex);
58 for it in &self.renewers {
59 it.encode(buf, version)?;
60 }
61 }
62 }
63 if version >= 0 {
64 put_i64(buf, self.max_lifetime_ms);
65 }
66 if flex {
67 let tagged = WriteTaggedFields::new();
68 tagged.write(buf, &self.unknown_tagged_fields);
69 }
70 Ok(())
71 }
72 fn encoded_len(&self, version: i16) -> usize {
73 let flex = is_flexible(version);
74 let mut n: usize = 0;
75 if version >= 3 {
76 n += if flex {
77 compact_nullable_string_len(self.owner_principal_type.as_deref())
78 } else {
79 nullable_string_len(self.owner_principal_type.as_deref())
80 };
81 }
82 if version >= 3 {
83 n += if flex {
84 compact_nullable_string_len(self.owner_principal_name.as_deref())
85 } else {
86 nullable_string_len(self.owner_principal_name.as_deref())
87 };
88 }
89 if version >= 0 {
90 n += {
91 let prefix =
92 crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex);
93 let body: usize = (self.renewers)
94 .iter()
95 .map(|it| it.encoded_len(version))
96 .sum();
97 prefix + body
98 };
99 }
100 if version >= 0 {
101 n += 8;
102 }
103 if flex {
104 let known_pairs: Vec<(u32, usize)> = Vec::new();
105 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
106 }
107 n
108 }
109}
110impl Decode<'_> for CreateDelegationTokenRequest {
111 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
112 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
113 return Err(ProtocolError::UnsupportedVersion {
114 api_key: API_KEY,
115 version,
116 });
117 }
118 let flex = is_flexible(version);
119 let mut out = Self::default();
120 if version >= 3 {
121 out.owner_principal_type = if flex {
122 get_compact_nullable_string_owned(buf)?
123 } else {
124 get_nullable_string_owned(buf)?
125 };
126 }
127 if version >= 3 {
128 out.owner_principal_name = if flex {
129 get_compact_nullable_string_owned(buf)?
130 } else {
131 get_nullable_string_owned(buf)?
132 };
133 }
134 if version >= 0 {
135 out.renewers = {
136 let n = crate::primitives::array::get_array_len(buf, flex)?;
137 let mut v = Vec::with_capacity(n);
138 for _ in 0..n {
139 v.push(CreatableRenewers::decode(buf, version)?);
140 }
141 v
142 };
143 }
144 if version >= 0 {
145 out.max_lifetime_ms = get_i64(buf)?;
146 }
147 if flex {
148 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
149 }
150 Ok(out)
151 }
152}
153#[cfg(test)]
154impl CreateDelegationTokenRequest {
155 #[must_use]
156 pub fn populated(version: i16) -> Self {
157 let mut m = Self::default();
158 if version >= 3 {
159 m.owner_principal_type = Some("x".to_string());
160 }
161 if version >= 3 {
162 m.owner_principal_name = Some("x".to_string());
163 }
164 if version >= 0 {
165 m.renewers = vec![CreatableRenewers::populated(version)];
166 }
167 if version >= 0 {
168 m.max_lifetime_ms = 1i64;
169 }
170 m
171 }
172}
173#[derive(Debug, Clone, PartialEq, Eq, Default)]
174pub struct CreatableRenewers {
175 pub principal_type: String,
176 pub principal_name: String,
177 pub unknown_tagged_fields: UnknownTaggedFields,
178}
179impl Encode for CreatableRenewers {
180 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
181 let flex = version >= 2;
182 if version >= 0 {
183 if flex {
184 put_compact_string(buf, &self.principal_type);
185 } else {
186 put_string(buf, &self.principal_type);
187 }
188 }
189 if version >= 0 {
190 if flex {
191 put_compact_string(buf, &self.principal_name);
192 } else {
193 put_string(buf, &self.principal_name);
194 }
195 }
196 if flex {
197 let tagged = WriteTaggedFields::new();
198 tagged.write(buf, &self.unknown_tagged_fields);
199 }
200 Ok(())
201 }
202 fn encoded_len(&self, version: i16) -> usize {
203 let flex = version >= 2;
204 let mut n: usize = 0;
205 if version >= 0 {
206 n += if flex {
207 compact_string_len(&self.principal_type)
208 } else {
209 string_len(&self.principal_type)
210 };
211 }
212 if version >= 0 {
213 n += if flex {
214 compact_string_len(&self.principal_name)
215 } else {
216 string_len(&self.principal_name)
217 };
218 }
219 if flex {
220 let known_pairs: Vec<(u32, usize)> = Vec::new();
221 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
222 }
223 n
224 }
225}
226impl Decode<'_> for CreatableRenewers {
227 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
228 let flex = version >= 2;
229 let mut out = Self::default();
230 if version >= 0 {
231 out.principal_type = if flex {
232 get_compact_string_owned(buf)?
233 } else {
234 get_string_owned(buf)?
235 };
236 }
237 if version >= 0 {
238 out.principal_name = if flex {
239 get_compact_string_owned(buf)?
240 } else {
241 get_string_owned(buf)?
242 };
243 }
244 if flex {
245 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
246 }
247 Ok(out)
248 }
249}
250#[cfg(test)]
251impl CreatableRenewers {
252 #[must_use]
253 pub fn populated(version: i16) -> Self {
254 let mut m = Self::default();
255 if version >= 0 {
256 m.principal_type = "x".to_string();
257 }
258 if version >= 0 {
259 m.principal_name = "x".to_string();
260 }
261 m
262 }
263}
264
265#[must_use]
268#[allow(unused_comparisons)]
269pub fn default_json(version: i16) -> ::serde_json::Value {
270 let mut obj = ::serde_json::Map::new();
271 if version >= 3 {
272 obj.insert("ownerPrincipalType".to_string(), ::serde_json::Value::Null);
273 }
274 if version >= 3 {
275 obj.insert("ownerPrincipalName".to_string(), ::serde_json::Value::Null);
276 }
277 obj.insert("renewers".to_string(), ::serde_json::Value::Array(vec![]));
278 obj.insert("maxLifetimeMs".to_string(), ::serde_json::json!(0));
279 ::serde_json::Value::Object(obj)
280}
281
282impl crate::ProtocolRequest for CreateDelegationTokenRequest {
283 const API_KEY: i16 = API_KEY;
284 const MIN_VERSION: i16 = MIN_VERSION;
285 const MAX_VERSION: i16 = MAX_VERSION;
286 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
287 type Response = super::create_delegation_token_response::CreateDelegationTokenResponse;
288}