krabka_protocol/opt/rustwide/workdir/generated/
ListGroupsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::string_bytes::{
8 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
9 put_string, string_len,
10 },
11 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 16;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const LATEST_STABLE_VERSION: i16 = 5;
17pub const FLEXIBLE_MIN: i16 = 3;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ListGroupsRequest {
25 pub states_filter: Vec<String>,
26 pub types_filter: Vec<String>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for ListGroupsRequest {
30 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32 return Err(ProtocolError::UnsupportedVersion {
33 api_key: API_KEY,
34 version,
35 });
36 }
37 let flex = is_flexible(version);
38 if version >= 4 {
39 {
40 crate::primitives::array::put_array_len(buf, (self.states_filter).len(), flex);
41 for it in &self.states_filter {
42 if flex {
43 let () = put_compact_string(buf, it);
44 } else {
45 let () = put_string(buf, it);
46 }
47 }
48 };
49 }
50 if version >= 5 {
51 {
52 crate::primitives::array::put_array_len(buf, (self.types_filter).len(), flex);
53 for it in &self.types_filter {
54 if flex {
55 let () = put_compact_string(buf, it);
56 } else {
57 let () = put_string(buf, it);
58 }
59 }
60 };
61 }
62 if flex {
63 let tagged = WriteTaggedFields::new();
64 tagged.write(buf, &self.unknown_tagged_fields);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version >= 4 {
72 n += {
73 let prefix = crate::primitives::array::array_len_prefix_len(
74 (self.states_filter).len(),
75 flex,
76 );
77 let body: usize = (self.states_filter)
78 .iter()
79 .map(|it| {
80 if flex {
81 compact_string_len(it)
82 } else {
83 string_len(it)
84 }
85 })
86 .sum();
87 prefix + body
88 };
89 }
90 if version >= 5 {
91 n += {
92 let prefix =
93 crate::primitives::array::array_len_prefix_len((self.types_filter).len(), flex);
94 let body: usize = (self.types_filter)
95 .iter()
96 .map(|it| {
97 if flex {
98 compact_string_len(it)
99 } else {
100 string_len(it)
101 }
102 })
103 .sum();
104 prefix + body
105 };
106 }
107 if flex {
108 let known_pairs: Vec<(u32, usize)> = Vec::new();
109 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
110 }
111 n
112 }
113}
114impl Decode<'_> for ListGroupsRequest {
115 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
116 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
117 return Err(ProtocolError::UnsupportedVersion {
118 api_key: API_KEY,
119 version,
120 });
121 }
122 let flex = is_flexible(version);
123 let mut out = Self::default();
124 if version >= 4 {
125 out.states_filter = {
126 let n = crate::primitives::array::get_array_len(buf, flex)?;
127 let mut v = Vec::with_capacity(n);
128 for _ in 0..n {
129 v.push(if flex {
130 get_compact_string_owned(buf)?
131 } else {
132 get_string_owned(buf)?
133 });
134 }
135 v
136 };
137 }
138 if version >= 5 {
139 out.types_filter = {
140 let n = crate::primitives::array::get_array_len(buf, flex)?;
141 let mut v = Vec::with_capacity(n);
142 for _ in 0..n {
143 v.push(if flex {
144 get_compact_string_owned(buf)?
145 } else {
146 get_string_owned(buf)?
147 });
148 }
149 v
150 };
151 }
152 if flex {
153 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
154 }
155 Ok(out)
156 }
157}
158#[cfg(test)]
159impl ListGroupsRequest {
160 #[must_use]
161 pub fn populated(version: i16) -> Self {
162 let mut m = Self::default();
163 if version >= 4 {
164 m.states_filter = vec!["x".to_string()];
165 }
166 if version >= 5 {
167 m.types_filter = vec!["x".to_string()];
168 }
169 m
170 }
171}
172#[must_use]
175#[allow(unused_comparisons)]
176pub fn default_json(version: i16) -> ::serde_json::Value {
177 let mut obj = ::serde_json::Map::new();
178 if version >= 4 {
179 obj.insert(
180 "statesFilter".to_string(),
181 ::serde_json::Value::Array(vec![]),
182 );
183 }
184 if version >= 5 {
185 obj.insert(
186 "typesFilter".to_string(),
187 ::serde_json::Value::Array(vec![]),
188 );
189 }
190 ::serde_json::Value::Object(obj)
191}
192impl crate::ProtocolRequest for ListGroupsRequest {
193 const API_KEY: i16 = API_KEY;
194 const MIN_VERSION: i16 = MIN_VERSION;
195 const MAX_VERSION: i16 = MAX_VERSION;
196 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
197 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
198 type Response = super::list_groups_response::ListGroupsResponse;
199}