1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct ConsumerGroupDescribeResponseData {
17 pub throttle_time_ms: i32,
20 pub groups: Vec<DescribedGroup>,
22 pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for ConsumerGroupDescribeResponseData {
25 fn default() -> Self {
26 Self {
27 throttle_time_ms: 0_i32,
28 groups: Vec::new(),
29 _unknown_tagged_fields: Vec::new(),
30 }
31 }
32}
33impl ConsumerGroupDescribeResponseData {
34 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35 self.throttle_time_ms = value;
36 self
37 }
38 pub fn with_groups(mut self, value: Vec<DescribedGroup>) -> Self {
39 self.groups = value;
40 self
41 }
42 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43 if version < 0 || version > 1 {
44 return Err(UnsupportedVersion::new(69, version).into());
45 }
46 let throttle_time_ms;
47 let groups;
48 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49 throttle_time_ms = read_i32(buf)?;
50 groups = {
51 let len = read_compact_array_length(buf)?;
52 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
53 for _ in 0..len {
54 arr.push(DescribedGroup::read(buf, version)?);
55 }
56 arr
57 };
58 let tagged_fields = read_tagged_fields(buf)?;
59 for field in &tagged_fields {
60 match field.tag {
61 _ => {
62 _unknown_tagged_fields.push(field.clone());
63 },
64 }
65 }
66 Ok(Self {
67 throttle_time_ms,
68 groups,
69 _unknown_tagged_fields,
70 })
71 }
72 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
73 if version < 0 || version > 1 {
74 return Err(UnsupportedVersion::new(69, version).into());
75 }
76 write_i32(buf, self.throttle_time_ms);
77 write_compact_array_length(buf, self.groups.len() as i32);
78 for el in &self.groups {
79 el.write(buf, version)?;
80 }
81 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
82 all_tags.sort_by_key(|f| f.tag);
83 write_tagged_fields(buf, &all_tags)?;
84 Ok(())
85 }
86 pub fn encoded_len(&self, version: i16) -> Result<usize> {
87 if version < 0 || version > 1 {
88 return Err(UnsupportedVersion::new(69, version).into());
89 }
90 let mut len: usize = 0;
91 len += 4;
92 len += compact_array_length_len(self.groups.len() as i32);
93 for el in &self.groups {
94 len += el.encoded_len(version)?;
95 }
96 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
97 all_tags.sort_by_key(|f| f.tag);
98 len += tagged_fields_len(&all_tags)?;
99 Ok(len)
100 }
101}
102#[derive(Debug, Clone, PartialEq)]
103pub struct DescribedGroup {
104 pub error_code: i16,
106 pub error_message: Option<KafkaString>,
108 pub group_id: KafkaString,
110 pub group_state: KafkaString,
112 pub group_epoch: i32,
114 pub assignment_epoch: i32,
116 pub assignor_name: KafkaString,
118 pub members: Vec<Member>,
120 pub authorized_operations: i32,
122 pub _unknown_tagged_fields: Vec<RawTaggedField>,
123}
124impl Default for DescribedGroup {
125 fn default() -> Self {
126 Self {
127 error_code: 0_i16,
128 error_message: None,
129 group_id: KafkaString::default(),
130 group_state: KafkaString::default(),
131 group_epoch: 0_i32,
132 assignment_epoch: 0_i32,
133 assignor_name: KafkaString::default(),
134 members: Vec::new(),
135 authorized_operations: i32::MIN,
136 _unknown_tagged_fields: Vec::new(),
137 }
138 }
139}
140impl DescribedGroup {
141 pub fn with_error_code(mut self, value: i16) -> Self {
142 self.error_code = value;
143 self
144 }
145 pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
146 self.error_message = value;
147 self
148 }
149 pub fn with_group_id(mut self, value: KafkaString) -> Self {
150 self.group_id = value;
151 self
152 }
153 pub fn with_group_state(mut self, value: KafkaString) -> Self {
154 self.group_state = value;
155 self
156 }
157 pub fn with_group_epoch(mut self, value: i32) -> Self {
158 self.group_epoch = value;
159 self
160 }
161 pub fn with_assignment_epoch(mut self, value: i32) -> Self {
162 self.assignment_epoch = value;
163 self
164 }
165 pub fn with_assignor_name(mut self, value: KafkaString) -> Self {
166 self.assignor_name = value;
167 self
168 }
169 pub fn with_members(mut self, value: Vec<Member>) -> Self {
170 self.members = value;
171 self
172 }
173 pub fn with_authorized_operations(mut self, value: i32) -> Self {
174 self.authorized_operations = value;
175 self
176 }
177 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
178 let error_code;
179 let error_message;
180 let group_id;
181 let group_state;
182 let group_epoch;
183 let assignment_epoch;
184 let assignor_name;
185 let members;
186 let authorized_operations;
187 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
188 error_code = read_i16(buf)?;
189 error_message = read_compact_nullable_string(buf)?;
190 group_id = read_compact_string(buf)?;
191 group_state = read_compact_string(buf)?;
192 group_epoch = read_i32(buf)?;
193 assignment_epoch = read_i32(buf)?;
194 assignor_name = read_compact_string(buf)?;
195 members = {
196 let len = read_compact_array_length(buf)?;
197 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
198 for _ in 0..len {
199 arr.push(Member::read(buf, version)?);
200 }
201 arr
202 };
203 authorized_operations = read_i32(buf)?;
204 let tagged_fields = read_tagged_fields(buf)?;
205 for field in &tagged_fields {
206 match field.tag {
207 _ => {
208 _unknown_tagged_fields.push(field.clone());
209 },
210 }
211 }
212 Ok(Self {
213 error_code,
214 error_message,
215 group_id,
216 group_state,
217 group_epoch,
218 assignment_epoch,
219 assignor_name,
220 members,
221 authorized_operations,
222 _unknown_tagged_fields,
223 })
224 }
225 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
226 write_i16(buf, self.error_code);
227 write_compact_nullable_string(buf, self.error_message.as_ref())?;
228 write_compact_string(buf, &self.group_id)?;
229 write_compact_string(buf, &self.group_state)?;
230 write_i32(buf, self.group_epoch);
231 write_i32(buf, self.assignment_epoch);
232 write_compact_string(buf, &self.assignor_name)?;
233 write_compact_array_length(buf, self.members.len() as i32);
234 for el in &self.members {
235 el.write(buf, version)?;
236 }
237 write_i32(buf, self.authorized_operations);
238 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
239 all_tags.sort_by_key(|f| f.tag);
240 write_tagged_fields(buf, &all_tags)?;
241 Ok(())
242 }
243 pub fn encoded_len(&self, version: i16) -> Result<usize> {
244 let mut len: usize = 0;
245 len += 2;
246 len += compact_nullable_string_len(self.error_message.as_ref())?;
247 len += compact_string_len(&self.group_id)?;
248 len += compact_string_len(&self.group_state)?;
249 len += 4;
250 len += 4;
251 len += compact_string_len(&self.assignor_name)?;
252 len += compact_array_length_len(self.members.len() as i32);
253 for el in &self.members {
254 len += el.encoded_len(version)?;
255 }
256 len += 4;
257 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
258 all_tags.sort_by_key(|f| f.tag);
259 len += tagged_fields_len(&all_tags)?;
260 Ok(len)
261 }
262}
263#[derive(Debug, Clone, PartialEq)]
264pub struct Member {
265 pub member_id: KafkaString,
267 pub instance_id: Option<KafkaString>,
269 pub rack_id: Option<KafkaString>,
271 pub member_epoch: i32,
273 pub client_id: KafkaString,
275 pub client_host: KafkaString,
277 pub subscribed_topic_names: Vec<KafkaString>,
279 pub subscribed_topic_regex: Option<KafkaString>,
281 pub assignment: Assignment,
283 pub target_assignment: Assignment,
285 pub member_type: i8,
287 pub _unknown_tagged_fields: Vec<RawTaggedField>,
288}
289impl Default for Member {
290 fn default() -> Self {
291 Self {
292 member_id: KafkaString::default(),
293 instance_id: None,
294 rack_id: None,
295 member_epoch: 0_i32,
296 client_id: KafkaString::default(),
297 client_host: KafkaString::default(),
298 subscribed_topic_names: Vec::new(),
299 subscribed_topic_regex: None,
300 assignment: Assignment::default(),
301 target_assignment: Assignment::default(),
302 member_type: -1i8,
303 _unknown_tagged_fields: Vec::new(),
304 }
305 }
306}
307impl Member {
308 pub fn with_member_id(mut self, value: KafkaString) -> Self {
309 self.member_id = value;
310 self
311 }
312 pub fn with_instance_id(mut self, value: Option<KafkaString>) -> Self {
313 self.instance_id = value;
314 self
315 }
316 pub fn with_rack_id(mut self, value: Option<KafkaString>) -> Self {
317 self.rack_id = value;
318 self
319 }
320 pub fn with_member_epoch(mut self, value: i32) -> Self {
321 self.member_epoch = value;
322 self
323 }
324 pub fn with_client_id(mut self, value: KafkaString) -> Self {
325 self.client_id = value;
326 self
327 }
328 pub fn with_client_host(mut self, value: KafkaString) -> Self {
329 self.client_host = value;
330 self
331 }
332 pub fn with_subscribed_topic_names(mut self, value: Vec<KafkaString>) -> Self {
333 self.subscribed_topic_names = value;
334 self
335 }
336 pub fn with_subscribed_topic_regex(mut self, value: Option<KafkaString>) -> Self {
337 self.subscribed_topic_regex = value;
338 self
339 }
340 pub fn with_assignment(mut self, value: Assignment) -> Self {
341 self.assignment = value;
342 self
343 }
344 pub fn with_target_assignment(mut self, value: Assignment) -> Self {
345 self.target_assignment = value;
346 self
347 }
348 pub fn with_member_type(mut self, value: i8) -> Self {
349 self.member_type = value;
350 self
351 }
352 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
353 let member_id;
354 let instance_id;
355 let rack_id;
356 let member_epoch;
357 let client_id;
358 let client_host;
359 let subscribed_topic_names;
360 let subscribed_topic_regex;
361 let assignment;
362 let target_assignment;
363 let mut member_type = -1i8;
364 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
365 member_id = read_compact_string(buf)?;
366 instance_id = read_compact_nullable_string(buf)?;
367 rack_id = read_compact_nullable_string(buf)?;
368 member_epoch = read_i32(buf)?;
369 client_id = read_compact_string(buf)?;
370 client_host = read_compact_string(buf)?;
371 subscribed_topic_names = {
372 let len = read_compact_array_length(buf)?;
373 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
374 for _ in 0..len {
375 arr.push(read_compact_string(buf)?);
376 }
377 arr
378 };
379 subscribed_topic_regex = read_compact_nullable_string(buf)?;
380 assignment = Assignment::read(buf, version)?;
381 target_assignment = Assignment::read(buf, version)?;
382 if version >= 1 {
383 member_type = read_i8(buf)?;
384 }
385 let tagged_fields = read_tagged_fields(buf)?;
386 for field in &tagged_fields {
387 match field.tag {
388 _ => {
389 _unknown_tagged_fields.push(field.clone());
390 },
391 }
392 }
393 Ok(Self {
394 member_id,
395 instance_id,
396 rack_id,
397 member_epoch,
398 client_id,
399 client_host,
400 subscribed_topic_names,
401 subscribed_topic_regex,
402 assignment,
403 target_assignment,
404 member_type,
405 _unknown_tagged_fields,
406 })
407 }
408 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
409 write_compact_string(buf, &self.member_id)?;
410 write_compact_nullable_string(buf, self.instance_id.as_ref())?;
411 write_compact_nullable_string(buf, self.rack_id.as_ref())?;
412 write_i32(buf, self.member_epoch);
413 write_compact_string(buf, &self.client_id)?;
414 write_compact_string(buf, &self.client_host)?;
415 write_compact_array_length(buf, self.subscribed_topic_names.len() as i32);
416 for el in &self.subscribed_topic_names {
417 write_compact_string(buf, el)?;
418 }
419 write_compact_nullable_string(buf, self.subscribed_topic_regex.as_ref())?;
420 self.assignment.write(buf, version)?;
421 self.target_assignment.write(buf, version)?;
422 if version >= 1 {
423 write_i8(buf, self.member_type);
424 } else if self.member_type != -1i8 {
425 return Err(UnsupportedFieldVersion::new(69, "member_type", version).into());
426 }
427 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
428 all_tags.sort_by_key(|f| f.tag);
429 write_tagged_fields(buf, &all_tags)?;
430 Ok(())
431 }
432 pub fn encoded_len(&self, version: i16) -> Result<usize> {
433 let mut len: usize = 0;
434 len += compact_string_len(&self.member_id)?;
435 len += compact_nullable_string_len(self.instance_id.as_ref())?;
436 len += compact_nullable_string_len(self.rack_id.as_ref())?;
437 len += 4;
438 len += compact_string_len(&self.client_id)?;
439 len += compact_string_len(&self.client_host)?;
440 len += compact_array_length_len(self.subscribed_topic_names.len() as i32);
441 for el in &self.subscribed_topic_names {
442 len += compact_string_len(el)?;
443 }
444 len += compact_nullable_string_len(self.subscribed_topic_regex.as_ref())?;
445 len += self.assignment.encoded_len(version)?;
446 len += self.target_assignment.encoded_len(version)?;
447 if version >= 1 {
448 len += 1;
449 } else if self.member_type != -1i8 {
450 return Err(UnsupportedFieldVersion::new(69, "member_type", version).into());
451 }
452 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
453 all_tags.sort_by_key(|f| f.tag);
454 len += tagged_fields_len(&all_tags)?;
455 Ok(len)
456 }
457}
458#[derive(Debug, Clone, PartialEq)]
459pub struct TopicPartitions {
460 pub topic_id: KafkaUuid,
462 pub topic_name: KafkaString,
464 pub partitions: Vec<i32>,
466 pub _unknown_tagged_fields: Vec<RawTaggedField>,
467}
468impl Default for TopicPartitions {
469 fn default() -> Self {
470 Self {
471 topic_id: KafkaUuid::ZERO,
472 topic_name: KafkaString::default(),
473 partitions: Vec::new(),
474 _unknown_tagged_fields: Vec::new(),
475 }
476 }
477}
478impl TopicPartitions {
479 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
480 self.topic_id = value;
481 self
482 }
483 pub fn with_topic_name(mut self, value: KafkaString) -> Self {
484 self.topic_name = value;
485 self
486 }
487 pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
488 self.partitions = value;
489 self
490 }
491 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
492 let topic_id;
493 let topic_name;
494 let partitions;
495 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
496 topic_id = read_uuid(buf)?;
497 topic_name = read_compact_string(buf)?;
498 partitions = {
499 let len = read_compact_array_length(buf)?;
500 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
501 for _ in 0..len {
502 arr.push(read_i32(buf)?);
503 }
504 arr
505 };
506 let tagged_fields = read_tagged_fields(buf)?;
507 for field in &tagged_fields {
508 match field.tag {
509 _ => {
510 _unknown_tagged_fields.push(field.clone());
511 },
512 }
513 }
514 Ok(Self {
515 topic_id,
516 topic_name,
517 partitions,
518 _unknown_tagged_fields,
519 })
520 }
521 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
522 write_uuid(buf, &self.topic_id);
523 write_compact_string(buf, &self.topic_name)?;
524 write_compact_array_length(buf, self.partitions.len() as i32);
525 for el in &self.partitions {
526 write_i32(buf, *el);
527 }
528 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
529 all_tags.sort_by_key(|f| f.tag);
530 write_tagged_fields(buf, &all_tags)?;
531 Ok(())
532 }
533 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
534 let mut len: usize = 0;
535 len += 16;
536 len += compact_string_len(&self.topic_name)?;
537 len += compact_array_length_len(self.partitions.len() as i32);
538 len += self.partitions.len() * 4usize;
539 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
540 all_tags.sort_by_key(|f| f.tag);
541 len += tagged_fields_len(&all_tags)?;
542 Ok(len)
543 }
544}
545#[derive(Debug, Clone, PartialEq)]
546pub struct Assignment {
547 pub topic_partitions: Vec<TopicPartitions>,
549 pub _unknown_tagged_fields: Vec<RawTaggedField>,
550}
551impl Default for Assignment {
552 fn default() -> Self {
553 Self {
554 topic_partitions: Vec::new(),
555 _unknown_tagged_fields: Vec::new(),
556 }
557 }
558}
559impl Assignment {
560 pub fn with_topic_partitions(mut self, value: Vec<TopicPartitions>) -> Self {
561 self.topic_partitions = value;
562 self
563 }
564 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
565 let topic_partitions;
566 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
567 topic_partitions = {
568 let len = read_compact_array_length(buf)?;
569 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
570 for _ in 0..len {
571 arr.push(TopicPartitions::read(buf, version)?);
572 }
573 arr
574 };
575 let tagged_fields = read_tagged_fields(buf)?;
576 for field in &tagged_fields {
577 match field.tag {
578 _ => {
579 _unknown_tagged_fields.push(field.clone());
580 },
581 }
582 }
583 Ok(Self {
584 topic_partitions,
585 _unknown_tagged_fields,
586 })
587 }
588 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
589 write_compact_array_length(buf, self.topic_partitions.len() as i32);
590 for el in &self.topic_partitions {
591 el.write(buf, version)?;
592 }
593 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
594 all_tags.sort_by_key(|f| f.tag);
595 write_tagged_fields(buf, &all_tags)?;
596 Ok(())
597 }
598 pub fn encoded_len(&self, version: i16) -> Result<usize> {
599 let mut len: usize = 0;
600 len += compact_array_length_len(self.topic_partitions.len() as i32);
601 for el in &self.topic_partitions {
602 len += el.encoded_len(version)?;
603 }
604 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
605 all_tags.sort_by_key(|f| f.tag);
606 len += tagged_fields_len(&all_tags)?;
607 Ok(len)
608 }
609}