1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, 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 = 88;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
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)]
28pub struct StreamsGroupHeartbeatRequest<'a> {
29 pub group_id: &'a str,
30 pub member_id: &'a str,
31 pub member_epoch: i32,
32 pub endpoint_information_epoch: i32,
33 pub instance_id: Option<&'a str>,
34 pub rack_id: Option<&'a str>,
35 pub rebalance_timeout_ms: i32,
36 pub topology: Option<Topology<'a>>,
37 pub active_tasks:
38 Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds<'a>>>,
39 pub standby_tasks:
40 Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds<'a>>>,
41 pub warmup_tasks:
42 Option<Vec<super::common::streams_group_heartbeat_request::task_ids::TaskIds<'a>>>,
43 pub process_id: Option<&'a str>,
44 pub user_endpoint:
45 Option<super::common::streams_group_heartbeat_request::endpoint::Endpoint<'a>>,
46 pub client_tags:
47 Option<Vec<super::common::streams_group_heartbeat_request::key_value::KeyValue<'a>>>,
48 pub task_offsets:
49 Option<Vec<super::common::streams_group_heartbeat_request::task_offset::TaskOffset<'a>>>,
50 pub task_end_offsets:
51 Option<Vec<super::common::streams_group_heartbeat_request::task_offset::TaskOffset<'a>>>,
52 pub shutdown_application: bool,
53 pub unknown_tagged_fields: UnknownTaggedFields,
54}
55impl Default for StreamsGroupHeartbeatRequest<'_> {
56 fn default() -> Self {
57 Self {
58 group_id: "",
59 member_id: "",
60 member_epoch: 0i32,
61 endpoint_information_epoch: 0i32,
62 instance_id: None,
63 rack_id: None,
64 rebalance_timeout_ms: -1i32,
65 topology: None,
66 active_tasks: None,
67 standby_tasks: None,
68 warmup_tasks: None,
69 process_id: None,
70 user_endpoint: None,
71 client_tags: None,
72 task_offsets: None,
73 task_end_offsets: None,
74 shutdown_application: false,
75 unknown_tagged_fields: Default::default(),
76 }
77 }
78}
79impl StreamsGroupHeartbeatRequest<'_> {
80 pub fn to_owned(
81 &self,
82 ) -> crate::owned::streams_group_heartbeat_request::StreamsGroupHeartbeatRequest {
83 crate::owned::streams_group_heartbeat_request::StreamsGroupHeartbeatRequest {
84 group_id: (self.group_id).to_string(),
85 member_id: (self.member_id).to_string(),
86 member_epoch: (self.member_epoch),
87 endpoint_information_epoch: (self.endpoint_information_epoch),
88 instance_id: (self.instance_id).map(std::string::ToString::to_string),
89 rack_id: (self.rack_id).map(std::string::ToString::to_string),
90 rebalance_timeout_ms: (self.rebalance_timeout_ms),
91 topology: (self.topology).as_ref().map(Topology::to_owned),
92 active_tasks: (self.active_tasks)
93 .as_ref()
94 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::task_ids::TaskIds::to_owned).collect()),
95 standby_tasks: (self.standby_tasks)
96 .as_ref()
97 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::task_ids::TaskIds::to_owned).collect()),
98 warmup_tasks: (self.warmup_tasks)
99 .as_ref()
100 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::task_ids::TaskIds::to_owned).collect()),
101 process_id: (self.process_id).map(std::string::ToString::to_string),
102 user_endpoint: (self.user_endpoint).as_ref().map(super::common::streams_group_heartbeat_request::endpoint::Endpoint::to_owned),
103 client_tags: (self.client_tags)
104 .as_ref()
105 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::key_value::KeyValue::to_owned).collect()),
106 task_offsets: (self.task_offsets)
107 .as_ref()
108 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::task_offset::TaskOffset::to_owned).collect()),
109 task_end_offsets: (self.task_end_offsets)
110 .as_ref()
111 .map(|v| v.iter().map(super::common::streams_group_heartbeat_request::task_offset::TaskOffset::to_owned).collect()),
112 shutdown_application: (self.shutdown_application),
113 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
114 }
115 }
116}
117impl Encode for StreamsGroupHeartbeatRequest<'_> {
118 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
119 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
120 return Err(ProtocolError::UnsupportedVersion {
121 api_key: API_KEY,
122 version,
123 });
124 }
125 let flex = is_flexible(version);
126 if version >= 0 {
127 if flex {
128 put_compact_string(buf, self.group_id);
129 } else {
130 put_string(buf, self.group_id);
131 }
132 }
133 if version >= 0 {
134 if flex {
135 put_compact_string(buf, self.member_id);
136 } else {
137 put_string(buf, self.member_id);
138 }
139 }
140 if version >= 0 {
141 put_i32(buf, self.member_epoch);
142 }
143 if version >= 0 {
144 put_i32(buf, self.endpoint_information_epoch);
145 }
146 if version >= 0 {
147 if flex {
148 put_compact_nullable_string(buf, self.instance_id);
149 } else {
150 put_nullable_string(buf, self.instance_id);
151 }
152 }
153 if version >= 0 {
154 if flex {
155 put_compact_nullable_string(buf, self.rack_id);
156 } else {
157 put_nullable_string(buf, self.rack_id);
158 }
159 }
160 if version >= 0 {
161 put_i32(buf, self.rebalance_timeout_ms);
162 }
163 if version >= 0 {
164 match &self.topology {
165 None => {
166 buf.put_i8(-1);
167 }
168 Some(v) => {
169 buf.put_i8(1);
170 v.encode(buf, version)?;
171 }
172 }
173 }
174 if version >= 0 {
175 {
176 let len = (self.active_tasks).as_ref().map(Vec::len);
177 crate::primitives::array::put_nullable_array_len(buf, len, flex);
178 if let Some(v) = &self.active_tasks {
179 for it in v {
180 it.encode(buf, version)?;
181 }
182 }
183 }
184 }
185 if version >= 0 {
186 {
187 let len = (self.standby_tasks).as_ref().map(Vec::len);
188 crate::primitives::array::put_nullable_array_len(buf, len, flex);
189 if let Some(v) = &self.standby_tasks {
190 for it in v {
191 it.encode(buf, version)?;
192 }
193 }
194 }
195 }
196 if version >= 0 {
197 {
198 let len = (self.warmup_tasks).as_ref().map(Vec::len);
199 crate::primitives::array::put_nullable_array_len(buf, len, flex);
200 if let Some(v) = &self.warmup_tasks {
201 for it in v {
202 it.encode(buf, version)?;
203 }
204 }
205 }
206 }
207 if version >= 0 {
208 if flex {
209 put_compact_nullable_string(buf, self.process_id);
210 } else {
211 put_nullable_string(buf, self.process_id);
212 }
213 }
214 if version >= 0 {
215 match &self.user_endpoint {
216 None => {
217 buf.put_i8(-1);
218 }
219 Some(v) => {
220 buf.put_i8(1);
221 v.encode(buf, version)?;
222 }
223 }
224 }
225 if version >= 0 {
226 {
227 let len = (self.client_tags).as_ref().map(Vec::len);
228 crate::primitives::array::put_nullable_array_len(buf, len, flex);
229 if let Some(v) = &self.client_tags {
230 for it in v {
231 it.encode(buf, version)?;
232 }
233 }
234 }
235 }
236 if version >= 0 {
237 {
238 let len = (self.task_offsets).as_ref().map(Vec::len);
239 crate::primitives::array::put_nullable_array_len(buf, len, flex);
240 if let Some(v) = &self.task_offsets {
241 for it in v {
242 it.encode(buf, version)?;
243 }
244 }
245 }
246 }
247 if version >= 0 {
248 {
249 let len = (self.task_end_offsets).as_ref().map(Vec::len);
250 crate::primitives::array::put_nullable_array_len(buf, len, flex);
251 if let Some(v) = &self.task_end_offsets {
252 for it in v {
253 it.encode(buf, version)?;
254 }
255 }
256 }
257 }
258 if version >= 0 {
259 put_bool(buf, self.shutdown_application);
260 }
261 if flex {
262 let tagged = WriteTaggedFields::new();
263 tagged.write(buf, &self.unknown_tagged_fields);
264 }
265 Ok(())
266 }
267 fn encoded_len(&self, version: i16) -> usize {
268 let flex = is_flexible(version);
269 let mut n: usize = 0;
270 if version >= 0 {
271 n += if flex {
272 compact_string_len(self.group_id)
273 } else {
274 string_len(self.group_id)
275 };
276 }
277 if version >= 0 {
278 n += if flex {
279 compact_string_len(self.member_id)
280 } else {
281 string_len(self.member_id)
282 };
283 }
284 if version >= 0 {
285 n += 4;
286 }
287 if version >= 0 {
288 n += 4;
289 }
290 if version >= 0 {
291 n += if flex {
292 compact_nullable_string_len(self.instance_id)
293 } else {
294 nullable_string_len(self.instance_id)
295 };
296 }
297 if version >= 0 {
298 n += if flex {
299 compact_nullable_string_len(self.rack_id)
300 } else {
301 nullable_string_len(self.rack_id)
302 };
303 }
304 if version >= 0 {
305 n += 4;
306 }
307 if version >= 0 {
308 n += 1 + self.topology.as_ref().map_or(0, |v| v.encoded_len(version));
309 }
310 if version >= 0 {
311 n += {
312 let opt: Option<&Vec<_>> = (self.active_tasks).as_ref();
313 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
314 opt.map(std::vec::Vec::len),
315 flex,
316 );
317 let body: usize =
318 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
319 prefix + body
320 };
321 }
322 if version >= 0 {
323 n += {
324 let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref();
325 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
326 opt.map(std::vec::Vec::len),
327 flex,
328 );
329 let body: usize =
330 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
331 prefix + body
332 };
333 }
334 if version >= 0 {
335 n += {
336 let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref();
337 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
338 opt.map(std::vec::Vec::len),
339 flex,
340 );
341 let body: usize =
342 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
343 prefix + body
344 };
345 }
346 if version >= 0 {
347 n += if flex {
348 compact_nullable_string_len(self.process_id)
349 } else {
350 nullable_string_len(self.process_id)
351 };
352 }
353 if version >= 0 {
354 n += 1 + self
355 .user_endpoint
356 .as_ref()
357 .map_or(0, |v| v.encoded_len(version));
358 }
359 if version >= 0 {
360 n += {
361 let opt: Option<&Vec<_>> = (self.client_tags).as_ref();
362 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
363 opt.map(std::vec::Vec::len),
364 flex,
365 );
366 let body: usize =
367 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
368 prefix + body
369 };
370 }
371 if version >= 0 {
372 n += {
373 let opt: Option<&Vec<_>> = (self.task_offsets).as_ref();
374 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
375 opt.map(std::vec::Vec::len),
376 flex,
377 );
378 let body: usize =
379 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
380 prefix + body
381 };
382 }
383 if version >= 0 {
384 n += {
385 let opt: Option<&Vec<_>> = (self.task_end_offsets).as_ref();
386 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
387 opt.map(std::vec::Vec::len),
388 flex,
389 );
390 let body: usize =
391 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
392 prefix + body
393 };
394 }
395 if version >= 0 {
396 n += 1;
397 }
398 if flex {
399 let known_pairs: Vec<(u32, usize)> = Vec::new();
400 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
401 }
402 n
403 }
404}
405impl<'de> DecodeBorrow<'de> for StreamsGroupHeartbeatRequest<'de> {
406 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
407 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
408 return Err(ProtocolError::UnsupportedVersion {
409 api_key: API_KEY,
410 version,
411 });
412 }
413 let flex = is_flexible(version);
414 let mut out = Self::default();
415 if version >= 0 {
416 out.group_id = if flex {
417 get_compact_string_borrowed(buf)?
418 } else {
419 get_string_borrowed(buf)?
420 };
421 }
422 if version >= 0 {
423 out.member_id = if flex {
424 get_compact_string_borrowed(buf)?
425 } else {
426 get_string_borrowed(buf)?
427 };
428 }
429 if version >= 0 {
430 out.member_epoch = get_i32(buf)?;
431 }
432 if version >= 0 {
433 out.endpoint_information_epoch = get_i32(buf)?;
434 }
435 if version >= 0 {
436 out.instance_id = if flex {
437 get_compact_nullable_string_borrowed(buf)?
438 } else {
439 get_nullable_string_borrowed(buf)?
440 };
441 }
442 if version >= 0 {
443 out.rack_id = if flex {
444 get_compact_nullable_string_borrowed(buf)?
445 } else {
446 get_nullable_string_borrowed(buf)?
447 };
448 }
449 if version >= 0 {
450 out.rebalance_timeout_ms = get_i32(buf)?;
451 }
452 if version >= 0 {
453 out.topology = if get_i8(buf)? < 0 {
454 None
455 } else {
456 Some(Topology::decode_borrow(buf, version)?)
457 };
458 }
459 if version >= 0 {
460 out.active_tasks = {
461 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
462 match opt {
463 None => None,
464 Some(n) => {
465 let mut v = Vec::with_capacity(n);
466 for _ in 0..n {
467 v . push (super :: common :: streams_group_heartbeat_request :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
468 }
469 Some(v)
470 }
471 }
472 };
473 }
474 if version >= 0 {
475 out.standby_tasks = {
476 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
477 match opt {
478 None => None,
479 Some(n) => {
480 let mut v = Vec::with_capacity(n);
481 for _ in 0..n {
482 v . push (super :: common :: streams_group_heartbeat_request :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
483 }
484 Some(v)
485 }
486 }
487 };
488 }
489 if version >= 0 {
490 out.warmup_tasks = {
491 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
492 match opt {
493 None => None,
494 Some(n) => {
495 let mut v = Vec::with_capacity(n);
496 for _ in 0..n {
497 v . push (super :: common :: streams_group_heartbeat_request :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
498 }
499 Some(v)
500 }
501 }
502 };
503 }
504 if version >= 0 {
505 out.process_id = if flex {
506 get_compact_nullable_string_borrowed(buf)?
507 } else {
508 get_nullable_string_borrowed(buf)?
509 };
510 }
511 if version >= 0 {
512 out.user_endpoint = if get_i8(buf)? < 0 {
513 None
514 } else {
515 Some (super :: common :: streams_group_heartbeat_request :: endpoint :: Endpoint :: decode_borrow (buf , version) ?)
516 };
517 }
518 if version >= 0 {
519 out.client_tags = {
520 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
521 match opt {
522 None => None,
523 Some(n) => {
524 let mut v = Vec::with_capacity(n);
525 for _ in 0..n {
526 v . push (super :: common :: streams_group_heartbeat_request :: key_value :: KeyValue :: decode_borrow (buf , version) ?) ;
527 }
528 Some(v)
529 }
530 }
531 };
532 }
533 if version >= 0 {
534 out.task_offsets = {
535 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
536 match opt {
537 None => None,
538 Some(n) => {
539 let mut v = Vec::with_capacity(n);
540 for _ in 0..n {
541 v . push (super :: common :: streams_group_heartbeat_request :: task_offset :: TaskOffset :: decode_borrow (buf , version) ?) ;
542 }
543 Some(v)
544 }
545 }
546 };
547 }
548 if version >= 0 {
549 out.task_end_offsets = {
550 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
551 match opt {
552 None => None,
553 Some(n) => {
554 let mut v = Vec::with_capacity(n);
555 for _ in 0..n {
556 v . push (super :: common :: streams_group_heartbeat_request :: task_offset :: TaskOffset :: decode_borrow (buf , version) ?) ;
557 }
558 Some(v)
559 }
560 }
561 };
562 }
563 if version >= 0 {
564 out.shutdown_application = get_bool(buf)?;
565 }
566 if flex {
567 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
568 }
569 Ok(out)
570 }
571}
572#[cfg(test)]
573impl StreamsGroupHeartbeatRequest<'_> {
574 #[must_use]
575 pub fn populated(version: i16) -> Self {
576 let mut m = Self::default();
577 if version >= 0 {
578 m.group_id = "x";
579 }
580 if version >= 0 {
581 m.member_id = "x";
582 }
583 if version >= 0 {
584 m.member_epoch = 1i32;
585 }
586 if version >= 0 {
587 m.endpoint_information_epoch = 1i32;
588 }
589 if version >= 0 {
590 m.instance_id = Some("x");
591 }
592 if version >= 0 {
593 m.rack_id = Some("x");
594 }
595 if version >= 0 {
596 m.rebalance_timeout_ms = 1i32;
597 }
598 if version >= 0 {
599 m.topology = Some(Topology::populated(version));
600 }
601 if version >= 0 {
602 m.active_tasks = Some(vec![
603 super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
604 version,
605 ),
606 ]);
607 }
608 if version >= 0 {
609 m.standby_tasks = Some(vec![
610 super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
611 version,
612 ),
613 ]);
614 }
615 if version >= 0 {
616 m.warmup_tasks = Some(vec![
617 super::common::streams_group_heartbeat_request::task_ids::TaskIds::populated(
618 version,
619 ),
620 ]);
621 }
622 if version >= 0 {
623 m.process_id = Some("x");
624 }
625 if version >= 0 {
626 m.user_endpoint = Some(
627 super::common::streams_group_heartbeat_request::endpoint::Endpoint::populated(
628 version,
629 ),
630 );
631 }
632 if version >= 0 {
633 m.client_tags = Some(vec![
634 super::common::streams_group_heartbeat_request::key_value::KeyValue::populated(
635 version,
636 ),
637 ]);
638 }
639 if version >= 0 {
640 m.task_offsets = Some(vec![
641 super::common::streams_group_heartbeat_request::task_offset::TaskOffset::populated(
642 version,
643 ),
644 ]);
645 }
646 if version >= 0 {
647 m.task_end_offsets = Some(vec![
648 super::common::streams_group_heartbeat_request::task_offset::TaskOffset::populated(
649 version,
650 ),
651 ]);
652 }
653 if version >= 0 {
654 m.shutdown_application = true;
655 }
656 m
657 }
658}
659#[derive(Debug, Clone, PartialEq, Eq, Default)]
660pub struct Topology<'a> {
661 pub epoch: i32,
662 pub subtopologies: Vec<Subtopology<'a>>,
663 pub unknown_tagged_fields: UnknownTaggedFields,
664}
665impl Topology<'_> {
666 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::Topology {
667 crate::owned::streams_group_heartbeat_request::Topology {
668 epoch: (self.epoch),
669 subtopologies: (self.subtopologies)
670 .iter()
671 .map(Subtopology::to_owned)
672 .collect(),
673 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
674 }
675 }
676}
677impl Encode for Topology<'_> {
678 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
679 let flex = version >= 0;
680 if version >= 0 {
681 put_i32(buf, self.epoch);
682 }
683 if version >= 0 {
684 {
685 crate::primitives::array::put_array_len(buf, (self.subtopologies).len(), flex);
686 for it in &self.subtopologies {
687 it.encode(buf, version)?;
688 }
689 }
690 }
691 if flex {
692 let tagged = WriteTaggedFields::new();
693 tagged.write(buf, &self.unknown_tagged_fields);
694 }
695 Ok(())
696 }
697 fn encoded_len(&self, version: i16) -> usize {
698 let flex = version >= 0;
699 let mut n: usize = 0;
700 if version >= 0 {
701 n += 4;
702 }
703 if version >= 0 {
704 n += {
705 let prefix = crate::primitives::array::array_len_prefix_len(
706 (self.subtopologies).len(),
707 flex,
708 );
709 let body: usize = (self.subtopologies)
710 .iter()
711 .map(|it| it.encoded_len(version))
712 .sum();
713 prefix + body
714 };
715 }
716 if flex {
717 let known_pairs: Vec<(u32, usize)> = Vec::new();
718 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
719 }
720 n
721 }
722}
723impl<'de> DecodeBorrow<'de> for Topology<'de> {
724 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
725 let flex = version >= 0;
726 let mut out = Self::default();
727 if version >= 0 {
728 out.epoch = get_i32(buf)?;
729 }
730 if version >= 0 {
731 out.subtopologies = {
732 let n = crate::primitives::array::get_array_len(buf, flex)?;
733 let mut v = Vec::with_capacity(n);
734 for _ in 0..n {
735 v.push(Subtopology::decode_borrow(buf, version)?);
736 }
737 v
738 };
739 }
740 if flex {
741 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
742 }
743 Ok(out)
744 }
745}
746#[cfg(test)]
747impl Topology<'_> {
748 #[must_use]
749 pub fn populated(version: i16) -> Self {
750 let mut m = Self::default();
751 if version >= 0 {
752 m.epoch = 1i32;
753 }
754 if version >= 0 {
755 m.subtopologies = vec![Subtopology::populated(version)];
756 }
757 m
758 }
759}
760#[derive(Debug, Clone, PartialEq, Eq, Default)]
761pub struct Subtopology<'a> {
762 pub subtopology_id: &'a str,
763 pub source_topics: Vec<&'a str>,
764 pub source_topic_regex: Vec<&'a str>,
765 pub state_changelog_topics:
766 Vec<super::common::streams_group_heartbeat_request::topic_info::TopicInfo<'a>>,
767 pub repartition_sink_topics: Vec<&'a str>,
768 pub repartition_source_topics:
769 Vec<super::common::streams_group_heartbeat_request::topic_info::TopicInfo<'a>>,
770 pub copartition_groups: Vec<CopartitionGroup>,
771 pub unknown_tagged_fields: UnknownTaggedFields,
772}
773impl Subtopology<'_> {
774 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::Subtopology {
775 crate::owned::streams_group_heartbeat_request::Subtopology {
776 subtopology_id: (self.subtopology_id).to_string(),
777 source_topics: (self.source_topics)
778 .iter()
779 .map(std::string::ToString::to_string)
780 .collect(),
781 source_topic_regex: (self.source_topic_regex)
782 .iter()
783 .map(std::string::ToString::to_string)
784 .collect(),
785 state_changelog_topics: (self.state_changelog_topics)
786 .iter()
787 .map(
788 super::common::streams_group_heartbeat_request::topic_info::TopicInfo::to_owned,
789 )
790 .collect(),
791 repartition_sink_topics: (self.repartition_sink_topics)
792 .iter()
793 .map(std::string::ToString::to_string)
794 .collect(),
795 repartition_source_topics: (self.repartition_source_topics)
796 .iter()
797 .map(
798 super::common::streams_group_heartbeat_request::topic_info::TopicInfo::to_owned,
799 )
800 .collect(),
801 copartition_groups: (self.copartition_groups)
802 .iter()
803 .map(CopartitionGroup::to_owned)
804 .collect(),
805 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
806 }
807 }
808}
809impl Encode for Subtopology<'_> {
810 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
811 let flex = version >= 0;
812 if version >= 0 {
813 if flex {
814 put_compact_string(buf, self.subtopology_id);
815 } else {
816 put_string(buf, self.subtopology_id);
817 }
818 }
819 if version >= 0 {
820 {
821 crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex);
822 for it in &self.source_topics {
823 if flex {
824 put_compact_string(buf, it);
825 } else {
826 put_string(buf, it);
827 }
828 }
829 }
830 }
831 if version >= 0 {
832 {
833 crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex);
834 for it in &self.source_topic_regex {
835 if flex {
836 put_compact_string(buf, it);
837 } else {
838 put_string(buf, it);
839 }
840 }
841 }
842 }
843 if version >= 0 {
844 {
845 crate::primitives::array::put_array_len(
846 buf,
847 (self.state_changelog_topics).len(),
848 flex,
849 );
850 for it in &self.state_changelog_topics {
851 it.encode(buf, version)?;
852 }
853 }
854 }
855 if version >= 0 {
856 {
857 crate::primitives::array::put_array_len(
858 buf,
859 (self.repartition_sink_topics).len(),
860 flex,
861 );
862 for it in &self.repartition_sink_topics {
863 if flex {
864 put_compact_string(buf, it);
865 } else {
866 put_string(buf, it);
867 }
868 }
869 }
870 }
871 if version >= 0 {
872 {
873 crate::primitives::array::put_array_len(
874 buf,
875 (self.repartition_source_topics).len(),
876 flex,
877 );
878 for it in &self.repartition_source_topics {
879 it.encode(buf, version)?;
880 }
881 }
882 }
883 if version >= 0 {
884 {
885 crate::primitives::array::put_array_len(buf, (self.copartition_groups).len(), flex);
886 for it in &self.copartition_groups {
887 it.encode(buf, version)?;
888 }
889 }
890 }
891 if flex {
892 let tagged = WriteTaggedFields::new();
893 tagged.write(buf, &self.unknown_tagged_fields);
894 }
895 Ok(())
896 }
897 fn encoded_len(&self, version: i16) -> usize {
898 let flex = version >= 0;
899 let mut n: usize = 0;
900 if version >= 0 {
901 n += if flex {
902 compact_string_len(self.subtopology_id)
903 } else {
904 string_len(self.subtopology_id)
905 };
906 }
907 if version >= 0 {
908 n += {
909 let prefix = crate::primitives::array::array_len_prefix_len(
910 (self.source_topics).len(),
911 flex,
912 );
913 let body: usize = (self.source_topics)
914 .iter()
915 .map(|it| {
916 if flex {
917 compact_string_len(it)
918 } else {
919 string_len(it)
920 }
921 })
922 .sum();
923 prefix + body
924 };
925 }
926 if version >= 0 {
927 n += {
928 let prefix = crate::primitives::array::array_len_prefix_len(
929 (self.source_topic_regex).len(),
930 flex,
931 );
932 let body: usize = (self.source_topic_regex)
933 .iter()
934 .map(|it| {
935 if flex {
936 compact_string_len(it)
937 } else {
938 string_len(it)
939 }
940 })
941 .sum();
942 prefix + body
943 };
944 }
945 if version >= 0 {
946 n += {
947 let prefix = crate::primitives::array::array_len_prefix_len(
948 (self.state_changelog_topics).len(),
949 flex,
950 );
951 let body: usize = (self.state_changelog_topics)
952 .iter()
953 .map(|it| it.encoded_len(version))
954 .sum();
955 prefix + body
956 };
957 }
958 if version >= 0 {
959 n += {
960 let prefix = crate::primitives::array::array_len_prefix_len(
961 (self.repartition_sink_topics).len(),
962 flex,
963 );
964 let body: usize = (self.repartition_sink_topics)
965 .iter()
966 .map(|it| {
967 if flex {
968 compact_string_len(it)
969 } else {
970 string_len(it)
971 }
972 })
973 .sum();
974 prefix + body
975 };
976 }
977 if version >= 0 {
978 n += {
979 let prefix = crate::primitives::array::array_len_prefix_len(
980 (self.repartition_source_topics).len(),
981 flex,
982 );
983 let body: usize = (self.repartition_source_topics)
984 .iter()
985 .map(|it| it.encoded_len(version))
986 .sum();
987 prefix + body
988 };
989 }
990 if version >= 0 {
991 n += {
992 let prefix = crate::primitives::array::array_len_prefix_len(
993 (self.copartition_groups).len(),
994 flex,
995 );
996 let body: usize = (self.copartition_groups)
997 .iter()
998 .map(|it| it.encoded_len(version))
999 .sum();
1000 prefix + body
1001 };
1002 }
1003 if flex {
1004 let known_pairs: Vec<(u32, usize)> = Vec::new();
1005 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
1006 }
1007 n
1008 }
1009}
1010impl<'de> DecodeBorrow<'de> for Subtopology<'de> {
1011 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
1012 let flex = version >= 0;
1013 let mut out = Self::default();
1014 if version >= 0 {
1015 out.subtopology_id = if flex {
1016 get_compact_string_borrowed(buf)?
1017 } else {
1018 get_string_borrowed(buf)?
1019 };
1020 }
1021 if version >= 0 {
1022 out.source_topics = {
1023 let n = crate::primitives::array::get_array_len(buf, flex)?;
1024 let mut v = Vec::with_capacity(n);
1025 for _ in 0..n {
1026 v.push(if flex {
1027 get_compact_string_borrowed(buf)?
1028 } else {
1029 get_string_borrowed(buf)?
1030 });
1031 }
1032 v
1033 };
1034 }
1035 if version >= 0 {
1036 out.source_topic_regex = {
1037 let n = crate::primitives::array::get_array_len(buf, flex)?;
1038 let mut v = Vec::with_capacity(n);
1039 for _ in 0..n {
1040 v.push(if flex {
1041 get_compact_string_borrowed(buf)?
1042 } else {
1043 get_string_borrowed(buf)?
1044 });
1045 }
1046 v
1047 };
1048 }
1049 if version >= 0 {
1050 out.state_changelog_topics = {
1051 let n = crate::primitives::array::get_array_len(buf, flex)?;
1052 let mut v = Vec::with_capacity(n);
1053 for _ in 0..n {
1054 v . push (super :: common :: streams_group_heartbeat_request :: topic_info :: TopicInfo :: decode_borrow (buf , version) ?) ;
1055 }
1056 v
1057 };
1058 }
1059 if version >= 0 {
1060 out.repartition_sink_topics = {
1061 let n = crate::primitives::array::get_array_len(buf, flex)?;
1062 let mut v = Vec::with_capacity(n);
1063 for _ in 0..n {
1064 v.push(if flex {
1065 get_compact_string_borrowed(buf)?
1066 } else {
1067 get_string_borrowed(buf)?
1068 });
1069 }
1070 v
1071 };
1072 }
1073 if version >= 0 {
1074 out.repartition_source_topics = {
1075 let n = crate::primitives::array::get_array_len(buf, flex)?;
1076 let mut v = Vec::with_capacity(n);
1077 for _ in 0..n {
1078 v . push (super :: common :: streams_group_heartbeat_request :: topic_info :: TopicInfo :: decode_borrow (buf , version) ?) ;
1079 }
1080 v
1081 };
1082 }
1083 if version >= 0 {
1084 out.copartition_groups = {
1085 let n = crate::primitives::array::get_array_len(buf, flex)?;
1086 let mut v = Vec::with_capacity(n);
1087 for _ in 0..n {
1088 v.push(CopartitionGroup::decode_borrow(buf, version)?);
1089 }
1090 v
1091 };
1092 }
1093 if flex {
1094 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
1095 }
1096 Ok(out)
1097 }
1098}
1099#[cfg(test)]
1100impl Subtopology<'_> {
1101 #[must_use]
1102 pub fn populated(version: i16) -> Self {
1103 let mut m = Self::default();
1104 if version >= 0 {
1105 m.subtopology_id = "x";
1106 }
1107 if version >= 0 {
1108 m.source_topics = vec!["x"];
1109 }
1110 if version >= 0 {
1111 m.source_topic_regex = vec!["x"];
1112 }
1113 if version >= 0 {
1114 m.state_changelog_topics = vec![
1115 super::common::streams_group_heartbeat_request::topic_info::TopicInfo::populated(
1116 version,
1117 ),
1118 ];
1119 }
1120 if version >= 0 {
1121 m.repartition_sink_topics = vec!["x"];
1122 }
1123 if version >= 0 {
1124 m.repartition_source_topics = vec![
1125 super::common::streams_group_heartbeat_request::topic_info::TopicInfo::populated(
1126 version,
1127 ),
1128 ];
1129 }
1130 if version >= 0 {
1131 m.copartition_groups = vec![CopartitionGroup::populated(version)];
1132 }
1133 m
1134 }
1135}
1136#[derive(Debug, Clone, PartialEq, Eq, Default)]
1137pub struct CopartitionGroup {
1138 pub source_topics: Vec<i16>,
1139 pub source_topic_regex: Vec<i16>,
1140 pub repartition_source_topics: Vec<i16>,
1141 pub unknown_tagged_fields: UnknownTaggedFields,
1142}
1143impl CopartitionGroup {
1144 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::CopartitionGroup {
1145 crate::owned::streams_group_heartbeat_request::CopartitionGroup {
1146 source_topics: (self.source_topics).clone(),
1147 source_topic_regex: (self.source_topic_regex).clone(),
1148 repartition_source_topics: (self.repartition_source_topics).clone(),
1149 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
1150 }
1151 }
1152}
1153impl Encode for CopartitionGroup {
1154 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
1155 let flex = version >= 0;
1156 if version >= 0 {
1157 {
1158 crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex);
1159 for it in &self.source_topics {
1160 put_i16(buf, *it);
1161 }
1162 }
1163 }
1164 if version >= 0 {
1165 {
1166 crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex);
1167 for it in &self.source_topic_regex {
1168 put_i16(buf, *it);
1169 }
1170 }
1171 }
1172 if version >= 0 {
1173 {
1174 crate::primitives::array::put_array_len(
1175 buf,
1176 (self.repartition_source_topics).len(),
1177 flex,
1178 );
1179 for it in &self.repartition_source_topics {
1180 put_i16(buf, *it);
1181 }
1182 }
1183 }
1184 if flex {
1185 let tagged = WriteTaggedFields::new();
1186 tagged.write(buf, &self.unknown_tagged_fields);
1187 }
1188 Ok(())
1189 }
1190 fn encoded_len(&self, version: i16) -> usize {
1191 let flex = version >= 0;
1192 let mut n: usize = 0;
1193 if version >= 0 {
1194 n += {
1195 let prefix = crate::primitives::array::array_len_prefix_len(
1196 (self.source_topics).len(),
1197 flex,
1198 );
1199 let body: usize = (self.source_topics).iter().map(|_| 2).sum();
1200 prefix + body
1201 };
1202 }
1203 if version >= 0 {
1204 n += {
1205 let prefix = crate::primitives::array::array_len_prefix_len(
1206 (self.source_topic_regex).len(),
1207 flex,
1208 );
1209 let body: usize = (self.source_topic_regex).iter().map(|_| 2).sum();
1210 prefix + body
1211 };
1212 }
1213 if version >= 0 {
1214 n += {
1215 let prefix = crate::primitives::array::array_len_prefix_len(
1216 (self.repartition_source_topics).len(),
1217 flex,
1218 );
1219 let body: usize = (self.repartition_source_topics).iter().map(|_| 2).sum();
1220 prefix + body
1221 };
1222 }
1223 if flex {
1224 let known_pairs: Vec<(u32, usize)> = Vec::new();
1225 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
1226 }
1227 n
1228 }
1229}
1230impl<'de> DecodeBorrow<'de> for CopartitionGroup {
1231 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
1232 let flex = version >= 0;
1233 let mut out = Self::default();
1234 if version >= 0 {
1235 out.source_topics = {
1236 let n = crate::primitives::array::get_array_len(buf, flex)?;
1237 let mut v = Vec::with_capacity(n);
1238 for _ in 0..n {
1239 v.push(get_i16(buf)?);
1240 }
1241 v
1242 };
1243 }
1244 if version >= 0 {
1245 out.source_topic_regex = {
1246 let n = crate::primitives::array::get_array_len(buf, flex)?;
1247 let mut v = Vec::with_capacity(n);
1248 for _ in 0..n {
1249 v.push(get_i16(buf)?);
1250 }
1251 v
1252 };
1253 }
1254 if version >= 0 {
1255 out.repartition_source_topics = {
1256 let n = crate::primitives::array::get_array_len(buf, flex)?;
1257 let mut v = Vec::with_capacity(n);
1258 for _ in 0..n {
1259 v.push(get_i16(buf)?);
1260 }
1261 v
1262 };
1263 }
1264 if flex {
1265 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
1266 }
1267 Ok(out)
1268 }
1269}
1270#[cfg(test)]
1271impl CopartitionGroup {
1272 #[must_use]
1273 pub fn populated(version: i16) -> Self {
1274 let mut m = Self::default();
1275 if version >= 0 {
1276 m.source_topics = vec![1i16];
1277 }
1278 if version >= 0 {
1279 m.source_topic_regex = vec![1i16];
1280 }
1281 if version >= 0 {
1282 m.repartition_source_topics = vec![1i16];
1283 }
1284 m
1285 }
1286}