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