krabka_protocol/opt/rustwide/workdir/generated/
ListGroupsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i16, get_i32, put_i16, put_i32},
10 string_bytes::{
11 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12 put_string, string_len,
13 },
14 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 16;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 5;
20pub const FLEXIBLE_MIN: i16 = 3;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ListGroupsResponse {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub groups: Vec<ListedGroup>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ListGroupsResponse {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::UnsupportedVersion {
37 api_key: API_KEY,
38 version,
39 });
40 }
41 let flex = is_flexible(version);
42 if version >= 1 {
43 put_i32(buf, self.throttle_time_ms);
44 }
45 if version >= 0 {
46 put_i16(buf, self.error_code);
47 }
48 if version >= 0 {
49 {
50 put_array_len(buf, (self.groups).len(), flex)?;
51 for it in &self.groups {
52 it.encode(buf, version)?;
53 }
54 }
55 }
56 if flex {
57 let tagged = WriteTaggedFields::new();
58 tagged.write(buf, &self.unknown_tagged_fields)?;
59 }
60 Ok(())
61 }
62 fn encoded_len(&self, version: i16) -> usize {
63 let flex = is_flexible(version);
64 let mut n: usize = 0;
65 if version >= 1 {
66 n += 4;
67 }
68 if version >= 0 {
69 n += 2;
70 }
71 if version >= 0 {
72 n += {
73 let prefix = array_len_prefix_len((self.groups).len(), flex);
74 let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
75 prefix + body
76 };
77 }
78 if flex {
79 let known_pairs: Vec<(u32, usize)> = Vec::new();
80 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
81 }
82 n
83 }
84}
85impl Decode<'_> for ListGroupsResponse {
86 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
87 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88 return Err(ProtocolError::UnsupportedVersion {
89 api_key: API_KEY,
90 version,
91 });
92 }
93 let flex = is_flexible(version);
94 let mut out = Self::default();
95 if version >= 1 {
96 out.throttle_time_ms = get_i32(buf)?;
97 }
98 if version >= 0 {
99 out.error_code = get_i16(buf)?;
100 }
101 if version >= 0 {
102 out.groups = {
103 let n = get_array_len(buf, flex)?;
104 let mut v = Vec::with_capacity(n);
105 for _ in 0..n {
106 v.push(ListedGroup::decode(buf, version)?);
107 }
108 v
109 };
110 }
111 if flex {
112 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
113 }
114 Ok(out)
115 }
116}
117#[cfg(test)]
118impl ListGroupsResponse {
119 #[must_use]
120 pub fn populated(version: i16) -> Self {
121 let mut m = Self::default();
122 if version >= 1 {
123 m.throttle_time_ms = 1i32;
124 }
125 if version >= 0 {
126 m.error_code = 1i16;
127 }
128 if version >= 0 {
129 m.groups = vec![ListedGroup::populated(version)];
130 }
131 m
132 }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct ListedGroup {
136 pub group_id: String,
137 pub protocol_type: String,
138 pub group_state: String,
139 pub group_type: String,
140 pub unknown_tagged_fields: UnknownTaggedFields,
141}
142impl Encode for ListedGroup {
143 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
144 let flex = version >= 3;
145 if version >= 0 {
146 if flex {
147 put_compact_string(buf, &self.group_id)?;
148 } else {
149 put_string(buf, &self.group_id)?;
150 }
151 }
152 if version >= 0 {
153 if flex {
154 put_compact_string(buf, &self.protocol_type)?;
155 } else {
156 put_string(buf, &self.protocol_type)?;
157 }
158 }
159 if version >= 4 {
160 if flex {
161 put_compact_string(buf, &self.group_state)?;
162 } else {
163 put_string(buf, &self.group_state)?;
164 }
165 }
166 if version >= 5 {
167 if flex {
168 put_compact_string(buf, &self.group_type)?;
169 } else {
170 put_string(buf, &self.group_type)?;
171 }
172 }
173 if flex {
174 let tagged = WriteTaggedFields::new();
175 tagged.write(buf, &self.unknown_tagged_fields)?;
176 }
177 Ok(())
178 }
179 fn encoded_len(&self, version: i16) -> usize {
180 let flex = version >= 3;
181 let mut n: usize = 0;
182 if version >= 0 {
183 n += if flex {
184 compact_string_len(&self.group_id)
185 } else {
186 string_len(&self.group_id)
187 };
188 }
189 if version >= 0 {
190 n += if flex {
191 compact_string_len(&self.protocol_type)
192 } else {
193 string_len(&self.protocol_type)
194 };
195 }
196 if version >= 4 {
197 n += if flex {
198 compact_string_len(&self.group_state)
199 } else {
200 string_len(&self.group_state)
201 };
202 }
203 if version >= 5 {
204 n += if flex {
205 compact_string_len(&self.group_type)
206 } else {
207 string_len(&self.group_type)
208 };
209 }
210 if flex {
211 let known_pairs: Vec<(u32, usize)> = Vec::new();
212 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
213 }
214 n
215 }
216}
217impl Decode<'_> for ListedGroup {
218 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
219 let flex = version >= 3;
220 let mut out = Self::default();
221 if version >= 0 {
222 out.group_id = if flex {
223 get_compact_string_owned(buf)?
224 } else {
225 get_string_owned(buf)?
226 };
227 }
228 if version >= 0 {
229 out.protocol_type = if flex {
230 get_compact_string_owned(buf)?
231 } else {
232 get_string_owned(buf)?
233 };
234 }
235 if version >= 4 {
236 out.group_state = if flex {
237 get_compact_string_owned(buf)?
238 } else {
239 get_string_owned(buf)?
240 };
241 }
242 if version >= 5 {
243 out.group_type = if flex {
244 get_compact_string_owned(buf)?
245 } else {
246 get_string_owned(buf)?
247 };
248 }
249 if flex {
250 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
251 }
252 Ok(out)
253 }
254}
255#[cfg(test)]
256impl ListedGroup {
257 #[must_use]
258 pub fn populated(version: i16) -> Self {
259 let mut m = Self::default();
260 if version >= 0 {
261 m.group_id = "x".to_owned();
262 }
263 if version >= 0 {
264 m.protocol_type = "x".to_owned();
265 }
266 if version >= 4 {
267 m.group_state = "x".to_owned();
268 }
269 if version >= 5 {
270 m.group_type = "x".to_owned();
271 }
272 m
273 }
274}
275#[must_use]
278#[allow(unused_comparisons)]
279pub fn default_json(version: i16) -> ::serde_json::Value {
280 let mut obj = ::serde_json::Map::new();
281 if version >= 1 {
282 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
283 }
284 obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
285 obj.insert("groups".to_owned(), ::serde_json::Value::Array(vec![]));
286 ::serde_json::Value::Object(obj)
287}