crabka_protocol/opt/rustwide/workdir/generated/
CreateDelegationTokenRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i64, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 38;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 3;
21pub const FLEXIBLE_MIN: i16 = 2;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct CreateDelegationTokenRequest<'a> {
28 pub owner_principal_type: Option<&'a str>,
29 pub owner_principal_name: Option<&'a str>,
30 pub renewers: Vec<CreatableRenewers<'a>>,
31 pub max_lifetime_ms: i64,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl<'a> Default for CreateDelegationTokenRequest<'a> {
36 fn default() -> Self {
37 Self {
38 owner_principal_type: None,
39 owner_principal_name: None,
40 renewers: Vec::new(),
41 max_lifetime_ms: 0i64,
42 unknown_tagged_fields: Default::default(),
43 }
44 }
45}
46
47impl<'a> CreateDelegationTokenRequest<'a> {
48 pub fn to_owned(&self) -> crate::owned::create_delegation_token_request::CreateDelegationTokenRequest {
49 crate::owned::create_delegation_token_request::CreateDelegationTokenRequest {
50 owner_principal_type: (self.owner_principal_type).map(|s| s.to_string()),
51 owner_principal_name: (self.owner_principal_name).map(|s| s.to_string()),
52 renewers: (self.renewers).iter().map(|it| it.to_owned()).collect(),
53 max_lifetime_ms: (self.max_lifetime_ms),
54 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55 }
56 }
57}
58
59impl<'a> Encode for CreateDelegationTokenRequest<'a> {
60 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), 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 if version >= 3 { if flex { put_compact_nullable_string(buf, self.owner_principal_type) } else { put_nullable_string(buf, self.owner_principal_type) } }
66 if version >= 3 { if flex { put_compact_nullable_string(buf, self.owner_principal_name) } else { put_nullable_string(buf, self.owner_principal_name) } }
67 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex); for it in &self.renewers { it.encode(buf, version)?; } } }
68 if version >= 0 { put_i64(buf, self.max_lifetime_ms) }
69 if flex {
70 let tagged = WriteTaggedFields::new();
71 tagged.write(buf, &self.unknown_tagged_fields);
72 }
73 Ok(())
74 }
75 fn encoded_len(&self, version: i16) -> usize {
76 let flex = is_flexible(version);
77 let mut n: usize = 0;
78 if version >= 3 { n += if flex { compact_nullable_string_len(self.owner_principal_type) } else { nullable_string_len(self.owner_principal_type) }; }
79 if version >= 3 { n += if flex { compact_nullable_string_len(self.owner_principal_name) } else { nullable_string_len(self.owner_principal_name) }; }
80 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 }; }
81 if version >= 0 { n += 8; }
82 if flex {
83 let known_pairs: Vec<(u32, usize)> = Vec::new();
84 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85 }
86 n
87 }
88}
89
90impl<'de> DecodeBorrow<'de> for CreateDelegationTokenRequest<'de> {
91 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
92 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
93 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
94 }
95 let flex = is_flexible(version);
96 let mut out = Self::default();
97 if version >= 3 { out.owner_principal_type = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
98 if version >= 3 { out.owner_principal_name = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
99 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_borrow(buf, version)?); } v }; }
100 if version >= 0 { out.max_lifetime_ms = get_i64(buf)?; }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
103 Ok(false)
104 })?;
105 }
106 Ok(out)
107 }
108}
109
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct CreatableRenewers<'a> {
112 pub principal_type: &'a str,
113 pub principal_name: &'a str,
114 pub unknown_tagged_fields: UnknownTaggedFields,
115}
116
117impl<'a> Default for CreatableRenewers<'a> {
118 fn default() -> Self {
119 Self {
120 principal_type: "",
121 principal_name: "",
122 unknown_tagged_fields: Default::default(),
123 }
124 }
125}
126
127impl<'a> CreatableRenewers<'a> {
128 pub fn to_owned(&self) -> crate::owned::create_delegation_token_request::CreatableRenewers {
129 crate::owned::create_delegation_token_request::CreatableRenewers {
130 principal_type: (self.principal_type).to_string(),
131 principal_name: (self.principal_name).to_string(),
132 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
133 }
134 }
135}
136
137impl<'a> Encode for CreatableRenewers<'a> {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 2;
140 if version >= 0 { if flex { put_compact_string(buf, self.principal_type) } else { put_string(buf, self.principal_type) } }
141 if version >= 0 { if flex { put_compact_string(buf, self.principal_name) } else { put_string(buf, self.principal_name) } }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = version >= 2;
150 let mut n: usize = 0;
151 if version >= 0 { n += if flex { compact_string_len(self.principal_type) } else { string_len(self.principal_type) }; }
152 if version >= 0 { n += if flex { compact_string_len(self.principal_name) } else { string_len(self.principal_name) }; }
153 if flex {
154 let known_pairs: Vec<(u32, usize)> = Vec::new();
155 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
156 }
157 n
158 }
159}
160
161impl<'de> DecodeBorrow<'de> for CreatableRenewers<'de> {
162 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
163 let flex = version >= 2;
164 let mut out = Self::default();
165 if version >= 0 { out.principal_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
166 if version >= 0 { out.principal_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
167 if flex {
168 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
169 Ok(false)
170 })?;
171 }
172 Ok(out)
173 }
174}