crabka_protocol/opt/rustwide/workdir/generated/
CreateAclsRequest.borrowed.rs1use crate::primitives::fixed::{get_i8, put_i8};
3use crate::primitives::string_bytes::{
4 compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10pub const API_KEY: i16 = 30;
11pub const MIN_VERSION: i16 = 1;
12pub const MAX_VERSION: i16 = 3;
13pub const FLEXIBLE_MIN: i16 = 2;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct CreateAclsRequest<'a> {
20 pub creations: Vec<AclCreation<'a>>,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl CreateAclsRequest<'_> {
24 pub fn to_owned(&self) -> crate::owned::create_acls_request::CreateAclsRequest {
25 crate::owned::create_acls_request::CreateAclsRequest {
26 creations: (self.creations).iter().map(AclCreation::to_owned).collect(),
27 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
28 }
29 }
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<'de> DecodeBorrow<'de> for CreateAclsRequest<'de> {
76 fn decode_borrow(buf: &mut &'de [u8], 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_borrow(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<'a> {
114 pub resource_type: i8,
115 pub resource_name: &'a str,
116 pub resource_pattern_type: i8,
117 pub principal: &'a str,
118 pub host: &'a str,
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: "",
128 resource_pattern_type: 3i8,
129 principal: "",
130 host: "",
131 operation: 0i8,
132 permission_type: 0i8,
133 unknown_tagged_fields: Default::default(),
134 }
135 }
136}
137impl AclCreation<'_> {
138 pub fn to_owned(&self) -> crate::owned::create_acls_request::AclCreation {
139 crate::owned::create_acls_request::AclCreation {
140 resource_type: (self.resource_type),
141 resource_name: (self.resource_name).to_string(),
142 resource_pattern_type: (self.resource_pattern_type),
143 principal: (self.principal).to_string(),
144 host: (self.host).to_string(),
145 operation: (self.operation),
146 permission_type: (self.permission_type),
147 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
148 }
149 }
150}
151impl Encode for AclCreation<'_> {
152 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
153 let flex = version >= 2;
154 if version >= 0 {
155 put_i8(buf, self.resource_type);
156 }
157 if version >= 0 {
158 if flex {
159 put_compact_string(buf, self.resource_name);
160 } else {
161 put_string(buf, self.resource_name);
162 }
163 }
164 if version >= 1 {
165 put_i8(buf, self.resource_pattern_type);
166 }
167 if version >= 0 {
168 if flex {
169 put_compact_string(buf, self.principal);
170 } else {
171 put_string(buf, self.principal);
172 }
173 }
174 if version >= 0 {
175 if flex {
176 put_compact_string(buf, self.host);
177 } else {
178 put_string(buf, self.host);
179 }
180 }
181 if version >= 0 {
182 put_i8(buf, self.operation);
183 }
184 if version >= 0 {
185 put_i8(buf, self.permission_type);
186 }
187 if flex {
188 let tagged = WriteTaggedFields::new();
189 tagged.write(buf, &self.unknown_tagged_fields);
190 }
191 Ok(())
192 }
193 fn encoded_len(&self, version: i16) -> usize {
194 let flex = version >= 2;
195 let mut n: usize = 0;
196 if version >= 0 {
197 n += 1;
198 }
199 if version >= 0 {
200 n += if flex {
201 compact_string_len(self.resource_name)
202 } else {
203 string_len(self.resource_name)
204 };
205 }
206 if version >= 1 {
207 n += 1;
208 }
209 if version >= 0 {
210 n += if flex {
211 compact_string_len(self.principal)
212 } else {
213 string_len(self.principal)
214 };
215 }
216 if version >= 0 {
217 n += if flex {
218 compact_string_len(self.host)
219 } else {
220 string_len(self.host)
221 };
222 }
223 if version >= 0 {
224 n += 1;
225 }
226 if version >= 0 {
227 n += 1;
228 }
229 if flex {
230 let known_pairs: Vec<(u32, usize)> = Vec::new();
231 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
232 }
233 n
234 }
235}
236impl<'de> DecodeBorrow<'de> for AclCreation<'de> {
237 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
238 let flex = version >= 2;
239 let mut out = Self::default();
240 if version >= 0 {
241 out.resource_type = get_i8(buf)?;
242 }
243 if version >= 0 {
244 out.resource_name = if flex {
245 get_compact_string_borrowed(buf)?
246 } else {
247 get_string_borrowed(buf)?
248 };
249 }
250 if version >= 1 {
251 out.resource_pattern_type = get_i8(buf)?;
252 }
253 if version >= 0 {
254 out.principal = if flex {
255 get_compact_string_borrowed(buf)?
256 } else {
257 get_string_borrowed(buf)?
258 };
259 }
260 if version >= 0 {
261 out.host = if flex {
262 get_compact_string_borrowed(buf)?
263 } else {
264 get_string_borrowed(buf)?
265 };
266 }
267 if version >= 0 {
268 out.operation = get_i8(buf)?;
269 }
270 if version >= 0 {
271 out.permission_type = get_i8(buf)?;
272 }
273 if flex {
274 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
275 }
276 Ok(out)
277 }
278}
279#[cfg(test)]
280impl AclCreation<'_> {
281 #[must_use]
282 pub fn populated(version: i16) -> Self {
283 let mut m = Self::default();
284 if version >= 0 {
285 m.resource_type = 1i8;
286 }
287 if version >= 0 {
288 m.resource_name = "x";
289 }
290 if version >= 1 {
291 m.resource_pattern_type = 1i8;
292 }
293 if version >= 0 {
294 m.principal = "x";
295 }
296 if version >= 0 {
297 m.host = "x";
298 }
299 if version >= 0 {
300 m.operation = 1i8;
301 }
302 if version >= 0 {
303 m.permission_type = 1i8;
304 }
305 m
306 }
307}