Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Bytes, 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, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::primitives::string_bytes::{put_bytes, put_compact_bytes};
13use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
14use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
15use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
16
17pub const API_KEY: i16 = 41;
18pub const MIN_VERSION: i16 = 1;
19pub const MAX_VERSION: i16 = 3;
20pub const FLEXIBLE_MIN: i16 = 2;
21
22#[inline]
23fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
24
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct DescribeDelegationTokenResponse<'a> {
27    pub error_code: i16,
28    pub tokens: Vec<DescribedDelegationToken<'a>>,
29    pub throttle_time_ms: i32,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for DescribeDelegationTokenResponse<'a> {
34    fn default() -> Self {
35        Self {
36            error_code: 0i16,
37            tokens: Vec::new(),
38            throttle_time_ms: 0i32,
39            unknown_tagged_fields: Default::default(),
40        }
41    }
42}
43
44impl<'a> DescribeDelegationTokenResponse<'a> {
45    pub fn to_owned(&self) -> crate::owned::describe_delegation_token_response::DescribeDelegationTokenResponse {
46        crate::owned::describe_delegation_token_response::DescribeDelegationTokenResponse {
47            error_code: (self.error_code),
48            tokens: (self.tokens).iter().map(|it| it.to_owned()).collect(),
49            throttle_time_ms: (self.throttle_time_ms),
50            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
51        }
52    }
53}
54
55impl<'a> Encode for DescribeDelegationTokenResponse<'a> {
56    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59        }
60        let flex = is_flexible(version);
61        if version >= 0 { put_i16(buf, self.error_code) }
62        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.tokens).len(), flex); for it in &self.tokens { it.encode(buf, version)?; } } }
63        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
64        if flex {
65            let tagged = WriteTaggedFields::new();
66            tagged.write(buf, &self.unknown_tagged_fields);
67        }
68        Ok(())
69    }
70    fn encoded_len(&self, version: i16) -> usize {
71        let flex = is_flexible(version);
72        let mut n: usize = 0;
73        if version >= 0 { n += 2; }
74        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 }; }
75        if version >= 0 { n += 4; }
76        if flex {
77            let known_pairs: Vec<(u32, usize)> = Vec::new();
78            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79        }
80        n
81    }
82}
83
84impl<'de> DecodeBorrow<'de> for DescribeDelegationTokenResponse<'de> {
85    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
88        }
89        let flex = is_flexible(version);
90        let mut out = Self::default();
91        if version >= 0 { out.error_code = get_i16(buf)?; }
92        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_borrow(buf, version)?); } v }; }
93        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
94        if flex {
95            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
96                Ok(false)
97            })?;
98        }
99        Ok(out)
100    }
101}
102
103#[derive(Debug, Clone, PartialEq, Eq)]
104pub struct DescribedDelegationToken<'a> {
105    pub principal_type: &'a str,
106    pub principal_name: &'a str,
107    pub token_requester_principal_type: &'a str,
108    pub token_requester_principal_name: &'a str,
109    pub issue_timestamp: i64,
110    pub expiry_timestamp: i64,
111    pub max_timestamp: i64,
112    pub token_id: &'a str,
113    pub hmac: &'a [u8],
114    pub renewers: Vec<DescribedDelegationTokenRenewer<'a>>,
115    pub unknown_tagged_fields: UnknownTaggedFields,
116}
117
118impl<'a> Default for DescribedDelegationToken<'a> {
119    fn default() -> Self {
120        Self {
121            principal_type: "",
122            principal_name: "",
123            token_requester_principal_type: "",
124            token_requester_principal_name: "",
125            issue_timestamp: 0i64,
126            expiry_timestamp: 0i64,
127            max_timestamp: 0i64,
128            token_id: "",
129            hmac: &[],
130            renewers: Vec::new(),
131            unknown_tagged_fields: Default::default(),
132        }
133    }
134}
135
136impl<'a> DescribedDelegationToken<'a> {
137    pub fn to_owned(&self) -> crate::owned::describe_delegation_token_response::DescribedDelegationToken {
138        crate::owned::describe_delegation_token_response::DescribedDelegationToken {
139            principal_type: (self.principal_type).to_string(),
140            principal_name: (self.principal_name).to_string(),
141            token_requester_principal_type: (self.token_requester_principal_type).to_string(),
142            token_requester_principal_name: (self.token_requester_principal_name).to_string(),
143            issue_timestamp: (self.issue_timestamp),
144            expiry_timestamp: (self.expiry_timestamp),
145            max_timestamp: (self.max_timestamp),
146            token_id: (self.token_id).to_string(),
147            hmac: Bytes::copy_from_slice(self.hmac),
148            renewers: (self.renewers).iter().map(|it| it.to_owned()).collect(),
149            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
150        }
151    }
152}
153
154impl<'a> Encode for DescribedDelegationToken<'a> {
155    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
156        let flex = version >= 2;
157        if version >= 0 { if flex { put_compact_string(buf, self.principal_type) } else { put_string(buf, self.principal_type) } }
158        if version >= 0 { if flex { put_compact_string(buf, self.principal_name) } else { put_string(buf, self.principal_name) } }
159        if version >= 3 { if flex { put_compact_string(buf, self.token_requester_principal_type) } else { put_string(buf, self.token_requester_principal_type) } }
160        if version >= 3 { if flex { put_compact_string(buf, self.token_requester_principal_name) } else { put_string(buf, self.token_requester_principal_name) } }
161        if version >= 0 { put_i64(buf, self.issue_timestamp) }
162        if version >= 0 { put_i64(buf, self.expiry_timestamp) }
163        if version >= 0 { put_i64(buf, self.max_timestamp) }
164        if version >= 0 { if flex { put_compact_string(buf, self.token_id) } else { put_string(buf, self.token_id) } }
165        if version >= 0 { if flex { put_compact_bytes(buf, self.hmac) } else { put_bytes(buf, self.hmac) } }
166        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex); for it in &self.renewers { it.encode(buf, version)?; } } }
167        if flex {
168            let tagged = WriteTaggedFields::new();
169            tagged.write(buf, &self.unknown_tagged_fields);
170        }
171        Ok(())
172    }
173    fn encoded_len(&self, version: i16) -> usize {
174        let flex = version >= 2;
175        let mut n: usize = 0;
176        if version >= 0 { n += if flex { compact_string_len(self.principal_type) } else { string_len(self.principal_type) }; }
177        if version >= 0 { n += if flex { compact_string_len(self.principal_name) } else { string_len(self.principal_name) }; }
178        if version >= 3 { n += if flex { compact_string_len(self.token_requester_principal_type) } else { string_len(self.token_requester_principal_type) }; }
179        if version >= 3 { n += if flex { compact_string_len(self.token_requester_principal_name) } else { string_len(self.token_requester_principal_name) }; }
180        if version >= 0 { n += 8; }
181        if version >= 0 { n += 8; }
182        if version >= 0 { n += 8; }
183        if version >= 0 { n += if flex { compact_string_len(self.token_id) } else { string_len(self.token_id) }; }
184        if version >= 0 { n += if flex { crate::primitives::varint::uvarint_len(u32::try_from((self.hmac).len() + 1).unwrap()) + (self.hmac).len() } else { 4 + (self.hmac).len() }; }
185        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 }; }
186        if flex {
187            let known_pairs: Vec<(u32, usize)> = Vec::new();
188            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
189        }
190        n
191    }
192}
193
194impl<'de> DecodeBorrow<'de> for DescribedDelegationToken<'de> {
195    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
196        let flex = version >= 2;
197        let mut out = Self::default();
198        if version >= 0 { out.principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
199        if version >= 0 { out.principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
200        if version >= 3 { out.token_requester_principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
201        if version >= 3 { out.token_requester_principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
202        if version >= 0 { out.issue_timestamp = get_i64(buf)?; }
203        if version >= 0 { out.expiry_timestamp = get_i64(buf)?; }
204        if version >= 0 { out.max_timestamp = get_i64(buf)?; }
205        if version >= 0 { out.token_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
206        if version >= 0 { out.hmac = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
207        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_borrow(buf, version)?); } v }; }
208        if flex {
209            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
210                Ok(false)
211            })?;
212        }
213        Ok(out)
214    }
215}
216
217#[derive(Debug, Clone, PartialEq, Eq)]
218pub struct DescribedDelegationTokenRenewer<'a> {
219    pub principal_type: &'a str,
220    pub principal_name: &'a str,
221    pub unknown_tagged_fields: UnknownTaggedFields,
222}
223
224impl<'a> Default for DescribedDelegationTokenRenewer<'a> {
225    fn default() -> Self {
226        Self {
227            principal_type: "",
228            principal_name: "",
229            unknown_tagged_fields: Default::default(),
230        }
231    }
232}
233
234impl<'a> DescribedDelegationTokenRenewer<'a> {
235    pub fn to_owned(&self) -> crate::owned::describe_delegation_token_response::DescribedDelegationTokenRenewer {
236        crate::owned::describe_delegation_token_response::DescribedDelegationTokenRenewer {
237            principal_type: (self.principal_type).to_string(),
238            principal_name: (self.principal_name).to_string(),
239            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
240        }
241    }
242}
243
244impl<'a> Encode for DescribedDelegationTokenRenewer<'a> {
245    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
246        let flex = version >= 2;
247        if version >= 0 { if flex { put_compact_string(buf, self.principal_type) } else { put_string(buf, self.principal_type) } }
248        if version >= 0 { if flex { put_compact_string(buf, self.principal_name) } else { put_string(buf, self.principal_name) } }
249        if flex {
250            let tagged = WriteTaggedFields::new();
251            tagged.write(buf, &self.unknown_tagged_fields);
252        }
253        Ok(())
254    }
255    fn encoded_len(&self, version: i16) -> usize {
256        let flex = version >= 2;
257        let mut n: usize = 0;
258        if version >= 0 { n += if flex { compact_string_len(self.principal_type) } else { string_len(self.principal_type) }; }
259        if version >= 0 { n += if flex { compact_string_len(self.principal_name) } else { string_len(self.principal_name) }; }
260        if flex {
261            let known_pairs: Vec<(u32, usize)> = Vec::new();
262            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
263        }
264        n
265    }
266}
267
268impl<'de> DecodeBorrow<'de> for DescribedDelegationTokenRenewer<'de> {
269    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
270        let flex = version >= 2;
271        let mut out = Self::default();
272        if version >= 0 { out.principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
273        if version >= 0 { out.principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
274        if flex {
275            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
276                Ok(false)
277            })?;
278        }
279        Ok(out)
280    }
281}