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