Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreateDelegationTokenResponse.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 = 38;
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 CreateDelegationTokenResponse<'a> {
27    pub error_code: i16,
28    pub principal_type: &'a str,
29    pub principal_name: &'a str,
30    pub token_requester_principal_type: &'a str,
31    pub token_requester_principal_name: &'a str,
32    pub issue_timestamp_ms: i64,
33    pub expiry_timestamp_ms: i64,
34    pub max_timestamp_ms: i64,
35    pub token_id: &'a str,
36    pub hmac: &'a [u8],
37    pub throttle_time_ms: i32,
38    pub unknown_tagged_fields: UnknownTaggedFields,
39}
40
41impl<'a> Default for CreateDelegationTokenResponse<'a> {
42    fn default() -> Self {
43        Self {
44            error_code: 0i16,
45            principal_type: "",
46            principal_name: "",
47            token_requester_principal_type: "",
48            token_requester_principal_name: "",
49            issue_timestamp_ms: 0i64,
50            expiry_timestamp_ms: 0i64,
51            max_timestamp_ms: 0i64,
52            token_id: "",
53            hmac: &[],
54            throttle_time_ms: 0i32,
55            unknown_tagged_fields: Default::default(),
56        }
57    }
58}
59
60impl<'a> CreateDelegationTokenResponse<'a> {
61    pub fn to_owned(&self) -> crate::owned::create_delegation_token_response::CreateDelegationTokenResponse {
62        crate::owned::create_delegation_token_response::CreateDelegationTokenResponse {
63            error_code: (self.error_code),
64            principal_type: (self.principal_type).to_string(),
65            principal_name: (self.principal_name).to_string(),
66            token_requester_principal_type: (self.token_requester_principal_type).to_string(),
67            token_requester_principal_name: (self.token_requester_principal_name).to_string(),
68            issue_timestamp_ms: (self.issue_timestamp_ms),
69            expiry_timestamp_ms: (self.expiry_timestamp_ms),
70            max_timestamp_ms: (self.max_timestamp_ms),
71            token_id: (self.token_id).to_string(),
72            hmac: Bytes::copy_from_slice(self.hmac),
73            throttle_time_ms: (self.throttle_time_ms),
74            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
75        }
76    }
77}
78
79impl<'a> Encode for CreateDelegationTokenResponse<'a> {
80    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
81        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
83        }
84        let flex = is_flexible(version);
85        if version >= 0 { put_i16(buf, self.error_code) }
86        if version >= 0 { if flex { put_compact_string(buf, self.principal_type) } else { put_string(buf, self.principal_type) } }
87        if version >= 0 { if flex { put_compact_string(buf, self.principal_name) } else { put_string(buf, self.principal_name) } }
88        if version >= 3 { if flex { put_compact_string(buf, self.token_requester_principal_type) } else { put_string(buf, self.token_requester_principal_type) } }
89        if version >= 3 { if flex { put_compact_string(buf, self.token_requester_principal_name) } else { put_string(buf, self.token_requester_principal_name) } }
90        if version >= 0 { put_i64(buf, self.issue_timestamp_ms) }
91        if version >= 0 { put_i64(buf, self.expiry_timestamp_ms) }
92        if version >= 0 { put_i64(buf, self.max_timestamp_ms) }
93        if version >= 0 { if flex { put_compact_string(buf, self.token_id) } else { put_string(buf, self.token_id) } }
94        if version >= 0 { if flex { put_compact_bytes(buf, self.hmac) } else { put_bytes(buf, self.hmac) } }
95        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
96        if flex {
97            let tagged = WriteTaggedFields::new();
98            tagged.write(buf, &self.unknown_tagged_fields);
99        }
100        Ok(())
101    }
102    fn encoded_len(&self, version: i16) -> usize {
103        let flex = is_flexible(version);
104        let mut n: usize = 0;
105        if version >= 0 { n += 2; }
106        if version >= 0 { n += if flex { compact_string_len(self.principal_type) } else { string_len(self.principal_type) }; }
107        if version >= 0 { n += if flex { compact_string_len(self.principal_name) } else { string_len(self.principal_name) }; }
108        if version >= 3 { n += if flex { compact_string_len(self.token_requester_principal_type) } else { string_len(self.token_requester_principal_type) }; }
109        if version >= 3 { n += if flex { compact_string_len(self.token_requester_principal_name) } else { string_len(self.token_requester_principal_name) }; }
110        if version >= 0 { n += 8; }
111        if version >= 0 { n += 8; }
112        if version >= 0 { n += 8; }
113        if version >= 0 { n += if flex { compact_string_len(self.token_id) } else { string_len(self.token_id) }; }
114        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() }; }
115        if version >= 0 { n += 4; }
116        if flex {
117            let known_pairs: Vec<(u32, usize)> = Vec::new();
118            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
119        }
120        n
121    }
122}
123
124impl<'de> DecodeBorrow<'de> for CreateDelegationTokenResponse<'de> {
125    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
126        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
127            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
128        }
129        let flex = is_flexible(version);
130        let mut out = Self::default();
131        if version >= 0 { out.error_code = get_i16(buf)?; }
132        if version >= 0 { out.principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
133        if version >= 0 { out.principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
134        if version >= 3 { out.token_requester_principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
135        if version >= 3 { out.token_requester_principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
136        if version >= 0 { out.issue_timestamp_ms = get_i64(buf)?; }
137        if version >= 0 { out.expiry_timestamp_ms = get_i64(buf)?; }
138        if version >= 0 { out.max_timestamp_ms = get_i64(buf)?; }
139        if version >= 0 { out.token_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
140        if version >= 0 { out.hmac = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
141        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
142        if flex {
143            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
144                Ok(false)
145            })?;
146        }
147        Ok(out)
148    }
149}