Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreateDelegationTokenRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 38;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 3;
18pub const FLEXIBLE_MIN: i16 = 2;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct CreateDelegationTokenRequest {
25    pub owner_principal_type: Option<String>,
26    pub owner_principal_name: Option<String>,
27    pub renewers: Vec<CreatableRenewers>,
28    pub max_lifetime_ms: i64,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
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 { api_key: API_KEY, version });
36        }
37        let flex = is_flexible(version);
38        if version >= 3 { if flex { put_compact_nullable_string(buf, self.owner_principal_type.as_deref()) } else { put_nullable_string(buf, self.owner_principal_type.as_deref()) } }
39        if version >= 3 { if flex { put_compact_nullable_string(buf, self.owner_principal_name.as_deref()) } else { put_nullable_string(buf, self.owner_principal_name.as_deref()) } }
40        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex); for it in &self.renewers { it.encode(buf, version)?; } } }
41        if version >= 0 { put_i64(buf, self.max_lifetime_ms) }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 3 { n += if flex { compact_nullable_string_len(self.owner_principal_type.as_deref()) } else { nullable_string_len(self.owner_principal_type.as_deref()) }; }
52        if version >= 3 { n += if flex { compact_nullable_string_len(self.owner_principal_name.as_deref()) } else { nullable_string_len(self.owner_principal_name.as_deref()) }; }
53        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex); let body: usize = (self.renewers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
54        if version >= 0 { n += 8; }
55        if flex {
56            let known_pairs: Vec<(u32, usize)> = Vec::new();
57            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58        }
59        n
60    }
61}
62
63impl<'de> Decode<'de> for CreateDelegationTokenRequest {
64    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
65        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
67        }
68        let flex = is_flexible(version);
69        let mut out = Self::default();
70        if version >= 3 { out.owner_principal_type = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
71        if version >= 3 { out.owner_principal_name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
72        if version >= 0 { out.renewers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableRenewers::decode(buf, version)?); } v }; }
73        if version >= 0 { out.max_lifetime_ms = get_i64(buf)?; }
74        if flex {
75            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
76                Ok(false)
77            })?;
78        }
79        Ok(out)
80    }
81}
82
83#[derive(Debug, Clone, PartialEq, Eq, Default)]
84pub struct CreatableRenewers {
85    pub principal_type: String,
86    pub principal_name: String,
87    pub unknown_tagged_fields: UnknownTaggedFields,
88}
89
90impl Encode for CreatableRenewers {
91    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
92        let flex = version >= 2;
93        if version >= 0 { if flex { put_compact_string(buf, &self.principal_type) } else { put_string(buf, &self.principal_type) } }
94        if version >= 0 { if flex { put_compact_string(buf, &self.principal_name) } else { put_string(buf, &self.principal_name) } }
95        if flex {
96            let tagged = WriteTaggedFields::new();
97            tagged.write(buf, &self.unknown_tagged_fields);
98        }
99        Ok(())
100    }
101    fn encoded_len(&self, version: i16) -> usize {
102        let flex = version >= 2;
103        let mut n: usize = 0;
104        if version >= 0 { n += if flex { compact_string_len(&self.principal_type) } else { string_len(&self.principal_type) }; }
105        if version >= 0 { n += if flex { compact_string_len(&self.principal_name) } else { string_len(&self.principal_name) }; }
106        if flex {
107            let known_pairs: Vec<(u32, usize)> = Vec::new();
108            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
109        }
110        n
111    }
112}
113
114impl<'de> Decode<'de> for CreatableRenewers {
115    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
116        let flex = version >= 2;
117        let mut out = Self::default();
118        if version >= 0 { out.principal_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
119        if version >= 0 { out.principal_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
122                Ok(false)
123            })?;
124        }
125        Ok(out)
126    }
127}
128
129/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
130/// Only includes fields valid for the given version.
131#[must_use]
132#[allow(unused_comparisons)]
133pub fn default_json(version: i16) -> ::serde_json::Value {
134    let mut obj = ::serde_json::Map::new();
135    if version >= 3 {
136        obj.insert("ownerPrincipalType".to_string(), ::serde_json::Value::Null);
137    }
138    if version >= 3 {
139        obj.insert("ownerPrincipalName".to_string(), ::serde_json::Value::Null);
140    }
141    obj.insert("renewers".to_string(), ::serde_json::Value::Array(vec![]));
142    obj.insert("maxLifetimeMs".to_string(), ::serde_json::json!(0));
143    ::serde_json::Value::Object(obj)
144}
145
146impl crate::ProtocolRequest for CreateDelegationTokenRequest {
147    const API_KEY: i16 = API_KEY;
148    const MIN_VERSION: i16 = MIN_VERSION;
149    const MAX_VERSION: i16 = MAX_VERSION;
150    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
151    type Response = super::create_delegation_token_response::CreateDelegationTokenResponse;
152}