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