Skip to main content

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