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