Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenResponse.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_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
11use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 41;
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 { version >= FLEXIBLE_MIN }
21
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct DescribeDelegationTokenResponse {
24    pub error_code: i16,
25    pub tokens: Vec<DescribedDelegationToken>,
26    pub throttle_time_ms: i32,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for DescribeDelegationTokenResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i16(buf, self.error_code) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.tokens).len(), flex); for it in &self.tokens { it.encode(buf, version)?; } } }
38        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
39        if flex {
40            let tagged = WriteTaggedFields::new();
41            tagged.write(buf, &self.unknown_tagged_fields);
42        }
43        Ok(())
44    }
45    fn encoded_len(&self, version: i16) -> usize {
46        let flex = is_flexible(version);
47        let mut n: usize = 0;
48        if version >= 0 { n += 2; }
49        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.tokens).len(), flex); let body: usize = (self.tokens).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
50        if version >= 0 { n += 4; }
51        if flex {
52            let known_pairs: Vec<(u32, usize)> = Vec::new();
53            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
54        }
55        n
56    }
57}
58
59impl<'de> Decode<'de> for DescribeDelegationTokenResponse {
60    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
61        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
63        }
64        let flex = is_flexible(version);
65        let mut out = Self::default();
66        if version >= 0 { out.error_code = get_i16(buf)?; }
67        if version >= 0 { out.tokens = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribedDelegationToken::decode(buf, version)?); } v }; }
68        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
69        if flex {
70            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
71                Ok(false)
72            })?;
73        }
74        Ok(out)
75    }
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Default)]
79pub struct DescribedDelegationToken {
80    pub principal_type: String,
81    pub principal_name: String,
82    pub token_requester_principal_type: String,
83    pub token_requester_principal_name: String,
84    pub issue_timestamp: i64,
85    pub expiry_timestamp: i64,
86    pub max_timestamp: i64,
87    pub token_id: String,
88    pub hmac: ::bytes::Bytes,
89    pub renewers: Vec<DescribedDelegationTokenRenewer>,
90    pub unknown_tagged_fields: UnknownTaggedFields,
91}
92
93impl Encode for DescribedDelegationToken {
94    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
95        let flex = version >= 2;
96        if version >= 0 { if flex { put_compact_string(buf, &self.principal_type) } else { put_string(buf, &self.principal_type) } }
97        if version >= 0 { if flex { put_compact_string(buf, &self.principal_name) } else { put_string(buf, &self.principal_name) } }
98        if version >= 3 { if flex { put_compact_string(buf, &self.token_requester_principal_type) } else { put_string(buf, &self.token_requester_principal_type) } }
99        if version >= 3 { if flex { put_compact_string(buf, &self.token_requester_principal_name) } else { put_string(buf, &self.token_requester_principal_name) } }
100        if version >= 0 { put_i64(buf, self.issue_timestamp) }
101        if version >= 0 { put_i64(buf, self.expiry_timestamp) }
102        if version >= 0 { put_i64(buf, self.max_timestamp) }
103        if version >= 0 { if flex { put_compact_string(buf, &self.token_id) } else { put_string(buf, &self.token_id) } }
104        if version >= 0 { if flex { put_compact_bytes(buf, &self.hmac) } else { put_bytes(buf, &self.hmac) } }
105        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex); for it in &self.renewers { it.encode(buf, version)?; } } }
106        if flex {
107            let tagged = WriteTaggedFields::new();
108            tagged.write(buf, &self.unknown_tagged_fields);
109        }
110        Ok(())
111    }
112    fn encoded_len(&self, version: i16) -> usize {
113        let flex = version >= 2;
114        let mut n: usize = 0;
115        if version >= 0 { n += if flex { compact_string_len(&self.principal_type) } else { string_len(&self.principal_type) }; }
116        if version >= 0 { n += if flex { compact_string_len(&self.principal_name) } else { string_len(&self.principal_name) }; }
117        if version >= 3 { n += if flex { compact_string_len(&self.token_requester_principal_type) } else { string_len(&self.token_requester_principal_type) }; }
118        if version >= 3 { n += if flex { compact_string_len(&self.token_requester_principal_name) } else { string_len(&self.token_requester_principal_name) }; }
119        if version >= 0 { n += 8; }
120        if version >= 0 { n += 8; }
121        if version >= 0 { n += 8; }
122        if version >= 0 { n += if flex { compact_string_len(&self.token_id) } else { string_len(&self.token_id) }; }
123        if version >= 0 { n += if flex { compact_bytes_len(&self.hmac) } else { bytes_len(&self.hmac) }; }
124        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 }; }
125        if flex {
126            let known_pairs: Vec<(u32, usize)> = Vec::new();
127            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
128        }
129        n
130    }
131}
132
133impl<'de> Decode<'de> for DescribedDelegationToken {
134    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
135        let flex = version >= 2;
136        let mut out = Self::default();
137        if version >= 0 { out.principal_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
138        if version >= 0 { out.principal_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
139        if version >= 3 { out.token_requester_principal_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
140        if version >= 3 { out.token_requester_principal_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
141        if version >= 0 { out.issue_timestamp = get_i64(buf)?; }
142        if version >= 0 { out.expiry_timestamp = get_i64(buf)?; }
143        if version >= 0 { out.max_timestamp = get_i64(buf)?; }
144        if version >= 0 { out.token_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
145        if version >= 0 { out.hmac = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
146        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(DescribedDelegationTokenRenewer::decode(buf, version)?); } v }; }
147        if flex {
148            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
149                Ok(false)
150            })?;
151        }
152        Ok(out)
153    }
154}
155
156#[derive(Debug, Clone, PartialEq, Eq, Default)]
157pub struct DescribedDelegationTokenRenewer {
158    pub principal_type: String,
159    pub principal_name: String,
160    pub unknown_tagged_fields: UnknownTaggedFields,
161}
162
163impl Encode for DescribedDelegationTokenRenewer {
164    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
165        let flex = version >= 2;
166        if version >= 0 { if flex { put_compact_string(buf, &self.principal_type) } else { put_string(buf, &self.principal_type) } }
167        if version >= 0 { if flex { put_compact_string(buf, &self.principal_name) } else { put_string(buf, &self.principal_name) } }
168        if flex {
169            let tagged = WriteTaggedFields::new();
170            tagged.write(buf, &self.unknown_tagged_fields);
171        }
172        Ok(())
173    }
174    fn encoded_len(&self, version: i16) -> usize {
175        let flex = version >= 2;
176        let mut n: usize = 0;
177        if version >= 0 { n += if flex { compact_string_len(&self.principal_type) } else { string_len(&self.principal_type) }; }
178        if version >= 0 { n += if flex { compact_string_len(&self.principal_name) } else { string_len(&self.principal_name) }; }
179        if flex {
180            let known_pairs: Vec<(u32, usize)> = Vec::new();
181            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
182        }
183        n
184    }
185}
186
187impl<'de> Decode<'de> for DescribedDelegationTokenRenewer {
188    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
189        let flex = version >= 2;
190        let mut out = Self::default();
191        if version >= 0 { out.principal_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
192        if version >= 0 { out.principal_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
193        if flex {
194            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
195                Ok(false)
196            })?;
197        }
198        Ok(out)
199    }
200}
201
202/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
203/// Only includes fields valid for the given version.
204#[must_use]
205#[allow(unused_comparisons)]
206pub fn default_json(version: i16) -> ::serde_json::Value {
207    let mut obj = ::serde_json::Map::new();
208    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
209    obj.insert("tokens".to_string(), ::serde_json::Value::Array(vec![]));
210    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
211    ::serde_json::Value::Object(obj)
212}