Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
CreateDelegationTokenResponse.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 = 38;
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 CreateDelegationTokenResponse {
28    pub error_code: i16,
29    pub principal_type: String,
30    pub principal_name: String,
31    pub token_requester_principal_type: String,
32    pub token_requester_principal_name: String,
33    pub issue_timestamp_ms: i64,
34    pub expiry_timestamp_ms: i64,
35    pub max_timestamp_ms: i64,
36    pub token_id: String,
37    pub hmac: ::bytes::Bytes,
38    pub throttle_time_ms: i32,
39    pub unknown_tagged_fields: UnknownTaggedFields,
40}
41impl CreateDelegationTokenResponse {
42    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
43        if version >= 0 {
44            put_i16(buf, self.error_code);
45        }
46    }
47    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
48        if version >= 0 {
49            if flex {
50                let () = put_compact_string(buf, &self.principal_type);
51            } else {
52                let () = put_string(buf, &self.principal_type);
53            }
54        }
55    }
56    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
57        if version >= 0 {
58            if flex {
59                let () = put_compact_string(buf, &self.principal_name);
60            } else {
61                let () = put_string(buf, &self.principal_name);
62            }
63        }
64    }
65    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
66        if version >= 3 {
67            if flex {
68                let () = put_compact_string(buf, &self.token_requester_principal_type);
69            } else {
70                let () = put_string(buf, &self.token_requester_principal_type);
71            }
72        }
73    }
74    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
75        if version >= 3 {
76            if flex {
77                let () = put_compact_string(buf, &self.token_requester_principal_name);
78            } else {
79                let () = put_string(buf, &self.token_requester_principal_name);
80            }
81        }
82    }
83    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
84        if version >= 0 {
85            put_i64(buf, self.issue_timestamp_ms);
86        }
87    }
88    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
89        if version >= 0 {
90            put_i64(buf, self.expiry_timestamp_ms);
91        }
92    }
93    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
94        if version >= 0 {
95            put_i64(buf, self.max_timestamp_ms);
96        }
97    }
98    fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
99        if version >= 0 {
100            if flex {
101                let () = put_compact_string(buf, &self.token_id);
102            } else {
103                let () = put_string(buf, &self.token_id);
104            }
105        }
106    }
107    fn encode_field_9<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
108        if version >= 0 {
109            if flex {
110                let () = put_compact_bytes(buf, &self.hmac);
111            } else {
112                let () = put_bytes(buf, &self.hmac);
113            }
114        }
115    }
116    fn encode_field_10<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
117        if version >= 0 {
118            put_i32(buf, self.throttle_time_ms);
119        }
120    }
121    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
122        if flex {
123            let tagged = WriteTaggedFields::new();
124            tagged.write(buf, &self.unknown_tagged_fields);
125        }
126    }
127    fn decode_field_0<B: Buf>(
128        out: &mut Self,
129        buf: &mut B,
130        version: i16,
131        _flex: bool,
132    ) -> Result<(), ProtocolError> {
133        if version >= 0 {
134            out.error_code = get_i16(buf)?;
135        }
136        Ok(())
137    }
138    fn decode_field_1<B: Buf>(
139        out: &mut Self,
140        buf: &mut B,
141        version: i16,
142        flex: bool,
143    ) -> Result<(), ProtocolError> {
144        if version >= 0 {
145            out.principal_type = if flex {
146                get_compact_string_owned(buf)?
147            } else {
148                get_string_owned(buf)?
149            };
150        }
151        Ok(())
152    }
153    fn decode_field_2<B: Buf>(
154        out: &mut Self,
155        buf: &mut B,
156        version: i16,
157        flex: bool,
158    ) -> Result<(), ProtocolError> {
159        if version >= 0 {
160            out.principal_name = if flex {
161                get_compact_string_owned(buf)?
162            } else {
163                get_string_owned(buf)?
164            };
165        }
166        Ok(())
167    }
168    fn decode_field_3<B: Buf>(
169        out: &mut Self,
170        buf: &mut B,
171        version: i16,
172        flex: bool,
173    ) -> Result<(), ProtocolError> {
174        if version >= 3 {
175            out.token_requester_principal_type = if flex {
176                get_compact_string_owned(buf)?
177            } else {
178                get_string_owned(buf)?
179            };
180        }
181        Ok(())
182    }
183    fn decode_field_4<B: Buf>(
184        out: &mut Self,
185        buf: &mut B,
186        version: i16,
187        flex: bool,
188    ) -> Result<(), ProtocolError> {
189        if version >= 3 {
190            out.token_requester_principal_name = if flex {
191                get_compact_string_owned(buf)?
192            } else {
193                get_string_owned(buf)?
194            };
195        }
196        Ok(())
197    }
198    fn decode_field_5<B: Buf>(
199        out: &mut Self,
200        buf: &mut B,
201        version: i16,
202        _flex: bool,
203    ) -> Result<(), ProtocolError> {
204        if version >= 0 {
205            out.issue_timestamp_ms = get_i64(buf)?;
206        }
207        Ok(())
208    }
209    fn decode_field_6<B: Buf>(
210        out: &mut Self,
211        buf: &mut B,
212        version: i16,
213        _flex: bool,
214    ) -> Result<(), ProtocolError> {
215        if version >= 0 {
216            out.expiry_timestamp_ms = get_i64(buf)?;
217        }
218        Ok(())
219    }
220    fn decode_field_7<B: Buf>(
221        out: &mut Self,
222        buf: &mut B,
223        version: i16,
224        _flex: bool,
225    ) -> Result<(), ProtocolError> {
226        if version >= 0 {
227            out.max_timestamp_ms = get_i64(buf)?;
228        }
229        Ok(())
230    }
231    fn decode_field_8<B: Buf>(
232        out: &mut Self,
233        buf: &mut B,
234        version: i16,
235        flex: bool,
236    ) -> Result<(), ProtocolError> {
237        if version >= 0 {
238            out.token_id = if flex {
239                get_compact_string_owned(buf)?
240            } else {
241                get_string_owned(buf)?
242            };
243        }
244        Ok(())
245    }
246    fn decode_field_9<B: Buf>(
247        out: &mut Self,
248        buf: &mut B,
249        version: i16,
250        flex: bool,
251    ) -> Result<(), ProtocolError> {
252        if version >= 0 {
253            out.hmac = if flex {
254                get_compact_bytes_owned(buf)?
255            } else {
256                get_bytes_owned(buf)?
257            };
258        }
259        Ok(())
260    }
261    fn decode_field_10<B: Buf>(
262        out: &mut Self,
263        buf: &mut B,
264        version: i16,
265        _flex: bool,
266    ) -> Result<(), ProtocolError> {
267        if version >= 0 {
268            out.throttle_time_ms = get_i32(buf)?;
269        }
270        Ok(())
271    }
272    fn decode_tagged_fields<B: Buf>(
273        out: &mut Self,
274        buf: &mut B,
275        _version: i16,
276        flex: bool,
277    ) -> Result<(), ProtocolError> {
278        if flex {
279            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
280        }
281        Ok(())
282    }
283}
284impl Encode for CreateDelegationTokenResponse {
285    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
286        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
287            return Err(ProtocolError::UnsupportedVersion {
288                api_key: API_KEY,
289                version,
290            });
291        }
292        let flex = is_flexible(version);
293        self.encode_field_0(buf, version, flex);
294        self.encode_field_1(buf, version, flex);
295        self.encode_field_2(buf, version, flex);
296        self.encode_field_3(buf, version, flex);
297        self.encode_field_4(buf, version, flex);
298        self.encode_field_5(buf, version, flex);
299        self.encode_field_6(buf, version, flex);
300        self.encode_field_7(buf, version, flex);
301        self.encode_field_8(buf, version, flex);
302        self.encode_field_9(buf, version, flex);
303        self.encode_field_10(buf, version, flex);
304        self.encode_tagged_fields(buf, version, flex);
305        Ok(())
306    }
307    fn encoded_len(&self, version: i16) -> usize {
308        let flex = is_flexible(version);
309        let mut n: usize = 0;
310        if version >= 0 {
311            n += 2;
312        }
313        if version >= 0 {
314            n += if flex {
315                compact_string_len(&self.principal_type)
316            } else {
317                string_len(&self.principal_type)
318            };
319        }
320        if version >= 0 {
321            n += if flex {
322                compact_string_len(&self.principal_name)
323            } else {
324                string_len(&self.principal_name)
325            };
326        }
327        if version >= 3 {
328            n += if flex {
329                compact_string_len(&self.token_requester_principal_type)
330            } else {
331                string_len(&self.token_requester_principal_type)
332            };
333        }
334        if version >= 3 {
335            n += if flex {
336                compact_string_len(&self.token_requester_principal_name)
337            } else {
338                string_len(&self.token_requester_principal_name)
339            };
340        }
341        if version >= 0 {
342            n += 8;
343        }
344        if version >= 0 {
345            n += 8;
346        }
347        if version >= 0 {
348            n += 8;
349        }
350        if version >= 0 {
351            n += if flex {
352                compact_string_len(&self.token_id)
353            } else {
354                string_len(&self.token_id)
355            };
356        }
357        if version >= 0 {
358            n += if flex {
359                compact_bytes_len(&self.hmac)
360            } else {
361                bytes_len(&self.hmac)
362            };
363        }
364        if version >= 0 {
365            n += 4;
366        }
367        if flex {
368            let known_pairs: Vec<(u32, usize)> = Vec::new();
369            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
370        }
371        n
372    }
373}
374impl Decode<'_> for CreateDelegationTokenResponse {
375    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
376        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
377            return Err(ProtocolError::UnsupportedVersion {
378                api_key: API_KEY,
379                version,
380            });
381        }
382        let flex = is_flexible(version);
383        let mut out = Self::default();
384        Self::decode_field_0(&mut out, buf, version, flex)?;
385        Self::decode_field_1(&mut out, buf, version, flex)?;
386        Self::decode_field_2(&mut out, buf, version, flex)?;
387        Self::decode_field_3(&mut out, buf, version, flex)?;
388        Self::decode_field_4(&mut out, buf, version, flex)?;
389        Self::decode_field_5(&mut out, buf, version, flex)?;
390        Self::decode_field_6(&mut out, buf, version, flex)?;
391        Self::decode_field_7(&mut out, buf, version, flex)?;
392        Self::decode_field_8(&mut out, buf, version, flex)?;
393        Self::decode_field_9(&mut out, buf, version, flex)?;
394        Self::decode_field_10(&mut out, buf, version, flex)?;
395        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
396        Ok(out)
397    }
398}
399#[cfg(test)]
400impl CreateDelegationTokenResponse {
401    #[must_use]
402    pub fn populated(version: i16) -> Self {
403        let mut m = Self::default();
404        if version >= 0 {
405            m.error_code = 1i16;
406        }
407        if version >= 0 {
408            m.principal_type = "x".to_string();
409        }
410        if version >= 0 {
411            m.principal_name = "x".to_string();
412        }
413        if version >= 3 {
414            m.token_requester_principal_type = "x".to_string();
415        }
416        if version >= 3 {
417            m.token_requester_principal_name = "x".to_string();
418        }
419        if version >= 0 {
420            m.issue_timestamp_ms = 1i64;
421        }
422        if version >= 0 {
423            m.expiry_timestamp_ms = 1i64;
424        }
425        if version >= 0 {
426            m.max_timestamp_ms = 1i64;
427        }
428        if version >= 0 {
429            m.token_id = "x".to_string();
430        }
431        if version >= 0 {
432            m.hmac = ::bytes::Bytes::from_static(b"x");
433        }
434        if version >= 0 {
435            m.throttle_time_ms = 1i32;
436        }
437        m
438    }
439}
440/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
441/// Only includes fields valid for the given version.
442#[must_use]
443#[allow(unused_comparisons)]
444pub fn default_json(version: i16) -> ::serde_json::Value {
445    let mut obj = ::serde_json::Map::new();
446    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
447    obj.insert(
448        "principalType".to_string(),
449        ::serde_json::Value::String(String::new()),
450    );
451    obj.insert(
452        "principalName".to_string(),
453        ::serde_json::Value::String(String::new()),
454    );
455    if version >= 3 {
456        obj.insert(
457            "tokenRequesterPrincipalType".to_string(),
458            ::serde_json::Value::String(String::new()),
459        );
460    }
461    if version >= 3 {
462        obj.insert(
463            "tokenRequesterPrincipalName".to_string(),
464            ::serde_json::Value::String(String::new()),
465        );
466    }
467    obj.insert("issueTimestampMs".to_string(), ::serde_json::json!(0));
468    obj.insert("expiryTimestampMs".to_string(), ::serde_json::json!(0));
469    obj.insert("maxTimestampMs".to_string(), ::serde_json::json!(0));
470    obj.insert(
471        "tokenId".to_string(),
472        ::serde_json::Value::String(String::new()),
473    );
474    obj.insert(
475        "hmac".to_string(),
476        ::serde_json::Value::String(String::new()),
477    );
478    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
479    ::serde_json::Value::Object(obj)
480}