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