krabka_protocol/opt/rustwide/workdir/generated/
CreateAclsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, put_i8},
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 = 30;
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, Default)]
27pub struct CreateAclsRequest {
28 pub creations: Vec<AclCreation>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for CreateAclsRequest {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion {
35 api_key: API_KEY,
36 version,
37 });
38 }
39 let flex = is_flexible(version);
40 if version >= 0 {
41 {
42 crate::primitives::array::put_array_len(buf, (self.creations).len(), flex);
43 for it in &self.creations {
44 it.encode(buf, version)?;
45 }
46 };
47 }
48 if flex {
49 let tagged = WriteTaggedFields::new();
50 tagged.write(buf, &self.unknown_tagged_fields);
51 }
52 Ok(())
53 }
54 fn encoded_len(&self, version: i16) -> usize {
55 let flex = is_flexible(version);
56 let mut n: usize = 0;
57 if version >= 0 {
58 n += {
59 let prefix =
60 crate::primitives::array::array_len_prefix_len((self.creations).len(), flex);
61 let body: usize = (self.creations)
62 .iter()
63 .map(|it| it.encoded_len(version))
64 .sum();
65 prefix + body
66 };
67 }
68 if flex {
69 let known_pairs: Vec<(u32, usize)> = Vec::new();
70 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
71 }
72 n
73 }
74}
75impl Decode<'_> for CreateAclsRequest {
76 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
77 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
78 return Err(ProtocolError::UnsupportedVersion {
79 api_key: API_KEY,
80 version,
81 });
82 }
83 let flex = is_flexible(version);
84 let mut out = Self::default();
85 if version >= 0 {
86 out.creations = {
87 let n = crate::primitives::array::get_array_len(buf, flex)?;
88 let mut v = Vec::with_capacity(n);
89 for _ in 0..n {
90 v.push(AclCreation::decode(buf, version)?);
91 }
92 v
93 };
94 }
95 if flex {
96 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
97 }
98 Ok(out)
99 }
100}
101#[cfg(test)]
102impl CreateAclsRequest {
103 #[must_use]
104 pub fn populated(version: i16) -> Self {
105 let mut m = Self::default();
106 if version >= 0 {
107 m.creations = vec![AclCreation::populated(version)];
108 }
109 m
110 }
111}
112#[derive(Debug, Clone, PartialEq, Eq)]
113pub struct AclCreation {
114 pub resource_type: i8,
115 pub resource_name: String,
116 pub resource_pattern_type: i8,
117 pub principal: String,
118 pub host: String,
119 pub operation: i8,
120 pub permission_type: i8,
121 pub unknown_tagged_fields: UnknownTaggedFields,
122}
123impl Default for AclCreation {
124 fn default() -> Self {
125 Self {
126 resource_type: 0i8,
127 resource_name: String::new(),
128 resource_pattern_type: 3i8,
129 principal: String::new(),
130 host: String::new(),
131 operation: 0i8,
132 permission_type: 0i8,
133 unknown_tagged_fields: UnknownTaggedFields::default(),
134 }
135 }
136}
137impl Encode for AclCreation {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 2;
140 if version >= 0 {
141 put_i8(buf, self.resource_type);
142 }
143 if version >= 0 {
144 if flex {
145 let () = put_compact_string(buf, &self.resource_name);
146 } else {
147 let () = put_string(buf, &self.resource_name);
148 }
149 }
150 if version >= 1 {
151 put_i8(buf, self.resource_pattern_type);
152 }
153 if version >= 0 {
154 if flex {
155 let () = put_compact_string(buf, &self.principal);
156 } else {
157 let () = put_string(buf, &self.principal);
158 }
159 }
160 if version >= 0 {
161 if flex {
162 let () = put_compact_string(buf, &self.host);
163 } else {
164 let () = put_string(buf, &self.host);
165 }
166 }
167 if version >= 0 {
168 put_i8(buf, self.operation);
169 }
170 if version >= 0 {
171 put_i8(buf, self.permission_type);
172 }
173 if flex {
174 let tagged = WriteTaggedFields::new();
175 tagged.write(buf, &self.unknown_tagged_fields);
176 }
177 Ok(())
178 }
179 fn encoded_len(&self, version: i16) -> usize {
180 let flex = version >= 2;
181 let mut n: usize = 0;
182 if version >= 0 {
183 n += 1;
184 }
185 if version >= 0 {
186 n += if flex {
187 compact_string_len(&self.resource_name)
188 } else {
189 string_len(&self.resource_name)
190 };
191 }
192 if version >= 1 {
193 n += 1;
194 }
195 if version >= 0 {
196 n += if flex {
197 compact_string_len(&self.principal)
198 } else {
199 string_len(&self.principal)
200 };
201 }
202 if version >= 0 {
203 n += if flex {
204 compact_string_len(&self.host)
205 } else {
206 string_len(&self.host)
207 };
208 }
209 if version >= 0 {
210 n += 1;
211 }
212 if version >= 0 {
213 n += 1;
214 }
215 if flex {
216 let known_pairs: Vec<(u32, usize)> = Vec::new();
217 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
218 }
219 n
220 }
221}
222impl Decode<'_> for AclCreation {
223 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
224 let flex = version >= 2;
225 let mut out = Self::default();
226 if version >= 0 {
227 out.resource_type = get_i8(buf)?;
228 }
229 if version >= 0 {
230 out.resource_name = if flex {
231 get_compact_string_owned(buf)?
232 } else {
233 get_string_owned(buf)?
234 };
235 }
236 if version >= 1 {
237 out.resource_pattern_type = get_i8(buf)?;
238 }
239 if version >= 0 {
240 out.principal = if flex {
241 get_compact_string_owned(buf)?
242 } else {
243 get_string_owned(buf)?
244 };
245 }
246 if version >= 0 {
247 out.host = if flex {
248 get_compact_string_owned(buf)?
249 } else {
250 get_string_owned(buf)?
251 };
252 }
253 if version >= 0 {
254 out.operation = get_i8(buf)?;
255 }
256 if version >= 0 {
257 out.permission_type = get_i8(buf)?;
258 }
259 if flex {
260 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
261 }
262 Ok(out)
263 }
264}
265#[cfg(test)]
266impl AclCreation {
267 #[must_use]
268 pub fn populated(version: i16) -> Self {
269 let mut m = Self::default();
270 if version >= 0 {
271 m.resource_type = 1i8;
272 }
273 if version >= 0 {
274 m.resource_name = "x".to_string();
275 }
276 if version >= 1 {
277 m.resource_pattern_type = 1i8;
278 }
279 if version >= 0 {
280 m.principal = "x".to_string();
281 }
282 if version >= 0 {
283 m.host = "x".to_string();
284 }
285 if version >= 0 {
286 m.operation = 1i8;
287 }
288 if version >= 0 {
289 m.permission_type = 1i8;
290 }
291 m
292 }
293}
294#[must_use]
297#[allow(unused_comparisons)]
298pub fn default_json(_version: i16) -> ::serde_json::Value {
299 let mut obj = ::serde_json::Map::new();
300 obj.insert("creations".to_string(), ::serde_json::Value::Array(vec![]));
301 ::serde_json::Value::Object(obj)
302}
303impl crate::ProtocolRequest for CreateAclsRequest {
304 const API_KEY: i16 = API_KEY;
305 const MIN_VERSION: i16 = MIN_VERSION;
306 const MAX_VERSION: i16 = MAX_VERSION;
307 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
308 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
309 type Response = super::create_acls_response::CreateAclsResponse;
310}