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