krabka_protocol/opt/rustwide/workdir/generated/
DescribeDelegationTokenRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{get_nullable_array_len, nullable_array_len_prefix_len, put_nullable_array_len},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 41;
17pub const MIN_VERSION: i16 = 1;
18pub const MAX_VERSION: i16 = 3;
19pub const LATEST_STABLE_VERSION: i16 = 3;
20pub const FLEXIBLE_MIN: i16 = 2;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DescribeDelegationTokenRequest {
28 pub owners: Option<Vec<DescribeDelegationTokenOwner>>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Default for DescribeDelegationTokenRequest {
32 fn default() -> Self {
33 Self {
34 owners: Some(Vec::new()),
35 unknown_tagged_fields: UnknownTaggedFields::default(),
36 }
37 }
38}
39impl Encode for DescribeDelegationTokenRequest {
40 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
41 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
42 return Err(ProtocolError::UnsupportedVersion {
43 api_key: API_KEY,
44 version,
45 });
46 }
47 let flex = is_flexible(version);
48 if version >= 0 {
49 {
50 let len = (self.owners).as_ref().map(Vec::len);
51 put_nullable_array_len(buf, len, flex)?;
52 if let Some(v) = &self.owners {
53 for it in v {
54 it.encode(buf, version)?;
55 }
56 }
57 }
58 }
59 if flex {
60 let tagged = WriteTaggedFields::new();
61 tagged.write(buf, &self.unknown_tagged_fields)?;
62 }
63 Ok(())
64 }
65 fn encoded_len(&self, version: i16) -> usize {
66 let flex = is_flexible(version);
67 let mut n: usize = 0;
68 if version >= 0 {
69 n += {
70 let opt: Option<&Vec<_>> = (self.owners).as_ref();
71 let prefix = nullable_array_len_prefix_len(opt.map(Vec::len), flex);
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 Decode<'_> for DescribeDelegationTokenRequest {
85 fn decode<B: Buf>(buf: &mut B, 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 = 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(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 {
128 pub principal_type: String,
129 pub principal_name: String,
130 pub unknown_tagged_fields: UnknownTaggedFields,
131}
132impl Encode for DescribeDelegationTokenOwner {
133 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134 let flex = version >= 2;
135 if version >= 0 {
136 if flex {
137 put_compact_string(buf, &self.principal_type)?;
138 } else {
139 put_string(buf, &self.principal_type)?;
140 }
141 }
142 if version >= 0 {
143 if flex {
144 put_compact_string(buf, &self.principal_name)?;
145 } else {
146 put_string(buf, &self.principal_name)?;
147 }
148 }
149 if flex {
150 let tagged = WriteTaggedFields::new();
151 tagged.write(buf, &self.unknown_tagged_fields)?;
152 }
153 Ok(())
154 }
155 fn encoded_len(&self, version: i16) -> usize {
156 let flex = version >= 2;
157 let mut n: usize = 0;
158 if version >= 0 {
159 n += if flex {
160 compact_string_len(&self.principal_type)
161 } else {
162 string_len(&self.principal_type)
163 };
164 }
165 if version >= 0 {
166 n += if flex {
167 compact_string_len(&self.principal_name)
168 } else {
169 string_len(&self.principal_name)
170 };
171 }
172 if flex {
173 let known_pairs: Vec<(u32, usize)> = Vec::new();
174 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175 }
176 n
177 }
178}
179impl Decode<'_> for DescribeDelegationTokenOwner {
180 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181 let flex = version >= 2;
182 let mut out = Self::default();
183 if version >= 0 {
184 out.principal_type = if flex {
185 get_compact_string_owned(buf)?
186 } else {
187 get_string_owned(buf)?
188 };
189 }
190 if version >= 0 {
191 out.principal_name = if flex {
192 get_compact_string_owned(buf)?
193 } else {
194 get_string_owned(buf)?
195 };
196 }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199 }
200 Ok(out)
201 }
202}
203#[cfg(test)]
204impl DescribeDelegationTokenOwner {
205 #[must_use]
206 pub fn populated(version: i16) -> Self {
207 let mut m = Self::default();
208 if version >= 0 {
209 m.principal_type = "x".to_owned();
210 }
211 if version >= 0 {
212 m.principal_name = "x".to_owned();
213 }
214 m
215 }
216}
217#[must_use]
220#[allow(unused_comparisons)]
221pub fn default_json(_version: i16) -> ::serde_json::Value {
222 let mut obj = ::serde_json::Map::new();
223 obj.insert("owners".to_owned(), ::serde_json::Value::Array(vec![]));
224 ::serde_json::Value::Object(obj)
225}
226impl crate::ProtocolRequest for DescribeDelegationTokenRequest {
227 const API_KEY: i16 = API_KEY;
228 const MIN_VERSION: i16 = MIN_VERSION;
229 const MAX_VERSION: i16 = MAX_VERSION;
230 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
231 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
232 type Response = super::describe_delegation_token_response::DescribeDelegationTokenResponse;
233}