crabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenRequest.borrowed.rs1use crate::primitives::string_bytes::{
3 compact_string_len, put_compact_string, put_string, string_len,
4};
5use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8use bytes::BufMut;
9pub const API_KEY: i16 = 41;
10pub const MIN_VERSION: i16 = 1;
11pub const MAX_VERSION: i16 = 3;
12pub const FLEXIBLE_MIN: i16 = 2;
13#[inline]
14fn is_flexible(version: i16) -> bool {
15 version >= FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct DescribeDelegationTokenRequest<'a> {
19 pub owners: Option<Vec<DescribeDelegationTokenOwner<'a>>>,
20 pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl DescribeDelegationTokenRequest<'_> {
23 pub fn to_owned(
24 &self,
25 ) -> crate::owned::describe_delegation_token_request::DescribeDelegationTokenRequest {
26 crate::owned::describe_delegation_token_request::DescribeDelegationTokenRequest {
27 owners: (self.owners).as_ref().map(|v| {
28 v.iter()
29 .map(DescribeDelegationTokenOwner::to_owned)
30 .collect()
31 }),
32 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
33 }
34 }
35}
36impl Encode for DescribeDelegationTokenRequest<'_> {
37 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39 return Err(ProtocolError::UnsupportedVersion {
40 api_key: API_KEY,
41 version,
42 });
43 }
44 let flex = is_flexible(version);
45 if version >= 0 {
46 {
47 let len = (self.owners).as_ref().map(Vec::len);
48 crate::primitives::array::put_nullable_array_len(buf, len, flex);
49 if let Some(v) = &self.owners {
50 for it in v {
51 it.encode(buf, version)?;
52 }
53 }
54 }
55 }
56 if flex {
57 let tagged = WriteTaggedFields::new();
58 tagged.write(buf, &self.unknown_tagged_fields);
59 }
60 Ok(())
61 }
62 fn encoded_len(&self, version: i16) -> usize {
63 let flex = is_flexible(version);
64 let mut n: usize = 0;
65 if version >= 0 {
66 n += {
67 let opt: Option<&Vec<_>> = (self.owners).as_ref();
68 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
69 opt.map(std::vec::Vec::len),
70 flex,
71 );
72 let body: usize =
73 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
74 prefix + body
75 };
76 }
77 if flex {
78 let known_pairs: Vec<(u32, usize)> = Vec::new();
79 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80 }
81 n
82 }
83}
84impl<'de> DecodeBorrow<'de> for DescribeDelegationTokenRequest<'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 {
88 api_key: API_KEY,
89 version,
90 });
91 }
92 let flex = is_flexible(version);
93 let mut out = Self::default();
94 if version >= 0 {
95 out.owners = {
96 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
97 match opt {
98 None => None,
99 Some(n) => {
100 let mut v = Vec::with_capacity(n);
101 for _ in 0..n {
102 v.push(DescribeDelegationTokenOwner::decode_borrow(buf, version)?);
103 }
104 Some(v)
105 }
106 }
107 };
108 }
109 if flex {
110 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
111 }
112 Ok(out)
113 }
114}
115#[cfg(test)]
116impl DescribeDelegationTokenRequest<'_> {
117 #[must_use]
118 pub fn populated(version: i16) -> Self {
119 let mut m = Self::default();
120 if version >= 0 {
121 m.owners = Some(vec![DescribeDelegationTokenOwner::populated(version)]);
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq, Default)]
127pub struct DescribeDelegationTokenOwner<'a> {
128 pub principal_type: &'a str,
129 pub principal_name: &'a str,
130 pub unknown_tagged_fields: UnknownTaggedFields,
131}
132impl DescribeDelegationTokenOwner<'_> {
133 pub fn to_owned(
134 &self,
135 ) -> crate::owned::describe_delegation_token_request::DescribeDelegationTokenOwner {
136 crate::owned::describe_delegation_token_request::DescribeDelegationTokenOwner {
137 principal_type: (self.principal_type).to_string(),
138 principal_name: (self.principal_name).to_string(),
139 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
140 }
141 }
142}
143impl Encode for DescribeDelegationTokenOwner<'_> {
144 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
145 let flex = version >= 2;
146 if version >= 0 {
147 if flex {
148 put_compact_string(buf, self.principal_type);
149 } else {
150 put_string(buf, self.principal_type);
151 }
152 }
153 if version >= 0 {
154 if flex {
155 put_compact_string(buf, self.principal_name);
156 } else {
157 put_string(buf, self.principal_name);
158 }
159 }
160 if flex {
161 let tagged = WriteTaggedFields::new();
162 tagged.write(buf, &self.unknown_tagged_fields);
163 }
164 Ok(())
165 }
166 fn encoded_len(&self, version: i16) -> usize {
167 let flex = version >= 2;
168 let mut n: usize = 0;
169 if version >= 0 {
170 n += if flex {
171 compact_string_len(self.principal_type)
172 } else {
173 string_len(self.principal_type)
174 };
175 }
176 if version >= 0 {
177 n += if flex {
178 compact_string_len(self.principal_name)
179 } else {
180 string_len(self.principal_name)
181 };
182 }
183 if flex {
184 let known_pairs: Vec<(u32, usize)> = Vec::new();
185 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
186 }
187 n
188 }
189}
190impl<'de> DecodeBorrow<'de> for DescribeDelegationTokenOwner<'de> {
191 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
192 let flex = version >= 2;
193 let mut out = Self::default();
194 if version >= 0 {
195 out.principal_type = if flex {
196 get_compact_string_borrowed(buf)?
197 } else {
198 get_string_borrowed(buf)?
199 };
200 }
201 if version >= 0 {
202 out.principal_name = if flex {
203 get_compact_string_borrowed(buf)?
204 } else {
205 get_string_borrowed(buf)?
206 };
207 }
208 if flex {
209 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
210 }
211 Ok(out)
212 }
213}
214#[cfg(test)]
215impl DescribeDelegationTokenOwner<'_> {
216 #[must_use]
217 pub fn populated(version: i16) -> Self {
218 let mut m = Self::default();
219 if version >= 0 {
220 m.principal_type = "x";
221 }
222 if version >= 0 {
223 m.principal_name = "x";
224 }
225 m
226 }
227}