1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, 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,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 88;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct StreamsGroupHeartbeatRequest<'a> {
28 pub group_id: &'a str,
29 pub member_id: &'a str,
30 pub member_epoch: i32,
31 pub endpoint_information_epoch: i32,
32 pub instance_id: Option<&'a str>,
33 pub rack_id: Option<&'a str>,
34 pub rebalance_timeout_ms: i32,
35 pub topology: Option<Topology<'a>>,
36 pub active_tasks: Option<Vec<super::common::task_ids::TaskIds<'a>>>,
37 pub standby_tasks: Option<Vec<super::common::task_ids::TaskIds<'a>>>,
38 pub warmup_tasks: Option<Vec<super::common::task_ids::TaskIds<'a>>>,
39 pub process_id: Option<&'a str>,
40 pub user_endpoint: Option<super::common::endpoint::Endpoint<'a>>,
41 pub client_tags: Option<Vec<super::common::key_value::KeyValue<'a>>>,
42 pub task_offsets: Option<Vec<super::common::task_offset::TaskOffset<'a>>>,
43 pub task_end_offsets: Option<Vec<super::common::task_offset::TaskOffset<'a>>>,
44 pub shutdown_application: bool,
45 pub unknown_tagged_fields: UnknownTaggedFields,
46}
47
48impl<'a> Default for StreamsGroupHeartbeatRequest<'a> {
49 fn default() -> Self {
50 Self {
51 group_id: "",
52 member_id: "",
53 member_epoch: 0i32,
54 endpoint_information_epoch: 0i32,
55 instance_id: None,
56 rack_id: None,
57 rebalance_timeout_ms: -1i32,
58 topology: None,
59 active_tasks: None,
60 standby_tasks: None,
61 warmup_tasks: None,
62 process_id: None,
63 user_endpoint: None,
64 client_tags: None,
65 task_offsets: None,
66 task_end_offsets: None,
67 shutdown_application: false,
68 unknown_tagged_fields: Default::default(),
69 }
70 }
71}
72
73impl<'a> StreamsGroupHeartbeatRequest<'a> {
74 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::StreamsGroupHeartbeatRequest {
75 crate::owned::streams_group_heartbeat_request::StreamsGroupHeartbeatRequest {
76 group_id: (self.group_id).to_string(),
77 member_id: (self.member_id).to_string(),
78 member_epoch: (self.member_epoch),
79 endpoint_information_epoch: (self.endpoint_information_epoch),
80 instance_id: (self.instance_id).map(|s| s.to_string()),
81 rack_id: (self.rack_id).map(|s| s.to_string()),
82 rebalance_timeout_ms: (self.rebalance_timeout_ms),
83 topology: (self.topology).as_ref().map(|v| v.to_owned()),
84 active_tasks: (self.active_tasks).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
85 standby_tasks: (self.standby_tasks).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
86 warmup_tasks: (self.warmup_tasks).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
87 process_id: (self.process_id).map(|s| s.to_string()),
88 user_endpoint: (self.user_endpoint).as_ref().map(|v| v.to_owned()),
89 client_tags: (self.client_tags).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
90 task_offsets: (self.task_offsets).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
91 task_end_offsets: (self.task_end_offsets).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
92 shutdown_application: (self.shutdown_application),
93 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
94 }
95 }
96}
97
98impl<'a> Encode for StreamsGroupHeartbeatRequest<'a> {
99 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
100 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
102 }
103 let flex = is_flexible(version);
104 if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
105 if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
106 if version >= 0 { put_i32(buf, self.member_epoch) }
107 if version >= 0 { put_i32(buf, self.endpoint_information_epoch) }
108 if version >= 0 { if flex { put_compact_nullable_string(buf, self.instance_id) } else { put_nullable_string(buf, self.instance_id) } }
109 if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id) } else { put_nullable_string(buf, self.rack_id) } }
110 if version >= 0 { put_i32(buf, self.rebalance_timeout_ms) }
111 if version >= 0 { match &self.topology { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
112 if version >= 0 { { let len = (self.active_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.active_tasks { for it in v { it.encode(buf, version)?; } } } }
113 if version >= 0 { { let len = (self.standby_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.standby_tasks { for it in v { it.encode(buf, version)?; } } } }
114 if version >= 0 { { let len = (self.warmup_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.warmup_tasks { for it in v { it.encode(buf, version)?; } } } }
115 if version >= 0 { if flex { put_compact_nullable_string(buf, self.process_id) } else { put_nullable_string(buf, self.process_id) } }
116 if version >= 0 { match &self.user_endpoint { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
117 if version >= 0 { { let len = (self.client_tags).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.client_tags { for it in v { it.encode(buf, version)?; } } } }
118 if version >= 0 { { let len = (self.task_offsets).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.task_offsets { for it in v { it.encode(buf, version)?; } } } }
119 if version >= 0 { { let len = (self.task_end_offsets).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.task_end_offsets { for it in v { it.encode(buf, version)?; } } } }
120 if version >= 0 { put_bool(buf, self.shutdown_application) }
121 if flex {
122 let tagged = WriteTaggedFields::new();
123 tagged.write(buf, &self.unknown_tagged_fields);
124 }
125 Ok(())
126 }
127 fn encoded_len(&self, version: i16) -> usize {
128 let flex = is_flexible(version);
129 let mut n: usize = 0;
130 if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
131 if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
132 if version >= 0 { n += 4; }
133 if version >= 0 { n += 4; }
134 if version >= 0 { n += if flex { compact_nullable_string_len(self.instance_id) } else { nullable_string_len(self.instance_id) }; }
135 if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id) } else { nullable_string_len(self.rack_id) }; }
136 if version >= 0 { n += 4; }
137 if version >= 0 { n += 1 + self.topology.as_ref().map_or(0, |v| v.encoded_len(version)); }
138 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.active_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
139 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
140 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
141 if version >= 0 { n += if flex { compact_nullable_string_len(self.process_id) } else { nullable_string_len(self.process_id) }; }
142 if version >= 0 { n += 1 + self.user_endpoint.as_ref().map_or(0, |v| v.encoded_len(version)); }
143 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.client_tags).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
144 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.task_offsets).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
145 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.task_end_offsets).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
146 if version >= 0 { n += 1; }
147 if flex {
148 let known_pairs: Vec<(u32, usize)> = Vec::new();
149 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150 }
151 n
152 }
153}
154
155impl<'de> DecodeBorrow<'de> for StreamsGroupHeartbeatRequest<'de> {
156 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
157 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
158 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
159 }
160 let flex = is_flexible(version);
161 let mut out = Self::default();
162 if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
163 if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
164 if version >= 0 { out.member_epoch = get_i32(buf)?; }
165 if version >= 0 { out.endpoint_information_epoch = get_i32(buf)?; }
166 if version >= 0 { out.instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
167 if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
168 if version >= 0 { out.rebalance_timeout_ms = get_i32(buf)?; }
169 if version >= 0 { out.topology = if get_i8(buf)? < 0 { None } else { Some(Topology::decode_borrow(buf, version)?) }; }
170 if version >= 0 { out.active_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode_borrow(buf, version)?); } Some(v) } } }; }
171 if version >= 0 { out.standby_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode_borrow(buf, version)?); } Some(v) } } }; }
172 if version >= 0 { out.warmup_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode_borrow(buf, version)?); } Some(v) } } }; }
173 if version >= 0 { out.process_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
174 if version >= 0 { out.user_endpoint = if get_i8(buf)? < 0 { None } else { Some(super::common::endpoint::Endpoint::decode_borrow(buf, version)?) }; }
175 if version >= 0 { out.client_tags = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::key_value::KeyValue::decode_borrow(buf, version)?); } Some(v) } } }; }
176 if version >= 0 { out.task_offsets = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_offset::TaskOffset::decode_borrow(buf, version)?); } Some(v) } } }; }
177 if version >= 0 { out.task_end_offsets = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_offset::TaskOffset::decode_borrow(buf, version)?); } Some(v) } } }; }
178 if version >= 0 { out.shutdown_application = get_bool(buf)?; }
179 if flex {
180 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
181 Ok(false)
182 })?;
183 }
184 Ok(out)
185 }
186}
187
188#[derive(Debug, Clone, PartialEq, Eq)]
189pub struct Topology<'a> {
190 pub epoch: i32,
191 pub subtopologies: Vec<Subtopology<'a>>,
192 pub unknown_tagged_fields: UnknownTaggedFields,
193}
194
195impl<'a> Default for Topology<'a> {
196 fn default() -> Self {
197 Self {
198 epoch: 0i32,
199 subtopologies: Vec::new(),
200 unknown_tagged_fields: Default::default(),
201 }
202 }
203}
204
205impl<'a> Topology<'a> {
206 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::Topology {
207 crate::owned::streams_group_heartbeat_request::Topology {
208 epoch: (self.epoch),
209 subtopologies: (self.subtopologies).iter().map(|it| it.to_owned()).collect(),
210 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
211 }
212 }
213}
214
215impl<'a> Encode for Topology<'a> {
216 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
217 let flex = version >= 0;
218 if version >= 0 { put_i32(buf, self.epoch) }
219 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.subtopologies).len(), flex); for it in &self.subtopologies { it.encode(buf, version)?; } } }
220 if flex {
221 let tagged = WriteTaggedFields::new();
222 tagged.write(buf, &self.unknown_tagged_fields);
223 }
224 Ok(())
225 }
226 fn encoded_len(&self, version: i16) -> usize {
227 let flex = version >= 0;
228 let mut n: usize = 0;
229 if version >= 0 { n += 4; }
230 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.subtopologies).len(), flex); let body: usize = (self.subtopologies).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
231 if flex {
232 let known_pairs: Vec<(u32, usize)> = Vec::new();
233 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
234 }
235 n
236 }
237}
238
239impl<'de> DecodeBorrow<'de> for Topology<'de> {
240 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
241 let flex = version >= 0;
242 let mut out = Self::default();
243 if version >= 0 { out.epoch = get_i32(buf)?; }
244 if version >= 0 { out.subtopologies = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Subtopology::decode_borrow(buf, version)?); } v }; }
245 if flex {
246 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
247 Ok(false)
248 })?;
249 }
250 Ok(out)
251 }
252}
253
254#[derive(Debug, Clone, PartialEq, Eq)]
255pub struct Subtopology<'a> {
256 pub subtopology_id: &'a str,
257 pub source_topics: Vec<&'a str>,
258 pub source_topic_regex: Vec<&'a str>,
259 pub state_changelog_topics: Vec<super::common::topic_info::TopicInfo<'a>>,
260 pub repartition_sink_topics: Vec<&'a str>,
261 pub repartition_source_topics: Vec<super::common::topic_info::TopicInfo<'a>>,
262 pub copartition_groups: Vec<CopartitionGroup>,
263 pub unknown_tagged_fields: UnknownTaggedFields,
264}
265
266impl<'a> Default for Subtopology<'a> {
267 fn default() -> Self {
268 Self {
269 subtopology_id: "",
270 source_topics: Vec::new(),
271 source_topic_regex: Vec::new(),
272 state_changelog_topics: Vec::new(),
273 repartition_sink_topics: Vec::new(),
274 repartition_source_topics: Vec::new(),
275 copartition_groups: Vec::new(),
276 unknown_tagged_fields: Default::default(),
277 }
278 }
279}
280
281impl<'a> Subtopology<'a> {
282 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::Subtopology {
283 crate::owned::streams_group_heartbeat_request::Subtopology {
284 subtopology_id: (self.subtopology_id).to_string(),
285 source_topics: (self.source_topics).iter().map(|s| s.to_string()).collect(),
286 source_topic_regex: (self.source_topic_regex).iter().map(|s| s.to_string()).collect(),
287 state_changelog_topics: (self.state_changelog_topics).iter().map(|it| it.to_owned()).collect(),
288 repartition_sink_topics: (self.repartition_sink_topics).iter().map(|s| s.to_string()).collect(),
289 repartition_source_topics: (self.repartition_source_topics).iter().map(|it| it.to_owned()).collect(),
290 copartition_groups: (self.copartition_groups).iter().map(|it| it.to_owned()).collect(),
291 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
292 }
293 }
294}
295
296impl<'a> Encode for Subtopology<'a> {
297 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
298 let flex = version >= 0;
299 if version >= 0 { if flex { put_compact_string(buf, self.subtopology_id) } else { put_string(buf, self.subtopology_id) } }
300 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex); for it in &self.source_topics { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
301 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex); for it in &self.source_topic_regex { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
302 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.state_changelog_topics).len(), flex); for it in &self.state_changelog_topics { it.encode(buf, version)?; } } }
303 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.repartition_sink_topics).len(), flex); for it in &self.repartition_sink_topics { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
304 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.repartition_source_topics).len(), flex); for it in &self.repartition_source_topics { it.encode(buf, version)?; } } }
305 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.copartition_groups).len(), flex); for it in &self.copartition_groups { it.encode(buf, version)?; } } }
306 if flex {
307 let tagged = WriteTaggedFields::new();
308 tagged.write(buf, &self.unknown_tagged_fields);
309 }
310 Ok(())
311 }
312 fn encoded_len(&self, version: i16) -> usize {
313 let flex = version >= 0;
314 let mut n: usize = 0;
315 if version >= 0 { n += if flex { compact_string_len(self.subtopology_id) } else { string_len(self.subtopology_id) }; }
316 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.source_topics).len(), flex); let body: usize = (self.source_topics).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
317 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.source_topic_regex).len(), flex); let body: usize = (self.source_topic_regex).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
318 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.state_changelog_topics).len(), flex); let body: usize = (self.state_changelog_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
319 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.repartition_sink_topics).len(), flex); let body: usize = (self.repartition_sink_topics).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
320 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.repartition_source_topics).len(), flex); let body: usize = (self.repartition_source_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
321 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.copartition_groups).len(), flex); let body: usize = (self.copartition_groups).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
322 if flex {
323 let known_pairs: Vec<(u32, usize)> = Vec::new();
324 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
325 }
326 n
327 }
328}
329
330impl<'de> DecodeBorrow<'de> for Subtopology<'de> {
331 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
332 let flex = version >= 0;
333 let mut out = Self::default();
334 if version >= 0 { out.subtopology_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
335 if version >= 0 { out.source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
336 if version >= 0 { out.source_topic_regex = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
337 if version >= 0 { out.state_changelog_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_info::TopicInfo::decode_borrow(buf, version)?); } v }; }
338 if version >= 0 { out.repartition_sink_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
339 if version >= 0 { out.repartition_source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_info::TopicInfo::decode_borrow(buf, version)?); } v }; }
340 if version >= 0 { out.copartition_groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CopartitionGroup::decode_borrow(buf, version)?); } v }; }
341 if flex {
342 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
343 Ok(false)
344 })?;
345 }
346 Ok(out)
347 }
348}
349
350#[derive(Debug, Clone, PartialEq, Eq)]
351pub struct CopartitionGroup {
352 pub source_topics: Vec<i16>,
353 pub source_topic_regex: Vec<i16>,
354 pub repartition_source_topics: Vec<i16>,
355 pub unknown_tagged_fields: UnknownTaggedFields,
356}
357
358impl Default for CopartitionGroup {
359 fn default() -> Self {
360 Self {
361 source_topics: Vec::new(),
362 source_topic_regex: Vec::new(),
363 repartition_source_topics: Vec::new(),
364 unknown_tagged_fields: Default::default(),
365 }
366 }
367}
368
369impl CopartitionGroup {
370 pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_request::CopartitionGroup {
371 crate::owned::streams_group_heartbeat_request::CopartitionGroup {
372 source_topics: (self.source_topics).clone(),
373 source_topic_regex: (self.source_topic_regex).clone(),
374 repartition_source_topics: (self.repartition_source_topics).clone(),
375 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
376 }
377 }
378}
379
380impl Encode for CopartitionGroup {
381 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
382 let flex = version >= 0;
383 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex); for it in &self.source_topics { put_i16(buf, *it); } } }
384 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.source_topic_regex).len(), flex); for it in &self.source_topic_regex { put_i16(buf, *it); } } }
385 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.repartition_source_topics).len(), flex); for it in &self.repartition_source_topics { put_i16(buf, *it); } } }
386 if flex {
387 let tagged = WriteTaggedFields::new();
388 tagged.write(buf, &self.unknown_tagged_fields);
389 }
390 Ok(())
391 }
392 fn encoded_len(&self, version: i16) -> usize {
393 let flex = version >= 0;
394 let mut n: usize = 0;
395 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.source_topics).len(), flex); let body: usize = (self.source_topics).iter().map(|_| 2).sum(); prefix + body }; }
396 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.source_topic_regex).len(), flex); let body: usize = (self.source_topic_regex).iter().map(|_| 2).sum(); prefix + body }; }
397 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.repartition_source_topics).len(), flex); let body: usize = (self.repartition_source_topics).iter().map(|_| 2).sum(); prefix + body }; }
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}
405
406impl<'de> DecodeBorrow<'de> for CopartitionGroup {
407 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
408 let flex = version >= 0;
409 let mut out = Self::default();
410 if version >= 0 { out.source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i16(buf)?); } v }; }
411 if version >= 0 { out.source_topic_regex = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i16(buf)?); } v }; }
412 if version >= 0 { out.repartition_source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i16(buf)?); } v }; }
413 if flex {
414 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
415 Ok(false)
416 })?;
417 }
418 Ok(out)
419 }
420}