1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DescribeShareGroupOffsetsResponse {
24 pub throttle_time_ms: i32,
28
29 pub groups: Vec<DescribeShareGroupOffsetsResponseGroup>,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl DescribeShareGroupOffsetsResponse {
39 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
45 self.throttle_time_ms = value;
46 self
47 }
48 pub fn with_groups(mut self, value: Vec<DescribeShareGroupOffsetsResponseGroup>) -> Self {
54 self.groups = value;
55 self
56 }
57 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59 self.unknown_tagged_fields = value;
60 self
61 }
62 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64 self.unknown_tagged_fields.insert(key, value);
65 self
66 }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for DescribeShareGroupOffsetsResponse {
71 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72 if version != 0 {
73 bail!("specified version not supported by this message type");
74 }
75 types::Int32.encode(buf, &self.throttle_time_ms)?;
76 types::CompactArray(types::Struct { version }).encode(buf, &self.groups)?;
77 let num_tagged_fields = self.unknown_tagged_fields.len();
78 if num_tagged_fields > std::u32::MAX as usize {
79 bail!(
80 "Too many tagged fields to encode ({} fields)",
81 num_tagged_fields
82 );
83 }
84 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
85
86 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
87 Ok(())
88 }
89 fn compute_size(&self, version: i16) -> Result<usize> {
90 let mut total_size = 0;
91 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
92 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.groups)?;
93 let num_tagged_fields = self.unknown_tagged_fields.len();
94 if num_tagged_fields > std::u32::MAX as usize {
95 bail!(
96 "Too many tagged fields to encode ({} fields)",
97 num_tagged_fields
98 );
99 }
100 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
101
102 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
103 Ok(total_size)
104 }
105}
106
107#[cfg(feature = "client")]
108impl Decodable for DescribeShareGroupOffsetsResponse {
109 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
110 if version != 0 {
111 bail!("specified version not supported by this message type");
112 }
113 let throttle_time_ms = types::Int32.decode(buf)?;
114 let groups = types::CompactArray(types::Struct { version }).decode(buf)?;
115 let mut unknown_tagged_fields = BTreeMap::new();
116 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
117 for _ in 0..num_tagged_fields {
118 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
119 let size: u32 = types::UnsignedVarInt.decode(buf)?;
120 let unknown_value = buf.try_get_bytes(size as usize)?;
121 unknown_tagged_fields.insert(tag as i32, unknown_value);
122 }
123 Ok(Self {
124 throttle_time_ms,
125 groups,
126 unknown_tagged_fields,
127 })
128 }
129}
130
131impl Default for DescribeShareGroupOffsetsResponse {
132 fn default() -> Self {
133 Self {
134 throttle_time_ms: 0,
135 groups: Default::default(),
136 unknown_tagged_fields: BTreeMap::new(),
137 }
138 }
139}
140
141impl Message for DescribeShareGroupOffsetsResponse {
142 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
143 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
144}
145
146#[non_exhaustive]
148#[derive(Debug, Clone, PartialEq)]
149pub struct DescribeShareGroupOffsetsResponseGroup {
150 pub group_id: super::GroupId,
154
155 pub topics: Vec<DescribeShareGroupOffsetsResponseTopic>,
159
160 pub error_code: i16,
164
165 pub error_message: Option<StrBytes>,
169
170 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
172}
173
174impl DescribeShareGroupOffsetsResponseGroup {
175 pub fn with_group_id(mut self, value: super::GroupId) -> Self {
181 self.group_id = value;
182 self
183 }
184 pub fn with_topics(mut self, value: Vec<DescribeShareGroupOffsetsResponseTopic>) -> Self {
190 self.topics = value;
191 self
192 }
193 pub fn with_error_code(mut self, value: i16) -> Self {
199 self.error_code = value;
200 self
201 }
202 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
208 self.error_message = value;
209 self
210 }
211 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
213 self.unknown_tagged_fields = value;
214 self
215 }
216 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
218 self.unknown_tagged_fields.insert(key, value);
219 self
220 }
221}
222
223#[cfg(feature = "broker")]
224impl Encodable for DescribeShareGroupOffsetsResponseGroup {
225 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
226 if version != 0 {
227 bail!("specified version not supported by this message type");
228 }
229 types::CompactString.encode(buf, &self.group_id)?;
230 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
231 types::Int16.encode(buf, &self.error_code)?;
232 types::CompactString.encode(buf, &self.error_message)?;
233 let num_tagged_fields = self.unknown_tagged_fields.len();
234 if num_tagged_fields > std::u32::MAX as usize {
235 bail!(
236 "Too many tagged fields to encode ({} fields)",
237 num_tagged_fields
238 );
239 }
240 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
241
242 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
243 Ok(())
244 }
245 fn compute_size(&self, version: i16) -> Result<usize> {
246 let mut total_size = 0;
247 total_size += types::CompactString.compute_size(&self.group_id)?;
248 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
249 total_size += types::Int16.compute_size(&self.error_code)?;
250 total_size += types::CompactString.compute_size(&self.error_message)?;
251 let num_tagged_fields = self.unknown_tagged_fields.len();
252 if num_tagged_fields > std::u32::MAX as usize {
253 bail!(
254 "Too many tagged fields to encode ({} fields)",
255 num_tagged_fields
256 );
257 }
258 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
259
260 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
261 Ok(total_size)
262 }
263}
264
265#[cfg(feature = "client")]
266impl Decodable for DescribeShareGroupOffsetsResponseGroup {
267 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
268 if version != 0 {
269 bail!("specified version not supported by this message type");
270 }
271 let group_id = types::CompactString.decode(buf)?;
272 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
273 let error_code = types::Int16.decode(buf)?;
274 let error_message = types::CompactString.decode(buf)?;
275 let mut unknown_tagged_fields = BTreeMap::new();
276 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
277 for _ in 0..num_tagged_fields {
278 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
279 let size: u32 = types::UnsignedVarInt.decode(buf)?;
280 let unknown_value = buf.try_get_bytes(size as usize)?;
281 unknown_tagged_fields.insert(tag as i32, unknown_value);
282 }
283 Ok(Self {
284 group_id,
285 topics,
286 error_code,
287 error_message,
288 unknown_tagged_fields,
289 })
290 }
291}
292
293impl Default for DescribeShareGroupOffsetsResponseGroup {
294 fn default() -> Self {
295 Self {
296 group_id: Default::default(),
297 topics: Default::default(),
298 error_code: 0,
299 error_message: None,
300 unknown_tagged_fields: BTreeMap::new(),
301 }
302 }
303}
304
305impl Message for DescribeShareGroupOffsetsResponseGroup {
306 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
307 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
308}
309
310#[non_exhaustive]
312#[derive(Debug, Clone, PartialEq)]
313pub struct DescribeShareGroupOffsetsResponsePartition {
314 pub partition_index: i32,
318
319 pub start_offset: i64,
323
324 pub leader_epoch: i32,
328
329 pub error_code: i16,
333
334 pub error_message: Option<StrBytes>,
338
339 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
341}
342
343impl DescribeShareGroupOffsetsResponsePartition {
344 pub fn with_partition_index(mut self, value: i32) -> Self {
350 self.partition_index = value;
351 self
352 }
353 pub fn with_start_offset(mut self, value: i64) -> Self {
359 self.start_offset = value;
360 self
361 }
362 pub fn with_leader_epoch(mut self, value: i32) -> Self {
368 self.leader_epoch = value;
369 self
370 }
371 pub fn with_error_code(mut self, value: i16) -> Self {
377 self.error_code = value;
378 self
379 }
380 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
386 self.error_message = value;
387 self
388 }
389 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
391 self.unknown_tagged_fields = value;
392 self
393 }
394 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
396 self.unknown_tagged_fields.insert(key, value);
397 self
398 }
399}
400
401#[cfg(feature = "broker")]
402impl Encodable for DescribeShareGroupOffsetsResponsePartition {
403 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
404 if version != 0 {
405 bail!("specified version not supported by this message type");
406 }
407 types::Int32.encode(buf, &self.partition_index)?;
408 types::Int64.encode(buf, &self.start_offset)?;
409 types::Int32.encode(buf, &self.leader_epoch)?;
410 types::Int16.encode(buf, &self.error_code)?;
411 types::CompactString.encode(buf, &self.error_message)?;
412 let num_tagged_fields = self.unknown_tagged_fields.len();
413 if num_tagged_fields > std::u32::MAX as usize {
414 bail!(
415 "Too many tagged fields to encode ({} fields)",
416 num_tagged_fields
417 );
418 }
419 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
420
421 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
422 Ok(())
423 }
424 fn compute_size(&self, version: i16) -> Result<usize> {
425 let mut total_size = 0;
426 total_size += types::Int32.compute_size(&self.partition_index)?;
427 total_size += types::Int64.compute_size(&self.start_offset)?;
428 total_size += types::Int32.compute_size(&self.leader_epoch)?;
429 total_size += types::Int16.compute_size(&self.error_code)?;
430 total_size += types::CompactString.compute_size(&self.error_message)?;
431 let num_tagged_fields = self.unknown_tagged_fields.len();
432 if num_tagged_fields > std::u32::MAX as usize {
433 bail!(
434 "Too many tagged fields to encode ({} fields)",
435 num_tagged_fields
436 );
437 }
438 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
439
440 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
441 Ok(total_size)
442 }
443}
444
445#[cfg(feature = "client")]
446impl Decodable for DescribeShareGroupOffsetsResponsePartition {
447 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
448 if version != 0 {
449 bail!("specified version not supported by this message type");
450 }
451 let partition_index = types::Int32.decode(buf)?;
452 let start_offset = types::Int64.decode(buf)?;
453 let leader_epoch = types::Int32.decode(buf)?;
454 let error_code = types::Int16.decode(buf)?;
455 let error_message = types::CompactString.decode(buf)?;
456 let mut unknown_tagged_fields = BTreeMap::new();
457 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
458 for _ in 0..num_tagged_fields {
459 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
460 let size: u32 = types::UnsignedVarInt.decode(buf)?;
461 let unknown_value = buf.try_get_bytes(size as usize)?;
462 unknown_tagged_fields.insert(tag as i32, unknown_value);
463 }
464 Ok(Self {
465 partition_index,
466 start_offset,
467 leader_epoch,
468 error_code,
469 error_message,
470 unknown_tagged_fields,
471 })
472 }
473}
474
475impl Default for DescribeShareGroupOffsetsResponsePartition {
476 fn default() -> Self {
477 Self {
478 partition_index: 0,
479 start_offset: 0,
480 leader_epoch: 0,
481 error_code: 0,
482 error_message: None,
483 unknown_tagged_fields: BTreeMap::new(),
484 }
485 }
486}
487
488impl Message for DescribeShareGroupOffsetsResponsePartition {
489 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
490 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
491}
492
493#[non_exhaustive]
495#[derive(Debug, Clone, PartialEq)]
496pub struct DescribeShareGroupOffsetsResponseTopic {
497 pub topic_name: super::TopicName,
501
502 pub topic_id: Uuid,
506
507 pub partitions: Vec<DescribeShareGroupOffsetsResponsePartition>,
511
512 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
514}
515
516impl DescribeShareGroupOffsetsResponseTopic {
517 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
523 self.topic_name = value;
524 self
525 }
526 pub fn with_topic_id(mut self, value: Uuid) -> Self {
532 self.topic_id = value;
533 self
534 }
535 pub fn with_partitions(
541 mut self,
542 value: Vec<DescribeShareGroupOffsetsResponsePartition>,
543 ) -> Self {
544 self.partitions = value;
545 self
546 }
547 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
549 self.unknown_tagged_fields = value;
550 self
551 }
552 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
554 self.unknown_tagged_fields.insert(key, value);
555 self
556 }
557}
558
559#[cfg(feature = "broker")]
560impl Encodable for DescribeShareGroupOffsetsResponseTopic {
561 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
562 if version != 0 {
563 bail!("specified version not supported by this message type");
564 }
565 types::CompactString.encode(buf, &self.topic_name)?;
566 types::Uuid.encode(buf, &self.topic_id)?;
567 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
568 let num_tagged_fields = self.unknown_tagged_fields.len();
569 if num_tagged_fields > std::u32::MAX as usize {
570 bail!(
571 "Too many tagged fields to encode ({} fields)",
572 num_tagged_fields
573 );
574 }
575 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
576
577 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
578 Ok(())
579 }
580 fn compute_size(&self, version: i16) -> Result<usize> {
581 let mut total_size = 0;
582 total_size += types::CompactString.compute_size(&self.topic_name)?;
583 total_size += types::Uuid.compute_size(&self.topic_id)?;
584 total_size +=
585 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
586 let num_tagged_fields = self.unknown_tagged_fields.len();
587 if num_tagged_fields > std::u32::MAX as usize {
588 bail!(
589 "Too many tagged fields to encode ({} fields)",
590 num_tagged_fields
591 );
592 }
593 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
594
595 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
596 Ok(total_size)
597 }
598}
599
600#[cfg(feature = "client")]
601impl Decodable for DescribeShareGroupOffsetsResponseTopic {
602 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
603 if version != 0 {
604 bail!("specified version not supported by this message type");
605 }
606 let topic_name = types::CompactString.decode(buf)?;
607 let topic_id = types::Uuid.decode(buf)?;
608 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
609 let mut unknown_tagged_fields = BTreeMap::new();
610 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
611 for _ in 0..num_tagged_fields {
612 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
613 let size: u32 = types::UnsignedVarInt.decode(buf)?;
614 let unknown_value = buf.try_get_bytes(size as usize)?;
615 unknown_tagged_fields.insert(tag as i32, unknown_value);
616 }
617 Ok(Self {
618 topic_name,
619 topic_id,
620 partitions,
621 unknown_tagged_fields,
622 })
623 }
624}
625
626impl Default for DescribeShareGroupOffsetsResponseTopic {
627 fn default() -> Self {
628 Self {
629 topic_name: Default::default(),
630 topic_id: Uuid::nil(),
631 partitions: Default::default(),
632 unknown_tagged_fields: BTreeMap::new(),
633 }
634 }
635}
636
637impl Message for DescribeShareGroupOffsetsResponseTopic {
638 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
639 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
640}
641
642impl HeaderVersion for DescribeShareGroupOffsetsResponse {
643 fn header_version(version: i16) -> i16 {
644 1
645 }
646}