crabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupHeartbeatRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, 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 = 68;
18pub const MIN_VERSION: i16 = 0;
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)]
28pub struct ConsumerGroupHeartbeatRequest<'a> {
29 pub group_id: &'a str,
30 pub member_id: &'a str,
31 pub member_epoch: i32,
32 pub instance_id: Option<&'a str>,
33 pub rack_id: Option<&'a str>,
34 pub rebalance_timeout_ms: i32,
35 pub subscribed_topic_names: Option<Vec<&'a str>>,
36 pub subscribed_topic_regex: Option<&'a str>,
37 pub server_assignor: Option<&'a str>,
38 pub topic_partitions: Option<Vec<TopicPartitions>>,
39 pub unknown_tagged_fields: UnknownTaggedFields,
40}
41impl Default for ConsumerGroupHeartbeatRequest<'_> {
42 fn default() -> Self {
43 Self {
44 group_id: "",
45 member_id: "",
46 member_epoch: 0i32,
47 instance_id: None,
48 rack_id: None,
49 rebalance_timeout_ms: -1i32,
50 subscribed_topic_names: None,
51 subscribed_topic_regex: None,
52 server_assignor: None,
53 topic_partitions: None,
54 unknown_tagged_fields: Default::default(),
55 }
56 }
57}
58impl ConsumerGroupHeartbeatRequest<'_> {
59 pub fn to_owned(
60 &self,
61 ) -> crate::owned::consumer_group_heartbeat_request::ConsumerGroupHeartbeatRequest {
62 crate::owned::consumer_group_heartbeat_request::ConsumerGroupHeartbeatRequest {
63 group_id: (self.group_id).to_string(),
64 member_id: (self.member_id).to_string(),
65 member_epoch: (self.member_epoch),
66 instance_id: (self.instance_id).map(std::string::ToString::to_string),
67 rack_id: (self.rack_id).map(std::string::ToString::to_string),
68 rebalance_timeout_ms: (self.rebalance_timeout_ms),
69 subscribed_topic_names: (self.subscribed_topic_names)
70 .as_ref()
71 .map(|v| v.iter().map(std::string::ToString::to_string).collect()),
72 subscribed_topic_regex: (self.subscribed_topic_regex)
73 .map(std::string::ToString::to_string),
74 server_assignor: (self.server_assignor).map(std::string::ToString::to_string),
75 topic_partitions: (self.topic_partitions)
76 .as_ref()
77 .map(|v| v.iter().map(TopicPartitions::to_owned).collect()),
78 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
79 }
80 }
81}
82impl Encode for ConsumerGroupHeartbeatRequest<'_> {
83 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
84 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85 return Err(ProtocolError::UnsupportedVersion {
86 api_key: API_KEY,
87 version,
88 });
89 }
90 let flex = is_flexible(version);
91 if version >= 0 {
92 if flex {
93 put_compact_string(buf, self.group_id);
94 } else {
95 put_string(buf, self.group_id);
96 }
97 }
98 if version >= 0 {
99 if flex {
100 put_compact_string(buf, self.member_id);
101 } else {
102 put_string(buf, self.member_id);
103 }
104 }
105 if version >= 0 {
106 put_i32(buf, self.member_epoch);
107 }
108 if version >= 0 {
109 if flex {
110 put_compact_nullable_string(buf, self.instance_id);
111 } else {
112 put_nullable_string(buf, self.instance_id);
113 }
114 }
115 if version >= 0 {
116 if flex {
117 put_compact_nullable_string(buf, self.rack_id);
118 } else {
119 put_nullable_string(buf, self.rack_id);
120 }
121 }
122 if version >= 0 {
123 put_i32(buf, self.rebalance_timeout_ms);
124 }
125 if version >= 0 {
126 {
127 let len = (self.subscribed_topic_names).as_ref().map(Vec::len);
128 crate::primitives::array::put_nullable_array_len(buf, len, flex);
129 if let Some(v) = &self.subscribed_topic_names {
130 for it in v {
131 if flex {
132 put_compact_string(buf, it);
133 } else {
134 put_string(buf, it);
135 }
136 }
137 }
138 }
139 }
140 if version >= 1 {
141 if flex {
142 put_compact_nullable_string(buf, self.subscribed_topic_regex);
143 } else {
144 put_nullable_string(buf, self.subscribed_topic_regex);
145 }
146 }
147 if version >= 0 {
148 if flex {
149 put_compact_nullable_string(buf, self.server_assignor);
150 } else {
151 put_nullable_string(buf, self.server_assignor);
152 }
153 }
154 if version >= 0 {
155 {
156 let len = (self.topic_partitions).as_ref().map(Vec::len);
157 crate::primitives::array::put_nullable_array_len(buf, len, flex);
158 if let Some(v) = &self.topic_partitions {
159 for it in v {
160 it.encode(buf, version)?;
161 }
162 }
163 }
164 }
165 if flex {
166 let tagged = WriteTaggedFields::new();
167 tagged.write(buf, &self.unknown_tagged_fields);
168 }
169 Ok(())
170 }
171 fn encoded_len(&self, version: i16) -> usize {
172 let flex = is_flexible(version);
173 let mut n: usize = 0;
174 if version >= 0 {
175 n += if flex {
176 compact_string_len(self.group_id)
177 } else {
178 string_len(self.group_id)
179 };
180 }
181 if version >= 0 {
182 n += if flex {
183 compact_string_len(self.member_id)
184 } else {
185 string_len(self.member_id)
186 };
187 }
188 if version >= 0 {
189 n += 4;
190 }
191 if version >= 0 {
192 n += if flex {
193 compact_nullable_string_len(self.instance_id)
194 } else {
195 nullable_string_len(self.instance_id)
196 };
197 }
198 if version >= 0 {
199 n += if flex {
200 compact_nullable_string_len(self.rack_id)
201 } else {
202 nullable_string_len(self.rack_id)
203 };
204 }
205 if version >= 0 {
206 n += 4;
207 }
208 if version >= 0 {
209 n += {
210 let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref();
211 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
212 opt.map(std::vec::Vec::len),
213 flex,
214 );
215 let body: usize = opt.map_or(0, |v| {
216 v.iter()
217 .map(|it| {
218 if flex {
219 compact_string_len(it)
220 } else {
221 string_len(it)
222 }
223 })
224 .sum()
225 });
226 prefix + body
227 };
228 }
229 if version >= 1 {
230 n += if flex {
231 compact_nullable_string_len(self.subscribed_topic_regex)
232 } else {
233 nullable_string_len(self.subscribed_topic_regex)
234 };
235 }
236 if version >= 0 {
237 n += if flex {
238 compact_nullable_string_len(self.server_assignor)
239 } else {
240 nullable_string_len(self.server_assignor)
241 };
242 }
243 if version >= 0 {
244 n += {
245 let opt: Option<&Vec<_>> = (self.topic_partitions).as_ref();
246 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
247 opt.map(std::vec::Vec::len),
248 flex,
249 );
250 let body: usize =
251 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
252 prefix + body
253 };
254 }
255 if flex {
256 let known_pairs: Vec<(u32, usize)> = Vec::new();
257 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
258 }
259 n
260 }
261}
262impl<'de> DecodeBorrow<'de> for ConsumerGroupHeartbeatRequest<'de> {
263 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
264 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
265 return Err(ProtocolError::UnsupportedVersion {
266 api_key: API_KEY,
267 version,
268 });
269 }
270 let flex = is_flexible(version);
271 let mut out = Self::default();
272 if version >= 0 {
273 out.group_id = if flex {
274 get_compact_string_borrowed(buf)?
275 } else {
276 get_string_borrowed(buf)?
277 };
278 }
279 if version >= 0 {
280 out.member_id = if flex {
281 get_compact_string_borrowed(buf)?
282 } else {
283 get_string_borrowed(buf)?
284 };
285 }
286 if version >= 0 {
287 out.member_epoch = get_i32(buf)?;
288 }
289 if version >= 0 {
290 out.instance_id = if flex {
291 get_compact_nullable_string_borrowed(buf)?
292 } else {
293 get_nullable_string_borrowed(buf)?
294 };
295 }
296 if version >= 0 {
297 out.rack_id = if flex {
298 get_compact_nullable_string_borrowed(buf)?
299 } else {
300 get_nullable_string_borrowed(buf)?
301 };
302 }
303 if version >= 0 {
304 out.rebalance_timeout_ms = get_i32(buf)?;
305 }
306 if version >= 0 {
307 out.subscribed_topic_names = {
308 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
309 match opt {
310 None => None,
311 Some(n) => {
312 let mut v = Vec::with_capacity(n);
313 for _ in 0..n {
314 v.push(if flex {
315 get_compact_string_borrowed(buf)?
316 } else {
317 get_string_borrowed(buf)?
318 });
319 }
320 Some(v)
321 }
322 }
323 };
324 }
325 if version >= 1 {
326 out.subscribed_topic_regex = if flex {
327 get_compact_nullable_string_borrowed(buf)?
328 } else {
329 get_nullable_string_borrowed(buf)?
330 };
331 }
332 if version >= 0 {
333 out.server_assignor = if flex {
334 get_compact_nullable_string_borrowed(buf)?
335 } else {
336 get_nullable_string_borrowed(buf)?
337 };
338 }
339 if version >= 0 {
340 out.topic_partitions = {
341 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
342 match opt {
343 None => None,
344 Some(n) => {
345 let mut v = Vec::with_capacity(n);
346 for _ in 0..n {
347 v.push(TopicPartitions::decode_borrow(buf, version)?);
348 }
349 Some(v)
350 }
351 }
352 };
353 }
354 if flex {
355 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
356 }
357 Ok(out)
358 }
359}
360#[cfg(test)]
361impl ConsumerGroupHeartbeatRequest<'_> {
362 #[must_use]
363 pub fn populated(version: i16) -> Self {
364 let mut m = Self::default();
365 if version >= 0 {
366 m.group_id = "x";
367 }
368 if version >= 0 {
369 m.member_id = "x";
370 }
371 if version >= 0 {
372 m.member_epoch = 1i32;
373 }
374 if version >= 0 {
375 m.instance_id = Some("x");
376 }
377 if version >= 0 {
378 m.rack_id = Some("x");
379 }
380 if version >= 0 {
381 m.rebalance_timeout_ms = 1i32;
382 }
383 if version >= 0 {
384 m.subscribed_topic_names = Some(vec!["x"]);
385 }
386 if version >= 1 {
387 m.subscribed_topic_regex = Some("x");
388 }
389 if version >= 0 {
390 m.server_assignor = Some("x");
391 }
392 if version >= 0 {
393 m.topic_partitions = Some(vec![TopicPartitions::populated(version)]);
394 }
395 m
396 }
397}
398#[derive(Debug, Clone, PartialEq, Eq, Default)]
399pub struct TopicPartitions {
400 pub topic_id: crate::primitives::uuid::Uuid,
401 pub partitions: Vec<i32>,
402 pub unknown_tagged_fields: UnknownTaggedFields,
403}
404impl TopicPartitions {
405 pub fn to_owned(&self) -> crate::owned::consumer_group_heartbeat_request::TopicPartitions {
406 crate::owned::consumer_group_heartbeat_request::TopicPartitions {
407 topic_id: (self.topic_id),
408 partitions: (self.partitions).clone(),
409 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
410 }
411 }
412}
413impl Encode for TopicPartitions {
414 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
415 let flex = version >= 0;
416 if version >= 0 {
417 crate::primitives::uuid::put_uuid(buf, self.topic_id);
418 }
419 if version >= 0 {
420 {
421 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
422 for it in &self.partitions {
423 put_i32(buf, *it);
424 }
425 }
426 }
427 if flex {
428 let tagged = WriteTaggedFields::new();
429 tagged.write(buf, &self.unknown_tagged_fields);
430 }
431 Ok(())
432 }
433 fn encoded_len(&self, version: i16) -> usize {
434 let flex = version >= 0;
435 let mut n: usize = 0;
436 if version >= 0 {
437 n += 16;
438 }
439 if version >= 0 {
440 n += {
441 let prefix =
442 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
443 let body: usize = (self.partitions).iter().map(|_| 4).sum();
444 prefix + body
445 };
446 }
447 if flex {
448 let known_pairs: Vec<(u32, usize)> = Vec::new();
449 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
450 }
451 n
452 }
453}
454impl<'de> DecodeBorrow<'de> for TopicPartitions {
455 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
456 let flex = version >= 0;
457 let mut out = Self::default();
458 if version >= 0 {
459 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
460 }
461 if version >= 0 {
462 out.partitions = {
463 let n = crate::primitives::array::get_array_len(buf, flex)?;
464 let mut v = Vec::with_capacity(n);
465 for _ in 0..n {
466 v.push(get_i32(buf)?);
467 }
468 v
469 };
470 }
471 if flex {
472 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
473 }
474 Ok(out)
475 }
476}
477#[cfg(test)]
478impl TopicPartitions {
479 #[must_use]
480 pub fn populated(version: i16) -> Self {
481 let mut m = Self::default();
482 if version >= 0 {
483 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
484 }
485 if version >= 0 {
486 m.partitions = vec![1i32];
487 }
488 m
489 }
490}