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 DescribeLogDirsPartition {
24 pub partition_index: i32,
28
29 pub partition_size: i64,
33
34 pub offset_lag: i64,
38
39 pub is_future_key: bool,
43
44 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl DescribeLogDirsPartition {
49 pub fn with_partition_index(mut self, value: i32) -> Self {
55 self.partition_index = value;
56 self
57 }
58 pub fn with_partition_size(mut self, value: i64) -> Self {
64 self.partition_size = value;
65 self
66 }
67 pub fn with_offset_lag(mut self, value: i64) -> Self {
73 self.offset_lag = value;
74 self
75 }
76 pub fn with_is_future_key(mut self, value: bool) -> Self {
82 self.is_future_key = value;
83 self
84 }
85 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87 self.unknown_tagged_fields = value;
88 self
89 }
90 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92 self.unknown_tagged_fields.insert(key, value);
93 self
94 }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for DescribeLogDirsPartition {
99 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100 if version < 0 || version > 4 {
101 bail!("specified version not supported by this message type");
102 }
103 types::Int32.encode(buf, &self.partition_index)?;
104 types::Int64.encode(buf, &self.partition_size)?;
105 types::Int64.encode(buf, &self.offset_lag)?;
106 types::Boolean.encode(buf, &self.is_future_key)?;
107 if version >= 2 {
108 let num_tagged_fields = self.unknown_tagged_fields.len();
109 if num_tagged_fields > std::u32::MAX as usize {
110 bail!(
111 "Too many tagged fields to encode ({} fields)",
112 num_tagged_fields
113 );
114 }
115 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
116
117 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
118 }
119 Ok(())
120 }
121 fn compute_size(&self, version: i16) -> Result<usize> {
122 let mut total_size = 0;
123 total_size += types::Int32.compute_size(&self.partition_index)?;
124 total_size += types::Int64.compute_size(&self.partition_size)?;
125 total_size += types::Int64.compute_size(&self.offset_lag)?;
126 total_size += types::Boolean.compute_size(&self.is_future_key)?;
127 if version >= 2 {
128 let num_tagged_fields = self.unknown_tagged_fields.len();
129 if num_tagged_fields > std::u32::MAX as usize {
130 bail!(
131 "Too many tagged fields to encode ({} fields)",
132 num_tagged_fields
133 );
134 }
135 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
136
137 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
138 }
139 Ok(total_size)
140 }
141}
142
143#[cfg(feature = "client")]
144impl Decodable for DescribeLogDirsPartition {
145 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
146 if version < 0 || version > 4 {
147 bail!("specified version not supported by this message type");
148 }
149 let partition_index = types::Int32.decode(buf)?;
150 let partition_size = types::Int64.decode(buf)?;
151 let offset_lag = types::Int64.decode(buf)?;
152 let is_future_key = types::Boolean.decode(buf)?;
153 let mut unknown_tagged_fields = BTreeMap::new();
154 if version >= 2 {
155 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
156 for _ in 0..num_tagged_fields {
157 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
158 let size: u32 = types::UnsignedVarInt.decode(buf)?;
159 let unknown_value = buf.try_get_bytes(size as usize)?;
160 unknown_tagged_fields.insert(tag as i32, unknown_value);
161 }
162 }
163 Ok(Self {
164 partition_index,
165 partition_size,
166 offset_lag,
167 is_future_key,
168 unknown_tagged_fields,
169 })
170 }
171}
172
173impl Default for DescribeLogDirsPartition {
174 fn default() -> Self {
175 Self {
176 partition_index: 0,
177 partition_size: 0,
178 offset_lag: 0,
179 is_future_key: false,
180 unknown_tagged_fields: BTreeMap::new(),
181 }
182 }
183}
184
185impl Message for DescribeLogDirsPartition {
186 const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
187 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
188}
189
190#[non_exhaustive]
192#[derive(Debug, Clone, PartialEq)]
193pub struct DescribeLogDirsResponse {
194 pub throttle_time_ms: i32,
198
199 pub error_code: i16,
203
204 pub results: Vec<DescribeLogDirsResult>,
208
209 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
211}
212
213impl DescribeLogDirsResponse {
214 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
220 self.throttle_time_ms = value;
221 self
222 }
223 pub fn with_error_code(mut self, value: i16) -> Self {
229 self.error_code = value;
230 self
231 }
232 pub fn with_results(mut self, value: Vec<DescribeLogDirsResult>) -> Self {
238 self.results = value;
239 self
240 }
241 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
243 self.unknown_tagged_fields = value;
244 self
245 }
246 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
248 self.unknown_tagged_fields.insert(key, value);
249 self
250 }
251}
252
253#[cfg(feature = "broker")]
254impl Encodable for DescribeLogDirsResponse {
255 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
256 if version < 0 || version > 4 {
257 bail!("specified version not supported by this message type");
258 }
259 types::Int32.encode(buf, &self.throttle_time_ms)?;
260 if version >= 3 {
261 types::Int16.encode(buf, &self.error_code)?;
262 }
263 if version >= 2 {
264 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
265 } else {
266 types::Array(types::Struct { version }).encode(buf, &self.results)?;
267 }
268 if version >= 2 {
269 let num_tagged_fields = self.unknown_tagged_fields.len();
270 if num_tagged_fields > std::u32::MAX as usize {
271 bail!(
272 "Too many tagged fields to encode ({} fields)",
273 num_tagged_fields
274 );
275 }
276 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
277
278 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
279 }
280 Ok(())
281 }
282 fn compute_size(&self, version: i16) -> Result<usize> {
283 let mut total_size = 0;
284 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
285 if version >= 3 {
286 total_size += types::Int16.compute_size(&self.error_code)?;
287 }
288 if version >= 2 {
289 total_size +=
290 types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
291 } else {
292 total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
293 }
294 if version >= 2 {
295 let num_tagged_fields = self.unknown_tagged_fields.len();
296 if num_tagged_fields > std::u32::MAX as usize {
297 bail!(
298 "Too many tagged fields to encode ({} fields)",
299 num_tagged_fields
300 );
301 }
302 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
303
304 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
305 }
306 Ok(total_size)
307 }
308}
309
310#[cfg(feature = "client")]
311impl Decodable for DescribeLogDirsResponse {
312 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
313 if version < 0 || version > 4 {
314 bail!("specified version not supported by this message type");
315 }
316 let throttle_time_ms = types::Int32.decode(buf)?;
317 let error_code = if version >= 3 {
318 types::Int16.decode(buf)?
319 } else {
320 0
321 };
322 let results = if version >= 2 {
323 types::CompactArray(types::Struct { version }).decode(buf)?
324 } else {
325 types::Array(types::Struct { version }).decode(buf)?
326 };
327 let mut unknown_tagged_fields = BTreeMap::new();
328 if version >= 2 {
329 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
330 for _ in 0..num_tagged_fields {
331 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
332 let size: u32 = types::UnsignedVarInt.decode(buf)?;
333 let unknown_value = buf.try_get_bytes(size as usize)?;
334 unknown_tagged_fields.insert(tag as i32, unknown_value);
335 }
336 }
337 Ok(Self {
338 throttle_time_ms,
339 error_code,
340 results,
341 unknown_tagged_fields,
342 })
343 }
344}
345
346impl Default for DescribeLogDirsResponse {
347 fn default() -> Self {
348 Self {
349 throttle_time_ms: 0,
350 error_code: 0,
351 results: Default::default(),
352 unknown_tagged_fields: BTreeMap::new(),
353 }
354 }
355}
356
357impl Message for DescribeLogDirsResponse {
358 const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
359 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
360}
361
362#[non_exhaustive]
364#[derive(Debug, Clone, PartialEq)]
365pub struct DescribeLogDirsResult {
366 pub error_code: i16,
370
371 pub log_dir: StrBytes,
375
376 pub topics: Vec<DescribeLogDirsTopic>,
380
381 pub total_bytes: i64,
385
386 pub usable_bytes: i64,
390
391 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
393}
394
395impl DescribeLogDirsResult {
396 pub fn with_error_code(mut self, value: i16) -> Self {
402 self.error_code = value;
403 self
404 }
405 pub fn with_log_dir(mut self, value: StrBytes) -> Self {
411 self.log_dir = value;
412 self
413 }
414 pub fn with_topics(mut self, value: Vec<DescribeLogDirsTopic>) -> Self {
420 self.topics = value;
421 self
422 }
423 pub fn with_total_bytes(mut self, value: i64) -> Self {
429 self.total_bytes = value;
430 self
431 }
432 pub fn with_usable_bytes(mut self, value: i64) -> Self {
438 self.usable_bytes = value;
439 self
440 }
441 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
443 self.unknown_tagged_fields = value;
444 self
445 }
446 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
448 self.unknown_tagged_fields.insert(key, value);
449 self
450 }
451}
452
453#[cfg(feature = "broker")]
454impl Encodable for DescribeLogDirsResult {
455 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
456 if version < 0 || version > 4 {
457 bail!("specified version not supported by this message type");
458 }
459 types::Int16.encode(buf, &self.error_code)?;
460 if version >= 2 {
461 types::CompactString.encode(buf, &self.log_dir)?;
462 } else {
463 types::String.encode(buf, &self.log_dir)?;
464 }
465 if version >= 2 {
466 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
467 } else {
468 types::Array(types::Struct { version }).encode(buf, &self.topics)?;
469 }
470 if version >= 4 {
471 types::Int64.encode(buf, &self.total_bytes)?;
472 }
473 if version >= 4 {
474 types::Int64.encode(buf, &self.usable_bytes)?;
475 }
476 if version >= 2 {
477 let num_tagged_fields = self.unknown_tagged_fields.len();
478 if num_tagged_fields > std::u32::MAX as usize {
479 bail!(
480 "Too many tagged fields to encode ({} fields)",
481 num_tagged_fields
482 );
483 }
484 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
485
486 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
487 }
488 Ok(())
489 }
490 fn compute_size(&self, version: i16) -> Result<usize> {
491 let mut total_size = 0;
492 total_size += types::Int16.compute_size(&self.error_code)?;
493 if version >= 2 {
494 total_size += types::CompactString.compute_size(&self.log_dir)?;
495 } else {
496 total_size += types::String.compute_size(&self.log_dir)?;
497 }
498 if version >= 2 {
499 total_size +=
500 types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
501 } else {
502 total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
503 }
504 if version >= 4 {
505 total_size += types::Int64.compute_size(&self.total_bytes)?;
506 }
507 if version >= 4 {
508 total_size += types::Int64.compute_size(&self.usable_bytes)?;
509 }
510 if version >= 2 {
511 let num_tagged_fields = self.unknown_tagged_fields.len();
512 if num_tagged_fields > std::u32::MAX as usize {
513 bail!(
514 "Too many tagged fields to encode ({} fields)",
515 num_tagged_fields
516 );
517 }
518 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
519
520 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
521 }
522 Ok(total_size)
523 }
524}
525
526#[cfg(feature = "client")]
527impl Decodable for DescribeLogDirsResult {
528 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
529 if version < 0 || version > 4 {
530 bail!("specified version not supported by this message type");
531 }
532 let error_code = types::Int16.decode(buf)?;
533 let log_dir = if version >= 2 {
534 types::CompactString.decode(buf)?
535 } else {
536 types::String.decode(buf)?
537 };
538 let topics = if version >= 2 {
539 types::CompactArray(types::Struct { version }).decode(buf)?
540 } else {
541 types::Array(types::Struct { version }).decode(buf)?
542 };
543 let total_bytes = if version >= 4 {
544 types::Int64.decode(buf)?
545 } else {
546 -1
547 };
548 let usable_bytes = if version >= 4 {
549 types::Int64.decode(buf)?
550 } else {
551 -1
552 };
553 let mut unknown_tagged_fields = BTreeMap::new();
554 if version >= 2 {
555 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
556 for _ in 0..num_tagged_fields {
557 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
558 let size: u32 = types::UnsignedVarInt.decode(buf)?;
559 let unknown_value = buf.try_get_bytes(size as usize)?;
560 unknown_tagged_fields.insert(tag as i32, unknown_value);
561 }
562 }
563 Ok(Self {
564 error_code,
565 log_dir,
566 topics,
567 total_bytes,
568 usable_bytes,
569 unknown_tagged_fields,
570 })
571 }
572}
573
574impl Default for DescribeLogDirsResult {
575 fn default() -> Self {
576 Self {
577 error_code: 0,
578 log_dir: Default::default(),
579 topics: Default::default(),
580 total_bytes: -1,
581 usable_bytes: -1,
582 unknown_tagged_fields: BTreeMap::new(),
583 }
584 }
585}
586
587impl Message for DescribeLogDirsResult {
588 const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
589 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
590}
591
592#[non_exhaustive]
594#[derive(Debug, Clone, PartialEq)]
595pub struct DescribeLogDirsTopic {
596 pub name: super::TopicName,
600
601 pub partitions: Vec<DescribeLogDirsPartition>,
605
606 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
608}
609
610impl DescribeLogDirsTopic {
611 pub fn with_name(mut self, value: super::TopicName) -> Self {
617 self.name = value;
618 self
619 }
620 pub fn with_partitions(mut self, value: Vec<DescribeLogDirsPartition>) -> Self {
626 self.partitions = value;
627 self
628 }
629 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
631 self.unknown_tagged_fields = value;
632 self
633 }
634 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
636 self.unknown_tagged_fields.insert(key, value);
637 self
638 }
639}
640
641#[cfg(feature = "broker")]
642impl Encodable for DescribeLogDirsTopic {
643 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
644 if version < 0 || version > 4 {
645 bail!("specified version not supported by this message type");
646 }
647 if version >= 2 {
648 types::CompactString.encode(buf, &self.name)?;
649 } else {
650 types::String.encode(buf, &self.name)?;
651 }
652 if version >= 2 {
653 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
654 } else {
655 types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
656 }
657 if version >= 2 {
658 let num_tagged_fields = self.unknown_tagged_fields.len();
659 if num_tagged_fields > std::u32::MAX as usize {
660 bail!(
661 "Too many tagged fields to encode ({} fields)",
662 num_tagged_fields
663 );
664 }
665 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
666
667 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
668 }
669 Ok(())
670 }
671 fn compute_size(&self, version: i16) -> Result<usize> {
672 let mut total_size = 0;
673 if version >= 2 {
674 total_size += types::CompactString.compute_size(&self.name)?;
675 } else {
676 total_size += types::String.compute_size(&self.name)?;
677 }
678 if version >= 2 {
679 total_size +=
680 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
681 } else {
682 total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
683 }
684 if version >= 2 {
685 let num_tagged_fields = self.unknown_tagged_fields.len();
686 if num_tagged_fields > std::u32::MAX as usize {
687 bail!(
688 "Too many tagged fields to encode ({} fields)",
689 num_tagged_fields
690 );
691 }
692 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
693
694 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
695 }
696 Ok(total_size)
697 }
698}
699
700#[cfg(feature = "client")]
701impl Decodable for DescribeLogDirsTopic {
702 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
703 if version < 0 || version > 4 {
704 bail!("specified version not supported by this message type");
705 }
706 let name = if version >= 2 {
707 types::CompactString.decode(buf)?
708 } else {
709 types::String.decode(buf)?
710 };
711 let partitions = if version >= 2 {
712 types::CompactArray(types::Struct { version }).decode(buf)?
713 } else {
714 types::Array(types::Struct { version }).decode(buf)?
715 };
716 let mut unknown_tagged_fields = BTreeMap::new();
717 if version >= 2 {
718 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
719 for _ in 0..num_tagged_fields {
720 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
721 let size: u32 = types::UnsignedVarInt.decode(buf)?;
722 let unknown_value = buf.try_get_bytes(size as usize)?;
723 unknown_tagged_fields.insert(tag as i32, unknown_value);
724 }
725 }
726 Ok(Self {
727 name,
728 partitions,
729 unknown_tagged_fields,
730 })
731 }
732}
733
734impl Default for DescribeLogDirsTopic {
735 fn default() -> Self {
736 Self {
737 name: Default::default(),
738 partitions: Default::default(),
739 unknown_tagged_fields: BTreeMap::new(),
740 }
741 }
742}
743
744impl Message for DescribeLogDirsTopic {
745 const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
746 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
747}
748
749impl HeaderVersion for DescribeLogDirsResponse {
750 fn header_version(version: i16) -> i16 {
751 if version >= 2 {
752 1
753 } else {
754 0
755 }
756 }
757}