1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_bool, get_i16, get_i32, get_i64, put_bool, put_i16, put_i32, put_i64},
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 = 88;
19pub const MIN_VERSION: i16 = 0;
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)]
28pub struct StreamsGroupHeartbeatResponse {
29 pub throttle_time_ms: i32,
30 pub error_code: i16,
31 pub error_message: Option<String>,
32 pub member_id: String,
33 pub member_epoch: i32,
34 pub heartbeat_interval_ms: i32,
35 pub acceptable_recovery_lag_legacy: i32,
36 pub task_offset_interval_ms: i32,
37 pub acceptable_recovery_lag: i64,
38 pub status: Option<Vec<super::common::streams_group_heartbeat_response::status::Status>>,
39 pub active_tasks:
40 Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds>>,
41 pub standby_tasks:
42 Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds>>,
43 pub warmup_tasks:
44 Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds>>,
45 pub topology_description_required: bool,
46 pub endpoint_information_epoch: i32,
47 pub partitions_by_user_endpoint: Option<Vec<EndpointToPartitions>>,
48 pub unknown_tagged_fields: UnknownTaggedFields,
49}
50impl Default for StreamsGroupHeartbeatResponse {
51 fn default() -> Self {
52 Self {
53 throttle_time_ms: 0i32,
54 error_code: 0i16,
55 error_message: None,
56 member_id: String::new(),
57 member_epoch: 0i32,
58 heartbeat_interval_ms: 0i32,
59 acceptable_recovery_lag_legacy: 0i32,
60 task_offset_interval_ms: 0i32,
61 acceptable_recovery_lag: -1i64,
62 status: Some(Vec::new()),
63 active_tasks: None,
64 standby_tasks: None,
65 warmup_tasks: None,
66 topology_description_required: false,
67 endpoint_information_epoch: 0i32,
68 partitions_by_user_endpoint: None,
69 unknown_tagged_fields: UnknownTaggedFields::default(),
70 }
71 }
72}
73impl StreamsGroupHeartbeatResponse {
74 fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
75 if version >= 0 {
76 put_i32(buf, self.throttle_time_ms);
77 }
78 }
79 fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
80 if version >= 0 {
81 put_i16(buf, self.error_code);
82 }
83 }
84 fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
85 if version >= 0 {
86 if flex {
87 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
88 } else {
89 let () = put_nullable_string(buf, self.error_message.as_deref());
90 }
91 }
92 }
93 fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
94 if version >= 0 {
95 if flex {
96 let () = put_compact_string(buf, &self.member_id);
97 } else {
98 let () = put_string(buf, &self.member_id);
99 }
100 }
101 }
102 fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
103 if version >= 0 {
104 put_i32(buf, self.member_epoch);
105 }
106 }
107 fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
108 if version >= 0 {
109 put_i32(buf, self.heartbeat_interval_ms);
110 }
111 }
112 fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
113 if version == 0 {
114 put_i32(buf, self.acceptable_recovery_lag_legacy);
115 }
116 }
117 fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
118 if version >= 0 {
119 put_i32(buf, self.task_offset_interval_ms);
120 }
121 }
122 fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
123 if version >= 1 {
124 put_i64(buf, self.acceptable_recovery_lag);
125 }
126 }
127 fn encode_field_9<B: BufMut>(
128 &self,
129 buf: &mut B,
130 version: i16,
131 flex: bool,
132 ) -> Result<(), ProtocolError> {
133 if version >= 0 {
134 {
135 let len = (self.status).as_ref().map(Vec::len);
136 crate::primitives::array::put_nullable_array_len(buf, len, flex);
137 if let Some(v) = &self.status {
138 for it in v {
139 it.encode(buf, version)?;
140 }
141 }
142 };
143 }
144 Ok(())
145 }
146 fn encode_field_10<B: BufMut>(
147 &self,
148 buf: &mut B,
149 version: i16,
150 flex: bool,
151 ) -> Result<(), ProtocolError> {
152 if version >= 0 {
153 {
154 let len = (self.active_tasks).as_ref().map(Vec::len);
155 crate::primitives::array::put_nullable_array_len(buf, len, flex);
156 if let Some(v) = &self.active_tasks {
157 for it in v {
158 it.encode(buf, version)?;
159 }
160 }
161 };
162 }
163 Ok(())
164 }
165 fn encode_field_11<B: BufMut>(
166 &self,
167 buf: &mut B,
168 version: i16,
169 flex: bool,
170 ) -> Result<(), ProtocolError> {
171 if version >= 0 {
172 {
173 let len = (self.standby_tasks).as_ref().map(Vec::len);
174 crate::primitives::array::put_nullable_array_len(buf, len, flex);
175 if let Some(v) = &self.standby_tasks {
176 for it in v {
177 it.encode(buf, version)?;
178 }
179 }
180 };
181 }
182 Ok(())
183 }
184 fn encode_field_12<B: BufMut>(
185 &self,
186 buf: &mut B,
187 version: i16,
188 flex: bool,
189 ) -> Result<(), ProtocolError> {
190 if version >= 0 {
191 {
192 let len = (self.warmup_tasks).as_ref().map(Vec::len);
193 crate::primitives::array::put_nullable_array_len(buf, len, flex);
194 if let Some(v) = &self.warmup_tasks {
195 for it in v {
196 it.encode(buf, version)?;
197 }
198 }
199 };
200 }
201 Ok(())
202 }
203 fn encode_field_13<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
204 if version >= 1 {
205 put_bool(buf, self.topology_description_required);
206 }
207 }
208 fn encode_field_14<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
209 if version >= 0 {
210 put_i32(buf, self.endpoint_information_epoch);
211 }
212 }
213 fn encode_field_15<B: BufMut>(
214 &self,
215 buf: &mut B,
216 version: i16,
217 flex: bool,
218 ) -> Result<(), ProtocolError> {
219 if version >= 0 {
220 {
221 let len = (self.partitions_by_user_endpoint).as_ref().map(Vec::len);
222 crate::primitives::array::put_nullable_array_len(buf, len, flex);
223 if let Some(v) = &self.partitions_by_user_endpoint {
224 for it in v {
225 it.encode(buf, version)?;
226 }
227 }
228 };
229 }
230 Ok(())
231 }
232 fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
233 if flex {
234 let tagged = WriteTaggedFields::new();
235 tagged.write(buf, &self.unknown_tagged_fields);
236 }
237 }
238 fn decode_field_0<B: Buf>(
239 out: &mut Self,
240 buf: &mut B,
241 version: i16,
242 _flex: bool,
243 ) -> Result<(), ProtocolError> {
244 if version >= 0 {
245 out.throttle_time_ms = get_i32(buf)?;
246 }
247 Ok(())
248 }
249 fn decode_field_1<B: Buf>(
250 out: &mut Self,
251 buf: &mut B,
252 version: i16,
253 _flex: bool,
254 ) -> Result<(), ProtocolError> {
255 if version >= 0 {
256 out.error_code = get_i16(buf)?;
257 }
258 Ok(())
259 }
260 fn decode_field_2<B: Buf>(
261 out: &mut Self,
262 buf: &mut B,
263 version: i16,
264 flex: bool,
265 ) -> Result<(), ProtocolError> {
266 if version >= 0 {
267 out.error_message = if flex {
268 get_compact_nullable_string_owned(buf)?
269 } else {
270 get_nullable_string_owned(buf)?
271 };
272 }
273 Ok(())
274 }
275 fn decode_field_3<B: Buf>(
276 out: &mut Self,
277 buf: &mut B,
278 version: i16,
279 flex: bool,
280 ) -> Result<(), ProtocolError> {
281 if version >= 0 {
282 out.member_id = if flex {
283 get_compact_string_owned(buf)?
284 } else {
285 get_string_owned(buf)?
286 };
287 }
288 Ok(())
289 }
290 fn decode_field_4<B: Buf>(
291 out: &mut Self,
292 buf: &mut B,
293 version: i16,
294 _flex: bool,
295 ) -> Result<(), ProtocolError> {
296 if version >= 0 {
297 out.member_epoch = get_i32(buf)?;
298 }
299 Ok(())
300 }
301 fn decode_field_5<B: Buf>(
302 out: &mut Self,
303 buf: &mut B,
304 version: i16,
305 _flex: bool,
306 ) -> Result<(), ProtocolError> {
307 if version >= 0 {
308 out.heartbeat_interval_ms = get_i32(buf)?;
309 }
310 Ok(())
311 }
312 fn decode_field_6<B: Buf>(
313 out: &mut Self,
314 buf: &mut B,
315 version: i16,
316 _flex: bool,
317 ) -> Result<(), ProtocolError> {
318 if version == 0 {
319 out.acceptable_recovery_lag_legacy = get_i32(buf)?;
320 }
321 Ok(())
322 }
323 fn decode_field_7<B: Buf>(
324 out: &mut Self,
325 buf: &mut B,
326 version: i16,
327 _flex: bool,
328 ) -> Result<(), ProtocolError> {
329 if version >= 0 {
330 out.task_offset_interval_ms = get_i32(buf)?;
331 }
332 Ok(())
333 }
334 fn decode_field_8<B: Buf>(
335 out: &mut Self,
336 buf: &mut B,
337 version: i16,
338 _flex: bool,
339 ) -> Result<(), ProtocolError> {
340 if version >= 1 {
341 out.acceptable_recovery_lag = get_i64(buf)?;
342 }
343 Ok(())
344 }
345 fn decode_field_9<B: Buf>(
346 out: &mut Self,
347 buf: &mut B,
348 version: i16,
349 flex: bool,
350 ) -> Result<(), ProtocolError> {
351 if version >= 0 {
352 out.status = {
353 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
354 match opt {
355 None => None,
356 Some(n) => {
357 let mut v = Vec::with_capacity(n);
358 for _ in 0..n {
359 v.push(super::common::streams_group_heartbeat_response::status::Status::decode(buf, version)?);
360 }
361 Some(v)
362 }
363 }
364 };
365 }
366 Ok(())
367 }
368 fn decode_field_10<B: Buf>(
369 out: &mut Self,
370 buf: &mut B,
371 version: i16,
372 flex: bool,
373 ) -> Result<(), ProtocolError> {
374 if version >= 0 {
375 out.active_tasks = {
376 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
377 match opt {
378 None => None,
379 Some(n) => {
380 let mut v = Vec::with_capacity(n);
381 for _ in 0..n {
382 v.push(super::common::streams_group_heartbeat_response::task_ids::TaskIds::decode(buf, version)?);
383 }
384 Some(v)
385 }
386 }
387 };
388 }
389 Ok(())
390 }
391 fn decode_field_11<B: Buf>(
392 out: &mut Self,
393 buf: &mut B,
394 version: i16,
395 flex: bool,
396 ) -> Result<(), ProtocolError> {
397 if version >= 0 {
398 out.standby_tasks = {
399 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
400 match opt {
401 None => None,
402 Some(n) => {
403 let mut v = Vec::with_capacity(n);
404 for _ in 0..n {
405 v.push(super::common::streams_group_heartbeat_response::task_ids::TaskIds::decode(buf, version)?);
406 }
407 Some(v)
408 }
409 }
410 };
411 }
412 Ok(())
413 }
414 fn decode_field_12<B: Buf>(
415 out: &mut Self,
416 buf: &mut B,
417 version: i16,
418 flex: bool,
419 ) -> Result<(), ProtocolError> {
420 if version >= 0 {
421 out.warmup_tasks = {
422 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
423 match opt {
424 None => None,
425 Some(n) => {
426 let mut v = Vec::with_capacity(n);
427 for _ in 0..n {
428 v.push(super::common::streams_group_heartbeat_response::task_ids::TaskIds::decode(buf, version)?);
429 }
430 Some(v)
431 }
432 }
433 };
434 }
435 Ok(())
436 }
437 fn decode_field_13<B: Buf>(
438 out: &mut Self,
439 buf: &mut B,
440 version: i16,
441 _flex: bool,
442 ) -> Result<(), ProtocolError> {
443 if version >= 1 {
444 out.topology_description_required = get_bool(buf)?;
445 }
446 Ok(())
447 }
448 fn decode_field_14<B: Buf>(
449 out: &mut Self,
450 buf: &mut B,
451 version: i16,
452 _flex: bool,
453 ) -> Result<(), ProtocolError> {
454 if version >= 0 {
455 out.endpoint_information_epoch = get_i32(buf)?;
456 }
457 Ok(())
458 }
459 fn decode_field_15<B: Buf>(
460 out: &mut Self,
461 buf: &mut B,
462 version: i16,
463 flex: bool,
464 ) -> Result<(), ProtocolError> {
465 if version >= 0 {
466 out.partitions_by_user_endpoint = {
467 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
468 match opt {
469 None => None,
470 Some(n) => {
471 let mut v = Vec::with_capacity(n);
472 for _ in 0..n {
473 v.push(EndpointToPartitions::decode(buf, version)?);
474 }
475 Some(v)
476 }
477 }
478 };
479 }
480 Ok(())
481 }
482 fn decode_tagged_fields<B: Buf>(
483 out: &mut Self,
484 buf: &mut B,
485 _version: i16,
486 flex: bool,
487 ) -> Result<(), ProtocolError> {
488 if flex {
489 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
490 }
491 Ok(())
492 }
493}
494impl Encode for StreamsGroupHeartbeatResponse {
495 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
496 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
497 return Err(ProtocolError::UnsupportedVersion {
498 api_key: API_KEY,
499 version,
500 });
501 }
502 let flex = is_flexible(version);
503 self.encode_field_0(buf, version, flex);
504 self.encode_field_1(buf, version, flex);
505 self.encode_field_2(buf, version, flex);
506 self.encode_field_3(buf, version, flex);
507 self.encode_field_4(buf, version, flex);
508 self.encode_field_5(buf, version, flex);
509 self.encode_field_6(buf, version, flex);
510 self.encode_field_7(buf, version, flex);
511 self.encode_field_8(buf, version, flex);
512 self.encode_field_9(buf, version, flex)?;
513 self.encode_field_10(buf, version, flex)?;
514 self.encode_field_11(buf, version, flex)?;
515 self.encode_field_12(buf, version, flex)?;
516 self.encode_field_13(buf, version, flex);
517 self.encode_field_14(buf, version, flex);
518 self.encode_field_15(buf, version, flex)?;
519 self.encode_tagged_fields(buf, version, flex);
520 Ok(())
521 }
522 fn encoded_len(&self, version: i16) -> usize {
523 let flex = is_flexible(version);
524 let mut n: usize = 0;
525 if version >= 0 {
526 n += 4;
527 }
528 if version >= 0 {
529 n += 2;
530 }
531 if version >= 0 {
532 n += if flex {
533 compact_nullable_string_len(self.error_message.as_deref())
534 } else {
535 nullable_string_len(self.error_message.as_deref())
536 };
537 }
538 if version >= 0 {
539 n += if flex {
540 compact_string_len(&self.member_id)
541 } else {
542 string_len(&self.member_id)
543 };
544 }
545 if version >= 0 {
546 n += 4;
547 }
548 if version >= 0 {
549 n += 4;
550 }
551 if version == 0 {
552 n += 4;
553 }
554 if version >= 0 {
555 n += 4;
556 }
557 if version >= 1 {
558 n += 8;
559 }
560 if version >= 0 {
561 n += {
562 let opt: Option<&Vec<_>> = (self.status).as_ref();
563 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
564 opt.map(std::vec::Vec::len),
565 flex,
566 );
567 let body: usize =
568 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
569 prefix + body
570 };
571 }
572 if version >= 0 {
573 n += {
574 let opt: Option<&Vec<_>> = (self.active_tasks).as_ref();
575 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
576 opt.map(std::vec::Vec::len),
577 flex,
578 );
579 let body: usize =
580 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
581 prefix + body
582 };
583 }
584 if version >= 0 {
585 n += {
586 let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref();
587 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
588 opt.map(std::vec::Vec::len),
589 flex,
590 );
591 let body: usize =
592 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
593 prefix + body
594 };
595 }
596 if version >= 0 {
597 n += {
598 let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref();
599 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
600 opt.map(std::vec::Vec::len),
601 flex,
602 );
603 let body: usize =
604 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
605 prefix + body
606 };
607 }
608 if version >= 1 {
609 n += 1;
610 }
611 if version >= 0 {
612 n += 4;
613 }
614 if version >= 0 {
615 n += {
616 let opt: Option<&Vec<_>> = (self.partitions_by_user_endpoint).as_ref();
617 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
618 opt.map(std::vec::Vec::len),
619 flex,
620 );
621 let body: usize =
622 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
623 prefix + body
624 };
625 }
626 if flex {
627 let known_pairs: Vec<(u32, usize)> = Vec::new();
628 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
629 }
630 n
631 }
632}
633impl Decode<'_> for StreamsGroupHeartbeatResponse {
634 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
635 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
636 return Err(ProtocolError::UnsupportedVersion {
637 api_key: API_KEY,
638 version,
639 });
640 }
641 let flex = is_flexible(version);
642 let mut out = Self::default();
643 Self::decode_field_0(&mut out, buf, version, flex)?;
644 Self::decode_field_1(&mut out, buf, version, flex)?;
645 Self::decode_field_2(&mut out, buf, version, flex)?;
646 Self::decode_field_3(&mut out, buf, version, flex)?;
647 Self::decode_field_4(&mut out, buf, version, flex)?;
648 Self::decode_field_5(&mut out, buf, version, flex)?;
649 Self::decode_field_6(&mut out, buf, version, flex)?;
650 Self::decode_field_7(&mut out, buf, version, flex)?;
651 Self::decode_field_8(&mut out, buf, version, flex)?;
652 Self::decode_field_9(&mut out, buf, version, flex)?;
653 Self::decode_field_10(&mut out, buf, version, flex)?;
654 Self::decode_field_11(&mut out, buf, version, flex)?;
655 Self::decode_field_12(&mut out, buf, version, flex)?;
656 Self::decode_field_13(&mut out, buf, version, flex)?;
657 Self::decode_field_14(&mut out, buf, version, flex)?;
658 Self::decode_field_15(&mut out, buf, version, flex)?;
659 Self::decode_tagged_fields(&mut out, buf, version, flex)?;
660 Ok(out)
661 }
662}
663#[cfg(test)]
664impl StreamsGroupHeartbeatResponse {
665 #[must_use]
666 pub fn populated(version: i16) -> Self {
667 let mut m = Self::default();
668 if version >= 0 {
669 m.throttle_time_ms = 1i32;
670 }
671 if version >= 0 {
672 m.error_code = 1i16;
673 }
674 if version >= 0 {
675 m.error_message = Some("x".to_string());
676 }
677 if version >= 0 {
678 m.member_id = "x".to_string();
679 }
680 if version >= 0 {
681 m.member_epoch = 1i32;
682 }
683 if version >= 0 {
684 m.heartbeat_interval_ms = 1i32;
685 }
686 if version == 0 {
687 m.acceptable_recovery_lag_legacy = 1i32;
688 }
689 if version >= 0 {
690 m.task_offset_interval_ms = 1i32;
691 }
692 if version >= 1 {
693 m.acceptable_recovery_lag = 1i64;
694 }
695 if version >= 0 {
696 m.status = Some(vec![
697 super::common::streams_group_heartbeat_response::status::Status::populated(version),
698 ]);
699 }
700 if version >= 0 {
701 m.active_tasks = Some(vec![
702 super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
703 version,
704 ),
705 ]);
706 }
707 if version >= 0 {
708 m.standby_tasks = Some(vec![
709 super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
710 version,
711 ),
712 ]);
713 }
714 if version >= 0 {
715 m.warmup_tasks = Some(vec![
716 super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
717 version,
718 ),
719 ]);
720 }
721 if version >= 1 {
722 m.topology_description_required = true;
723 }
724 if version >= 0 {
725 m.endpoint_information_epoch = 1i32;
726 }
727 if version >= 0 {
728 m.partitions_by_user_endpoint = Some(vec![EndpointToPartitions::populated(version)]);
729 }
730 m
731 }
732}
733#[derive(Debug, Clone, PartialEq, Eq, Default)]
734pub struct EndpointToPartitions {
735 pub user_endpoint: super::common::streams_group_heartbeat_response::endpoint::Endpoint,
736 pub active_partitions:
737 Vec<super::common::streams_group_heartbeat_response::topic_partition::TopicPartition>,
738 pub standby_partitions:
739 Vec<super::common::streams_group_heartbeat_response::topic_partition::TopicPartition>,
740 pub unknown_tagged_fields: UnknownTaggedFields,
741}
742impl Encode for EndpointToPartitions {
743 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
744 let flex = version >= 0;
745 if version >= 0 {
746 self.user_endpoint.encode(buf, version)?;
747 }
748 if version >= 0 {
749 {
750 crate::primitives::array::put_array_len(buf, (self.active_partitions).len(), flex);
751 for it in &self.active_partitions {
752 it.encode(buf, version)?;
753 }
754 };
755 }
756 if version >= 0 {
757 {
758 crate::primitives::array::put_array_len(buf, (self.standby_partitions).len(), flex);
759 for it in &self.standby_partitions {
760 it.encode(buf, version)?;
761 }
762 };
763 }
764 if flex {
765 let tagged = WriteTaggedFields::new();
766 tagged.write(buf, &self.unknown_tagged_fields);
767 }
768 Ok(())
769 }
770 fn encoded_len(&self, version: i16) -> usize {
771 let flex = version >= 0;
772 let mut n: usize = 0;
773 if version >= 0 {
774 n += self.user_endpoint.encoded_len(version);
775 }
776 if version >= 0 {
777 n += {
778 let prefix = crate::primitives::array::array_len_prefix_len(
779 (self.active_partitions).len(),
780 flex,
781 );
782 let body: usize = (self.active_partitions)
783 .iter()
784 .map(|it| it.encoded_len(version))
785 .sum();
786 prefix + body
787 };
788 }
789 if version >= 0 {
790 n += {
791 let prefix = crate::primitives::array::array_len_prefix_len(
792 (self.standby_partitions).len(),
793 flex,
794 );
795 let body: usize = (self.standby_partitions)
796 .iter()
797 .map(|it| it.encoded_len(version))
798 .sum();
799 prefix + body
800 };
801 }
802 if flex {
803 let known_pairs: Vec<(u32, usize)> = Vec::new();
804 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
805 }
806 n
807 }
808}
809impl Decode<'_> for EndpointToPartitions {
810 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
811 let flex = version >= 0;
812 let mut out = Self::default();
813 if version >= 0 {
814 out.user_endpoint =
815 super::common::streams_group_heartbeat_response::endpoint::Endpoint::decode(
816 buf, version,
817 )?;
818 }
819 if version >= 0 {
820 out.active_partitions = {
821 let n = crate::primitives::array::get_array_len(buf, flex)?;
822 let mut v = Vec::with_capacity(n);
823 for _ in 0..n {
824 v.push(super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::decode(buf, version)?);
825 }
826 v
827 };
828 }
829 if version >= 0 {
830 out.standby_partitions = {
831 let n = crate::primitives::array::get_array_len(buf, flex)?;
832 let mut v = Vec::with_capacity(n);
833 for _ in 0..n {
834 v.push(super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::decode(buf, version)?);
835 }
836 v
837 };
838 }
839 if flex {
840 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
841 }
842 Ok(out)
843 }
844}
845#[cfg(test)]
846impl EndpointToPartitions {
847 #[must_use]
848 pub fn populated(version: i16) -> Self {
849 let mut m = Self::default();
850 if version >= 0 {
851 m.user_endpoint =
852 super::common::streams_group_heartbeat_response::endpoint::Endpoint::populated(
853 version,
854 );
855 }
856 if version >= 0 {
857 m.active_partitions = vec![super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::populated(version)];
858 }
859 if version >= 0 {
860 m.standby_partitions = vec![super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::populated(version)];
861 }
862 m
863 }
864}
865#[must_use]
868#[allow(unused_comparisons)]
869pub fn default_json(version: i16) -> ::serde_json::Value {
870 let mut obj = ::serde_json::Map::new();
871 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
872 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
873 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
874 obj.insert(
875 "memberId".to_string(),
876 ::serde_json::Value::String(String::new()),
877 );
878 obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
879 obj.insert("heartbeatIntervalMs".to_string(), ::serde_json::json!(0));
880 if version <= 0 {
881 obj.insert(
882 "acceptableRecoveryLagLegacy".to_string(),
883 ::serde_json::json!(0),
884 );
885 }
886 obj.insert("taskOffsetIntervalMs".to_string(), ::serde_json::json!(0));
887 if version >= 1 {
888 obj.insert("acceptableRecoveryLag".to_string(), ::serde_json::json!(-1));
889 }
890 obj.insert("status".to_string(), ::serde_json::Value::Array(vec![]));
891 obj.insert("activeTasks".to_string(), ::serde_json::Value::Null);
892 obj.insert("standbyTasks".to_string(), ::serde_json::Value::Null);
893 obj.insert("warmupTasks".to_string(), ::serde_json::Value::Null);
894 if version >= 1 {
895 obj.insert(
896 "topologyDescriptionRequired".to_string(),
897 ::serde_json::Value::Bool(false),
898 );
899 }
900 obj.insert(
901 "endpointInformationEpoch".to_string(),
902 ::serde_json::json!(0),
903 );
904 obj.insert(
905 "partitionsByUserEndpoint".to_string(),
906 ::serde_json::Value::Null,
907 );
908 ::serde_json::Value::Object(obj)
909}