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