crabka_protocol/opt/rustwide/workdir/generated/
ListGroupsRequest.owned.rs1use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned,
6 put_compact_string, put_string, string_len,
7};
8use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10
11pub const API_KEY: i16 = 16;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 5;
14pub const FLEXIBLE_MIN: i16 = 3;
15
16#[inline]
17fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct ListGroupsRequest {
21 pub states_filter: Vec<String>,
22 pub types_filter: Vec<String>,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25
26impl Encode for ListGroupsRequest {
27 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
30 }
31 let flex = is_flexible(version);
32 if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.states_filter).len(), flex); for it in &self.states_filter { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
33 if version >= 5 { { crate::primitives::array::put_array_len(buf, (self.types_filter).len(), flex); for it in &self.types_filter { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
34 if flex {
35 let tagged = WriteTaggedFields::new();
36 tagged.write(buf, &self.unknown_tagged_fields);
37 }
38 Ok(())
39 }
40 fn encoded_len(&self, version: i16) -> usize {
41 let flex = is_flexible(version);
42 let mut n: usize = 0;
43 if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.states_filter).len(), flex); let body: usize = (self.states_filter).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
44 if version >= 5 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.types_filter).len(), flex); let body: usize = (self.types_filter).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
45 if flex {
46 let known_pairs: Vec<(u32, usize)> = Vec::new();
47 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
48 }
49 n
50 }
51}
52
53impl<'de> Decode<'de> for ListGroupsRequest {
54 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57 }
58 let flex = is_flexible(version);
59 let mut out = Self::default();
60 if version >= 4 { out.states_filter = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
61 if version >= 5 { out.types_filter = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
62 if flex {
63 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
64 Ok(false)
65 })?;
66 }
67 Ok(out)
68 }
69}
70
71#[must_use]
74#[allow(unused_comparisons)]
75pub fn default_json(version: i16) -> ::serde_json::Value {
76 let mut obj = ::serde_json::Map::new();
77 if version >= 4 {
78 obj.insert("statesFilter".to_string(), ::serde_json::Value::Array(vec![]));
79 }
80 if version >= 5 {
81 obj.insert("typesFilter".to_string(), ::serde_json::Value::Array(vec![]));
82 }
83 ::serde_json::Value::Object(obj)
84}
85
86impl crate::ProtocolRequest for ListGroupsRequest {
87 const API_KEY: i16 = API_KEY;
88 const MIN_VERSION: i16 = MIN_VERSION;
89 const MAX_VERSION: i16 = MAX_VERSION;
90 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
91 type Response = super::list_groups_response::ListGroupsResponse;
92}