crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasRequest.borrowed.rs1use crate::primitives::fixed::{get_bool, get_f64, put_bool, put_f64};
3use crate::primitives::string_bytes::{
4 compact_nullable_string_len, compact_string_len, nullable_string_len,
5 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
6};
7use crate::primitives::string_bytes_borrowed::{
8 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
9 get_nullable_string_borrowed, get_string_borrowed,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
13use bytes::BufMut;
14pub const API_KEY: i16 = 49;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 1;
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Default)]
23pub struct AlterClientQuotasRequest<'a> {
24 pub entries: Vec<EntryData<'a>>,
25 pub validate_only: bool,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl AlterClientQuotasRequest<'_> {
29 pub fn to_owned(&self) -> crate::owned::alter_client_quotas_request::AlterClientQuotasRequest {
30 crate::owned::alter_client_quotas_request::AlterClientQuotasRequest {
31 entries: (self.entries).iter().map(EntryData::to_owned).collect(),
32 validate_only: (self.validate_only),
33 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34 }
35 }
36}
37impl Encode for AlterClientQuotasRequest<'_> {
38 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40 return Err(ProtocolError::UnsupportedVersion {
41 api_key: API_KEY,
42 version,
43 });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 {
47 {
48 crate::primitives::array::put_array_len(buf, (self.entries).len(), flex);
49 for it in &self.entries {
50 it.encode(buf, version)?;
51 }
52 }
53 }
54 if version >= 0 {
55 put_bool(buf, self.validate_only);
56 }
57 if flex {
58 let tagged = WriteTaggedFields::new();
59 tagged.write(buf, &self.unknown_tagged_fields);
60 }
61 Ok(())
62 }
63 fn encoded_len(&self, version: i16) -> usize {
64 let flex = is_flexible(version);
65 let mut n: usize = 0;
66 if version >= 0 {
67 n += {
68 let prefix =
69 crate::primitives::array::array_len_prefix_len((self.entries).len(), flex);
70 let body: usize = (self.entries)
71 .iter()
72 .map(|it| it.encoded_len(version))
73 .sum();
74 prefix + body
75 };
76 }
77 if version >= 0 {
78 n += 1;
79 }
80 if flex {
81 let known_pairs: Vec<(u32, usize)> = Vec::new();
82 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
83 }
84 n
85 }
86}
87impl<'de> DecodeBorrow<'de> for AlterClientQuotasRequest<'de> {
88 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
89 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90 return Err(ProtocolError::UnsupportedVersion {
91 api_key: API_KEY,
92 version,
93 });
94 }
95 let flex = is_flexible(version);
96 let mut out = Self::default();
97 if version >= 0 {
98 out.entries = {
99 let n = crate::primitives::array::get_array_len(buf, flex)?;
100 let mut v = Vec::with_capacity(n);
101 for _ in 0..n {
102 v.push(EntryData::decode_borrow(buf, version)?);
103 }
104 v
105 };
106 }
107 if version >= 0 {
108 out.validate_only = get_bool(buf)?;
109 }
110 if flex {
111 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
112 }
113 Ok(out)
114 }
115}
116#[cfg(test)]
117impl AlterClientQuotasRequest<'_> {
118 #[must_use]
119 pub fn populated(version: i16) -> Self {
120 let mut m = Self::default();
121 if version >= 0 {
122 m.entries = vec![EntryData::populated(version)];
123 }
124 if version >= 0 {
125 m.validate_only = true;
126 }
127 m
128 }
129}
130#[derive(Debug, Clone, PartialEq, Default)]
131pub struct EntryData<'a> {
132 pub entity: Vec<EntityData<'a>>,
133 pub ops: Vec<OpData<'a>>,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136impl EntryData<'_> {
137 pub fn to_owned(&self) -> crate::owned::alter_client_quotas_request::EntryData {
138 crate::owned::alter_client_quotas_request::EntryData {
139 entity: (self.entity).iter().map(EntityData::to_owned).collect(),
140 ops: (self.ops).iter().map(OpData::to_owned).collect(),
141 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
142 }
143 }
144}
145impl Encode for EntryData<'_> {
146 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
147 let flex = version >= 1;
148 if version >= 0 {
149 {
150 crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
151 for it in &self.entity {
152 it.encode(buf, version)?;
153 }
154 }
155 }
156 if version >= 0 {
157 {
158 crate::primitives::array::put_array_len(buf, (self.ops).len(), flex);
159 for it in &self.ops {
160 it.encode(buf, version)?;
161 }
162 }
163 }
164 if flex {
165 let tagged = WriteTaggedFields::new();
166 tagged.write(buf, &self.unknown_tagged_fields);
167 }
168 Ok(())
169 }
170 fn encoded_len(&self, version: i16) -> usize {
171 let flex = version >= 1;
172 let mut n: usize = 0;
173 if version >= 0 {
174 n += {
175 let prefix =
176 crate::primitives::array::array_len_prefix_len((self.entity).len(), flex);
177 let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum();
178 prefix + body
179 };
180 }
181 if version >= 0 {
182 n += {
183 let prefix = crate::primitives::array::array_len_prefix_len((self.ops).len(), flex);
184 let body: usize = (self.ops).iter().map(|it| it.encoded_len(version)).sum();
185 prefix + body
186 };
187 }
188 if flex {
189 let known_pairs: Vec<(u32, usize)> = Vec::new();
190 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
191 }
192 n
193 }
194}
195impl<'de> DecodeBorrow<'de> for EntryData<'de> {
196 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
197 let flex = version >= 1;
198 let mut out = Self::default();
199 if version >= 0 {
200 out.entity = {
201 let n = crate::primitives::array::get_array_len(buf, flex)?;
202 let mut v = Vec::with_capacity(n);
203 for _ in 0..n {
204 v.push(EntityData::decode_borrow(buf, version)?);
205 }
206 v
207 };
208 }
209 if version >= 0 {
210 out.ops = {
211 let n = crate::primitives::array::get_array_len(buf, flex)?;
212 let mut v = Vec::with_capacity(n);
213 for _ in 0..n {
214 v.push(OpData::decode_borrow(buf, version)?);
215 }
216 v
217 };
218 }
219 if flex {
220 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
221 }
222 Ok(out)
223 }
224}
225#[cfg(test)]
226impl EntryData<'_> {
227 #[must_use]
228 pub fn populated(version: i16) -> Self {
229 let mut m = Self::default();
230 if version >= 0 {
231 m.entity = vec![EntityData::populated(version)];
232 }
233 if version >= 0 {
234 m.ops = vec![OpData::populated(version)];
235 }
236 m
237 }
238}
239#[derive(Debug, Clone, PartialEq, Eq, Default)]
240pub struct EntityData<'a> {
241 pub entity_type: &'a str,
242 pub entity_name: Option<&'a str>,
243 pub unknown_tagged_fields: UnknownTaggedFields,
244}
245impl EntityData<'_> {
246 pub fn to_owned(&self) -> crate::owned::alter_client_quotas_request::EntityData {
247 crate::owned::alter_client_quotas_request::EntityData {
248 entity_type: (self.entity_type).to_string(),
249 entity_name: (self.entity_name).map(std::string::ToString::to_string),
250 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
251 }
252 }
253}
254impl Encode for EntityData<'_> {
255 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
256 let flex = version >= 1;
257 if version >= 0 {
258 if flex {
259 put_compact_string(buf, self.entity_type);
260 } else {
261 put_string(buf, self.entity_type);
262 }
263 }
264 if version >= 0 {
265 if flex {
266 put_compact_nullable_string(buf, self.entity_name);
267 } else {
268 put_nullable_string(buf, self.entity_name);
269 }
270 }
271 if flex {
272 let tagged = WriteTaggedFields::new();
273 tagged.write(buf, &self.unknown_tagged_fields);
274 }
275 Ok(())
276 }
277 fn encoded_len(&self, version: i16) -> usize {
278 let flex = version >= 1;
279 let mut n: usize = 0;
280 if version >= 0 {
281 n += if flex {
282 compact_string_len(self.entity_type)
283 } else {
284 string_len(self.entity_type)
285 };
286 }
287 if version >= 0 {
288 n += if flex {
289 compact_nullable_string_len(self.entity_name)
290 } else {
291 nullable_string_len(self.entity_name)
292 };
293 }
294 if flex {
295 let known_pairs: Vec<(u32, usize)> = Vec::new();
296 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
297 }
298 n
299 }
300}
301impl<'de> DecodeBorrow<'de> for EntityData<'de> {
302 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
303 let flex = version >= 1;
304 let mut out = Self::default();
305 if version >= 0 {
306 out.entity_type = if flex {
307 get_compact_string_borrowed(buf)?
308 } else {
309 get_string_borrowed(buf)?
310 };
311 }
312 if version >= 0 {
313 out.entity_name = if flex {
314 get_compact_nullable_string_borrowed(buf)?
315 } else {
316 get_nullable_string_borrowed(buf)?
317 };
318 }
319 if flex {
320 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
321 }
322 Ok(out)
323 }
324}
325#[cfg(test)]
326impl EntityData<'_> {
327 #[must_use]
328 pub fn populated(version: i16) -> Self {
329 let mut m = Self::default();
330 if version >= 0 {
331 m.entity_type = "x";
332 }
333 if version >= 0 {
334 m.entity_name = Some("x");
335 }
336 m
337 }
338}
339#[derive(Debug, Clone, PartialEq)]
340pub struct OpData<'a> {
341 pub key: &'a str,
342 pub value: f64,
343 pub remove: bool,
344 pub unknown_tagged_fields: UnknownTaggedFields,
345}
346impl Default for OpData<'_> {
347 fn default() -> Self {
348 Self {
349 key: "",
350 value: 0.0f64,
351 remove: false,
352 unknown_tagged_fields: Default::default(),
353 }
354 }
355}
356impl OpData<'_> {
357 pub fn to_owned(&self) -> crate::owned::alter_client_quotas_request::OpData {
358 crate::owned::alter_client_quotas_request::OpData {
359 key: (self.key).to_string(),
360 value: (self.value),
361 remove: (self.remove),
362 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
363 }
364 }
365}
366impl Encode for OpData<'_> {
367 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
368 let flex = version >= 1;
369 if version >= 0 {
370 if flex {
371 put_compact_string(buf, self.key);
372 } else {
373 put_string(buf, self.key);
374 }
375 }
376 if version >= 0 {
377 put_f64(buf, self.value);
378 }
379 if version >= 0 {
380 put_bool(buf, self.remove);
381 }
382 if flex {
383 let tagged = WriteTaggedFields::new();
384 tagged.write(buf, &self.unknown_tagged_fields);
385 }
386 Ok(())
387 }
388 fn encoded_len(&self, version: i16) -> usize {
389 let flex = version >= 1;
390 let mut n: usize = 0;
391 if version >= 0 {
392 n += if flex {
393 compact_string_len(self.key)
394 } else {
395 string_len(self.key)
396 };
397 }
398 if version >= 0 {
399 n += 8;
400 }
401 if version >= 0 {
402 n += 1;
403 }
404 if flex {
405 let known_pairs: Vec<(u32, usize)> = Vec::new();
406 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
407 }
408 n
409 }
410}
411impl<'de> DecodeBorrow<'de> for OpData<'de> {
412 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
413 let flex = version >= 1;
414 let mut out = Self::default();
415 if version >= 0 {
416 out.key = if flex {
417 get_compact_string_borrowed(buf)?
418 } else {
419 get_string_borrowed(buf)?
420 };
421 }
422 if version >= 0 {
423 out.value = get_f64(buf)?;
424 }
425 if version >= 0 {
426 out.remove = get_bool(buf)?;
427 }
428 if flex {
429 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
430 }
431 Ok(out)
432 }
433}
434#[cfg(test)]
435impl OpData<'_> {
436 #[must_use]
437 pub fn populated(version: i16) -> Self {
438 let mut m = Self::default();
439 if version >= 0 {
440 m.key = "x";
441 }
442 if version >= 0 {
443 m.value = 1.0f64;
444 }
445 if version >= 0 {
446 m.remove = true;
447 }
448 m
449 }
450}