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