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