1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i16, get_i32, put_i16, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12 nullable_string_len, put_compact_nullable_string, put_compact_string,
13 put_nullable_string, put_string, string_len,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 77;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct ShareGroupDescribeResponse {
29 pub throttle_time_ms: i32,
30 pub groups: Vec<DescribedGroup>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ShareGroupDescribeResponse {
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 >= 0 {
43 put_i32(buf, self.throttle_time_ms);
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 >= 0 {
63 n += 4;
64 }
65 if version >= 0 {
66 n += {
67 let prefix =
68 crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
69 let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
70 prefix + body
71 };
72 }
73 if flex {
74 let known_pairs: Vec<(u32, usize)> = Vec::new();
75 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76 }
77 n
78 }
79}
80impl Decode<'_> for ShareGroupDescribeResponse {
81 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83 return Err(ProtocolError::UnsupportedVersion {
84 api_key: API_KEY,
85 version,
86 });
87 }
88 let flex = is_flexible(version);
89 let mut out = Self::default();
90 if version >= 0 {
91 out.throttle_time_ms = get_i32(buf)?;
92 }
93 if version >= 0 {
94 out.groups = {
95 let n = crate::primitives::array::get_array_len(buf, flex)?;
96 let mut v = Vec::with_capacity(n);
97 for _ in 0..n {
98 v.push(DescribedGroup::decode(buf, version)?);
99 }
100 v
101 };
102 }
103 if flex {
104 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105 }
106 Ok(out)
107 }
108}
109#[cfg(test)]
110impl ShareGroupDescribeResponse {
111 #[must_use]
112 pub fn populated(version: i16) -> Self {
113 let mut m = Self::default();
114 if version >= 0 {
115 m.throttle_time_ms = 1i32;
116 }
117 if version >= 0 {
118 m.groups = vec![DescribedGroup::populated(version)];
119 }
120 m
121 }
122}
123#[derive(Debug, Clone, PartialEq, Eq)]
124pub struct DescribedGroup {
125 pub error_code: i16,
126 pub error_message: Option<String>,
127 pub group_id: String,
128 pub group_state: String,
129 pub group_epoch: i32,
130 pub assignment_epoch: i32,
131 pub assignor_name: String,
132 pub members: Vec<Member>,
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 group_epoch: 0i32,
144 assignment_epoch: 0i32,
145 assignor_name: String::new(),
146 members: Vec::new(),
147 authorized_operations: -2_147_483_648i32,
148 unknown_tagged_fields: UnknownTaggedFields::default(),
149 }
150 }
151}
152impl DescribedGroup {
153 fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
154 if version >= 0 {
155 put_i16(buf, self.error_code);
156 }
157 }
158 fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
159 if version >= 0 {
160 if flex {
161 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
162 } else {
163 let () = put_nullable_string(buf, self.error_message.as_deref());
164 }
165 }
166 }
167 fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
168 if version >= 0 {
169 if flex {
170 let () = put_compact_string(buf, &self.group_id);
171 } else {
172 let () = put_string(buf, &self.group_id);
173 }
174 }
175 }
176 fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
177 if version >= 0 {
178 if flex {
179 let () = put_compact_string(buf, &self.group_state);
180 } else {
181 let () = put_string(buf, &self.group_state);
182 }
183 }
184 }
185 fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
186 if version >= 0 {
187 put_i32(buf, self.group_epoch);
188 }
189 }
190 fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
191 if version >= 0 {
192 put_i32(buf, self.assignment_epoch);
193 }
194 }
195 fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
196 if version >= 0 {
197 if flex {
198 let () = put_compact_string(buf, &self.assignor_name);
199 } else {
200 let () = put_string(buf, &self.assignor_name);
201 }
202 }
203 }
204 fn encode_field_7<B: BufMut>(
205 &self,
206 buf: &mut B,
207 version: i16,
208 flex: bool,
209 ) -> Result<(), ProtocolError> {
210 if version >= 0 {
211 {
212 crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
213 for it in &self.members {
214 it.encode(buf, version)?;
215 }
216 };
217 }
218 Ok(())
219 }
220 fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
221 if version >= 0 {
222 put_i32(buf, self.authorized_operations);
223 }
224 }
225 fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
226 if flex {
227 let tagged = WriteTaggedFields::new();
228 tagged.write(buf, &self.unknown_tagged_fields);
229 }
230 }
231 fn decode_field_0<B: Buf>(
232 out: &mut Self,
233 buf: &mut B,
234 version: i16,
235 _flex: bool,
236 ) -> Result<(), ProtocolError> {
237 if version >= 0 {
238 out.error_code = get_i16(buf)?;
239 }
240 Ok(())
241 }
242 fn decode_field_1<B: Buf>(
243 out: &mut Self,
244 buf: &mut B,
245 version: i16,
246 flex: bool,
247 ) -> Result<(), ProtocolError> {
248 if version >= 0 {
249 out.error_message = if flex {
250 get_compact_nullable_string_owned(buf)?
251 } else {
252 get_nullable_string_owned(buf)?
253 };
254 }
255 Ok(())
256 }
257 fn decode_field_2<B: Buf>(
258 out: &mut Self,
259 buf: &mut B,
260 version: i16,
261 flex: bool,
262 ) -> Result<(), ProtocolError> {
263 if version >= 0 {
264 out.group_id = if flex {
265 get_compact_string_owned(buf)?
266 } else {
267 get_string_owned(buf)?
268 };
269 }
270 Ok(())
271 }
272 fn decode_field_3<B: Buf>(
273 out: &mut Self,
274 buf: &mut B,
275 version: i16,
276 flex: bool,
277 ) -> Result<(), ProtocolError> {
278 if version >= 0 {
279 out.group_state = if flex {
280 get_compact_string_owned(buf)?
281 } else {
282 get_string_owned(buf)?
283 };
284 }
285 Ok(())
286 }
287 fn decode_field_4<B: Buf>(
288 out: &mut Self,
289 buf: &mut B,
290 version: i16,
291 _flex: bool,
292 ) -> Result<(), ProtocolError> {
293 if version >= 0 {
294 out.group_epoch = get_i32(buf)?;
295 }
296 Ok(())
297 }
298 fn decode_field_5<B: Buf>(
299 out: &mut Self,
300 buf: &mut B,
301 version: i16,
302 _flex: bool,
303 ) -> Result<(), ProtocolError> {
304 if version >= 0 {
305 out.assignment_epoch = get_i32(buf)?;
306 }
307 Ok(())
308 }
309 fn decode_field_6<B: Buf>(
310 out: &mut Self,
311 buf: &mut B,
312 version: i16,
313 flex: bool,
314 ) -> Result<(), ProtocolError> {
315 if version >= 0 {
316 out.assignor_name = if flex {
317 get_compact_string_owned(buf)?
318 } else {
319 get_string_owned(buf)?
320 };
321 }
322 Ok(())
323 }
324 fn decode_field_7<B: Buf>(
325 out: &mut Self,
326 buf: &mut B,
327 version: i16,
328 flex: bool,
329 ) -> Result<(), ProtocolError> {
330 if version >= 0 {
331 out.members = {
332 let n = crate::primitives::array::get_array_len(buf, flex)?;
333 let mut v = Vec::with_capacity(n);
334 for _ in 0..n {
335 v.push(Member::decode(buf, version)?);
336 }
337 v
338 };
339 }
340 Ok(())
341 }
342 fn decode_field_8<B: Buf>(
343 out: &mut Self,
344 buf: &mut B,
345 version: i16,
346 _flex: bool,
347 ) -> Result<(), ProtocolError> {
348 if version >= 0 {
349 out.authorized_operations = get_i32(buf)?;
350 }
351 Ok(())
352 }
353 fn decode_tagged_fields<B: Buf>(
354 out: &mut Self,
355 buf: &mut B,
356 _version: i16,
357 flex: bool,
358 ) -> Result<(), ProtocolError> {
359 if flex {
360 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
361 }
362 Ok(())
363 }
364}
365impl Encode for DescribedGroup {
366 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
367 let flex = version >= 0;
368 self.encode_field_0(buf, version, flex);
369 self.encode_field_1(buf, version, flex);
370 self.encode_field_2(buf, version, flex);
371 self.encode_field_3(buf, version, flex);
372 self.encode_field_4(buf, version, flex);
373 self.encode_field_5(buf, version, flex);
374 self.encode_field_6(buf, version, flex);
375 self.encode_field_7(buf, version, flex)?;
376 self.encode_field_8(buf, version, flex);
377 self.encode_tagged_fields(buf, version, flex);
378 Ok(())
379 }
380 fn encoded_len(&self, version: i16) -> usize {
381 let flex = version >= 0;
382 let mut n: usize = 0;
383 if version >= 0 {
384 n += 2;
385 }
386 if version >= 0 {
387 n += if flex {
388 compact_nullable_string_len(self.error_message.as_deref())
389 } else {
390 nullable_string_len(self.error_message.as_deref())
391 };
392 }
393 if version >= 0 {
394 n += if flex {
395 compact_string_len(&self.group_id)
396 } else {
397 string_len(&self.group_id)
398 };
399 }
400 if version >= 0 {
401 n += if flex {
402 compact_string_len(&self.group_state)
403 } else {
404 string_len(&self.group_state)
405 };
406 }
407 if version >= 0 {
408 n += 4;
409 }
410 if version >= 0 {
411 n += 4;
412 }
413 if version >= 0 {
414 n += if flex {
415 compact_string_len(&self.assignor_name)
416 } else {
417 string_len(&self.assignor_name)
418 };
419 }
420 if version >= 0 {
421 n += {
422 let prefix =
423 crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
424 let body: usize = (self.members)
425 .iter()
426 .map(|it| it.encoded_len(version))
427 .sum();
428 prefix + body
429 };
430 }
431 if version >= 0 {
432 n += 4;
433 }
434 if flex {
435 let known_pairs: Vec<(u32, usize)> = Vec::new();
436 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
437 }
438 n
439 }
440}
441impl Decode<'_> for DescribedGroup {
442 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
443 let flex = version >= 0;
444 let mut out = Self::default();
445 Self::decode_field_0(&mut out, buf, version, flex)?;
446 Self::decode_field_1(&mut out, buf, version, flex)?;
447 Self::decode_field_2(&mut out, buf, version, flex)?;
448 Self::decode_field_3(&mut out, buf, version, flex)?;
449 Self::decode_field_4(&mut out, buf, version, flex)?;
450 Self::decode_field_5(&mut out, buf, version, flex)?;
451 Self::decode_field_6(&mut out, buf, version, flex)?;
452 Self::decode_field_7(&mut out, buf, version, flex)?;
453 Self::decode_field_8(&mut out, buf, version, flex)?;
454 Self::decode_tagged_fields(&mut out, buf, version, flex)?;
455 Ok(out)
456 }
457}
458#[cfg(test)]
459impl DescribedGroup {
460 #[must_use]
461 pub fn populated(version: i16) -> Self {
462 let mut m = Self::default();
463 if version >= 0 {
464 m.error_code = 1i16;
465 }
466 if version >= 0 {
467 m.error_message = Some("x".to_string());
468 }
469 if version >= 0 {
470 m.group_id = "x".to_string();
471 }
472 if version >= 0 {
473 m.group_state = "x".to_string();
474 }
475 if version >= 0 {
476 m.group_epoch = 1i32;
477 }
478 if version >= 0 {
479 m.assignment_epoch = 1i32;
480 }
481 if version >= 0 {
482 m.assignor_name = "x".to_string();
483 }
484 if version >= 0 {
485 m.members = vec![Member::populated(version)];
486 }
487 if version >= 0 {
488 m.authorized_operations = 1i32;
489 }
490 m
491 }
492}
493#[derive(Debug, Clone, PartialEq, Eq, Default)]
494pub struct Member {
495 pub member_id: String,
496 pub rack_id: Option<String>,
497 pub member_epoch: i32,
498 pub client_id: String,
499 pub client_host: String,
500 pub subscribed_topic_names: Vec<String>,
501 pub assignment: super::common::share_group_describe_response::assignment::Assignment,
502 pub unknown_tagged_fields: UnknownTaggedFields,
503}
504impl Encode for Member {
505 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
506 let flex = version >= 0;
507 if version >= 0 {
508 if flex {
509 let () = put_compact_string(buf, &self.member_id);
510 } else {
511 let () = put_string(buf, &self.member_id);
512 }
513 }
514 if version >= 0 {
515 if flex {
516 let () = put_compact_nullable_string(buf, self.rack_id.as_deref());
517 } else {
518 let () = put_nullable_string(buf, self.rack_id.as_deref());
519 }
520 }
521 if version >= 0 {
522 put_i32(buf, self.member_epoch);
523 }
524 if version >= 0 {
525 if flex {
526 let () = put_compact_string(buf, &self.client_id);
527 } else {
528 let () = put_string(buf, &self.client_id);
529 }
530 }
531 if version >= 0 {
532 if flex {
533 let () = put_compact_string(buf, &self.client_host);
534 } else {
535 let () = put_string(buf, &self.client_host);
536 }
537 }
538 if version >= 0 {
539 {
540 crate::primitives::array::put_array_len(
541 buf,
542 (self.subscribed_topic_names).len(),
543 flex,
544 );
545 for it in &self.subscribed_topic_names {
546 if flex {
547 let () = put_compact_string(buf, it);
548 } else {
549 let () = put_string(buf, it);
550 }
551 }
552 };
553 }
554 if version >= 0 {
555 self.assignment.encode(buf, version)?;
556 }
557 if flex {
558 let tagged = WriteTaggedFields::new();
559 tagged.write(buf, &self.unknown_tagged_fields);
560 }
561 Ok(())
562 }
563 fn encoded_len(&self, version: i16) -> usize {
564 let flex = version >= 0;
565 let mut n: usize = 0;
566 if version >= 0 {
567 n += if flex {
568 compact_string_len(&self.member_id)
569 } else {
570 string_len(&self.member_id)
571 };
572 }
573 if version >= 0 {
574 n += if flex {
575 compact_nullable_string_len(self.rack_id.as_deref())
576 } else {
577 nullable_string_len(self.rack_id.as_deref())
578 };
579 }
580 if version >= 0 {
581 n += 4;
582 }
583 if version >= 0 {
584 n += if flex {
585 compact_string_len(&self.client_id)
586 } else {
587 string_len(&self.client_id)
588 };
589 }
590 if version >= 0 {
591 n += if flex {
592 compact_string_len(&self.client_host)
593 } else {
594 string_len(&self.client_host)
595 };
596 }
597 if version >= 0 {
598 n += {
599 let prefix = crate::primitives::array::array_len_prefix_len(
600 (self.subscribed_topic_names).len(),
601 flex,
602 );
603 let body: usize = (self.subscribed_topic_names)
604 .iter()
605 .map(|it| {
606 if flex {
607 compact_string_len(it)
608 } else {
609 string_len(it)
610 }
611 })
612 .sum();
613 prefix + body
614 };
615 }
616 if version >= 0 {
617 n += self.assignment.encoded_len(version);
618 }
619 if flex {
620 let known_pairs: Vec<(u32, usize)> = Vec::new();
621 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
622 }
623 n
624 }
625}
626impl Decode<'_> for Member {
627 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
628 let flex = version >= 0;
629 let mut out = Self::default();
630 if version >= 0 {
631 out.member_id = if flex {
632 get_compact_string_owned(buf)?
633 } else {
634 get_string_owned(buf)?
635 };
636 }
637 if version >= 0 {
638 out.rack_id = if flex {
639 get_compact_nullable_string_owned(buf)?
640 } else {
641 get_nullable_string_owned(buf)?
642 };
643 }
644 if version >= 0 {
645 out.member_epoch = get_i32(buf)?;
646 }
647 if version >= 0 {
648 out.client_id = if flex {
649 get_compact_string_owned(buf)?
650 } else {
651 get_string_owned(buf)?
652 };
653 }
654 if version >= 0 {
655 out.client_host = if flex {
656 get_compact_string_owned(buf)?
657 } else {
658 get_string_owned(buf)?
659 };
660 }
661 if version >= 0 {
662 out.subscribed_topic_names = {
663 let n = crate::primitives::array::get_array_len(buf, flex)?;
664 let mut v = Vec::with_capacity(n);
665 for _ in 0..n {
666 v.push(if flex {
667 get_compact_string_owned(buf)?
668 } else {
669 get_string_owned(buf)?
670 });
671 }
672 v
673 };
674 }
675 if version >= 0 {
676 out.assignment =
677 super::common::share_group_describe_response::assignment::Assignment::decode(
678 buf, version,
679 )?;
680 }
681 if flex {
682 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
683 }
684 Ok(out)
685 }
686}
687#[cfg(test)]
688impl Member {
689 #[must_use]
690 pub fn populated(version: i16) -> Self {
691 let mut m = Self::default();
692 if version >= 0 {
693 m.member_id = "x".to_string();
694 }
695 if version >= 0 {
696 m.rack_id = Some("x".to_string());
697 }
698 if version >= 0 {
699 m.member_epoch = 1i32;
700 }
701 if version >= 0 {
702 m.client_id = "x".to_string();
703 }
704 if version >= 0 {
705 m.client_host = "x".to_string();
706 }
707 if version >= 0 {
708 m.subscribed_topic_names = vec!["x".to_string()];
709 }
710 if version >= 0 {
711 m.assignment =
712 super::common::share_group_describe_response::assignment::Assignment::populated(
713 version,
714 );
715 }
716 m
717 }
718}
719#[must_use]
722#[allow(unused_comparisons)]
723pub fn default_json(_version: i16) -> ::serde_json::Value {
724 let mut obj = ::serde_json::Map::new();
725 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
726 obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
727 ::serde_json::Value::Object(obj)
728}