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 ApiVersion {
24 pub api_key: i16,
28
29 pub min_version: i16,
33
34 pub max_version: i16,
38
39 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl ApiVersion {
44 pub fn with_api_key(mut self, value: i16) -> Self {
50 self.api_key = value;
51 self
52 }
53 pub fn with_min_version(mut self, value: i16) -> Self {
59 self.min_version = value;
60 self
61 }
62 pub fn with_max_version(mut self, value: i16) -> Self {
68 self.max_version = value;
69 self
70 }
71 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73 self.unknown_tagged_fields = value;
74 self
75 }
76 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78 self.unknown_tagged_fields.insert(key, value);
79 self
80 }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for ApiVersion {
85 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86 types::Int16.encode(buf, &self.api_key)?;
87 types::Int16.encode(buf, &self.min_version)?;
88 types::Int16.encode(buf, &self.max_version)?;
89 if version >= 3 {
90 let num_tagged_fields = self.unknown_tagged_fields.len();
91 if num_tagged_fields > std::u32::MAX as usize {
92 bail!(
93 "Too many tagged fields to encode ({} fields)",
94 num_tagged_fields
95 );
96 }
97 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
98
99 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
100 }
101 Ok(())
102 }
103 fn compute_size(&self, version: i16) -> Result<usize> {
104 let mut total_size = 0;
105 total_size += types::Int16.compute_size(&self.api_key)?;
106 total_size += types::Int16.compute_size(&self.min_version)?;
107 total_size += types::Int16.compute_size(&self.max_version)?;
108 if version >= 3 {
109 let num_tagged_fields = self.unknown_tagged_fields.len();
110 if num_tagged_fields > std::u32::MAX as usize {
111 bail!(
112 "Too many tagged fields to encode ({} fields)",
113 num_tagged_fields
114 );
115 }
116 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
117
118 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
119 }
120 Ok(total_size)
121 }
122}
123
124#[cfg(feature = "client")]
125impl Decodable for ApiVersion {
126 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
127 let api_key = types::Int16.decode(buf)?;
128 let min_version = types::Int16.decode(buf)?;
129 let max_version = types::Int16.decode(buf)?;
130 let mut unknown_tagged_fields = BTreeMap::new();
131 if version >= 3 {
132 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
133 for _ in 0..num_tagged_fields {
134 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
135 let size: u32 = types::UnsignedVarInt.decode(buf)?;
136 let unknown_value = buf.try_get_bytes(size as usize)?;
137 unknown_tagged_fields.insert(tag as i32, unknown_value);
138 }
139 }
140 Ok(Self {
141 api_key,
142 min_version,
143 max_version,
144 unknown_tagged_fields,
145 })
146 }
147}
148
149impl Default for ApiVersion {
150 fn default() -> Self {
151 Self {
152 api_key: 0,
153 min_version: 0,
154 max_version: 0,
155 unknown_tagged_fields: BTreeMap::new(),
156 }
157 }
158}
159
160impl Message for ApiVersion {
161 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
162 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct ApiVersionsResponse {
169 pub error_code: i16,
173
174 pub api_keys: Vec<ApiVersion>,
178
179 pub throttle_time_ms: i32,
183
184 pub supported_features: Vec<SupportedFeatureKey>,
188
189 pub finalized_features_epoch: i64,
193
194 pub finalized_features: Vec<FinalizedFeatureKey>,
198
199 pub zk_migration_ready: bool,
203
204 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
206}
207
208impl ApiVersionsResponse {
209 pub fn with_error_code(mut self, value: i16) -> Self {
215 self.error_code = value;
216 self
217 }
218 pub fn with_api_keys(mut self, value: Vec<ApiVersion>) -> Self {
224 self.api_keys = value;
225 self
226 }
227 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
233 self.throttle_time_ms = value;
234 self
235 }
236 pub fn with_supported_features(mut self, value: Vec<SupportedFeatureKey>) -> Self {
242 self.supported_features = value;
243 self
244 }
245 pub fn with_finalized_features_epoch(mut self, value: i64) -> Self {
251 self.finalized_features_epoch = value;
252 self
253 }
254 pub fn with_finalized_features(mut self, value: Vec<FinalizedFeatureKey>) -> Self {
260 self.finalized_features = value;
261 self
262 }
263 pub fn with_zk_migration_ready(mut self, value: bool) -> Self {
269 self.zk_migration_ready = value;
270 self
271 }
272 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
274 self.unknown_tagged_fields = value;
275 self
276 }
277 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
279 self.unknown_tagged_fields.insert(key, value);
280 self
281 }
282}
283
284#[cfg(feature = "broker")]
285impl Encodable for ApiVersionsResponse {
286 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
287 types::Int16.encode(buf, &self.error_code)?;
288 if version >= 3 {
289 types::CompactArray(types::Struct { version }).encode(buf, &self.api_keys)?;
290 } else {
291 types::Array(types::Struct { version }).encode(buf, &self.api_keys)?;
292 }
293 if version >= 1 {
294 types::Int32.encode(buf, &self.throttle_time_ms)?;
295 }
296 if version >= 3 {
297 let mut num_tagged_fields = self.unknown_tagged_fields.len();
298 if !self.supported_features.is_empty() {
299 num_tagged_fields += 1;
300 }
301 if self.finalized_features_epoch != -1 {
302 num_tagged_fields += 1;
303 }
304 if !self.finalized_features.is_empty() {
305 num_tagged_fields += 1;
306 }
307 if self.zk_migration_ready {
308 num_tagged_fields += 1;
309 }
310 if num_tagged_fields > std::u32::MAX as usize {
311 bail!(
312 "Too many tagged fields to encode ({} fields)",
313 num_tagged_fields
314 );
315 }
316 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
317 if !self.supported_features.is_empty() {
318 let computed_size = types::CompactArray(types::Struct { version })
319 .compute_size(&self.supported_features)?;
320 if computed_size > std::u32::MAX as usize {
321 bail!(
322 "Tagged field is too large to encode ({} bytes)",
323 computed_size
324 );
325 }
326 types::UnsignedVarInt.encode(buf, 0)?;
327 types::UnsignedVarInt.encode(buf, computed_size as u32)?;
328 types::CompactArray(types::Struct { version })
329 .encode(buf, &self.supported_features)?;
330 }
331 if self.finalized_features_epoch != -1 {
332 let computed_size = types::Int64.compute_size(&self.finalized_features_epoch)?;
333 if computed_size > std::u32::MAX as usize {
334 bail!(
335 "Tagged field is too large to encode ({} bytes)",
336 computed_size
337 );
338 }
339 types::UnsignedVarInt.encode(buf, 1)?;
340 types::UnsignedVarInt.encode(buf, computed_size as u32)?;
341 types::Int64.encode(buf, &self.finalized_features_epoch)?;
342 }
343 if !self.finalized_features.is_empty() {
344 let computed_size = types::CompactArray(types::Struct { version })
345 .compute_size(&self.finalized_features)?;
346 if computed_size > std::u32::MAX as usize {
347 bail!(
348 "Tagged field is too large to encode ({} bytes)",
349 computed_size
350 );
351 }
352 types::UnsignedVarInt.encode(buf, 2)?;
353 types::UnsignedVarInt.encode(buf, computed_size as u32)?;
354 types::CompactArray(types::Struct { version })
355 .encode(buf, &self.finalized_features)?;
356 }
357 if self.zk_migration_ready {
358 let computed_size = types::Boolean.compute_size(&self.zk_migration_ready)?;
359 if computed_size > std::u32::MAX as usize {
360 bail!(
361 "Tagged field is too large to encode ({} bytes)",
362 computed_size
363 );
364 }
365 types::UnsignedVarInt.encode(buf, 3)?;
366 types::UnsignedVarInt.encode(buf, computed_size as u32)?;
367 types::Boolean.encode(buf, &self.zk_migration_ready)?;
368 }
369
370 write_unknown_tagged_fields(buf, 4.., &self.unknown_tagged_fields)?;
371 }
372 Ok(())
373 }
374 fn compute_size(&self, version: i16) -> Result<usize> {
375 let mut total_size = 0;
376 total_size += types::Int16.compute_size(&self.error_code)?;
377 if version >= 3 {
378 total_size +=
379 types::CompactArray(types::Struct { version }).compute_size(&self.api_keys)?;
380 } else {
381 total_size += types::Array(types::Struct { version }).compute_size(&self.api_keys)?;
382 }
383 if version >= 1 {
384 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
385 }
386 if version >= 3 {
387 let mut num_tagged_fields = self.unknown_tagged_fields.len();
388 if !self.supported_features.is_empty() {
389 num_tagged_fields += 1;
390 }
391 if self.finalized_features_epoch != -1 {
392 num_tagged_fields += 1;
393 }
394 if !self.finalized_features.is_empty() {
395 num_tagged_fields += 1;
396 }
397 if self.zk_migration_ready {
398 num_tagged_fields += 1;
399 }
400 if num_tagged_fields > std::u32::MAX as usize {
401 bail!(
402 "Too many tagged fields to encode ({} fields)",
403 num_tagged_fields
404 );
405 }
406 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
407 if !self.supported_features.is_empty() {
408 let computed_size = types::CompactArray(types::Struct { version })
409 .compute_size(&self.supported_features)?;
410 if computed_size > std::u32::MAX as usize {
411 bail!(
412 "Tagged field is too large to encode ({} bytes)",
413 computed_size
414 );
415 }
416 total_size += types::UnsignedVarInt.compute_size(0)?;
417 total_size += types::UnsignedVarInt.compute_size(computed_size as u32)?;
418 total_size += computed_size;
419 }
420 if self.finalized_features_epoch != -1 {
421 let computed_size = types::Int64.compute_size(&self.finalized_features_epoch)?;
422 if computed_size > std::u32::MAX as usize {
423 bail!(
424 "Tagged field is too large to encode ({} bytes)",
425 computed_size
426 );
427 }
428 total_size += types::UnsignedVarInt.compute_size(1)?;
429 total_size += types::UnsignedVarInt.compute_size(computed_size as u32)?;
430 total_size += computed_size;
431 }
432 if !self.finalized_features.is_empty() {
433 let computed_size = types::CompactArray(types::Struct { version })
434 .compute_size(&self.finalized_features)?;
435 if computed_size > std::u32::MAX as usize {
436 bail!(
437 "Tagged field is too large to encode ({} bytes)",
438 computed_size
439 );
440 }
441 total_size += types::UnsignedVarInt.compute_size(2)?;
442 total_size += types::UnsignedVarInt.compute_size(computed_size as u32)?;
443 total_size += computed_size;
444 }
445 if self.zk_migration_ready {
446 let computed_size = types::Boolean.compute_size(&self.zk_migration_ready)?;
447 if computed_size > std::u32::MAX as usize {
448 bail!(
449 "Tagged field is too large to encode ({} bytes)",
450 computed_size
451 );
452 }
453 total_size += types::UnsignedVarInt.compute_size(3)?;
454 total_size += types::UnsignedVarInt.compute_size(computed_size as u32)?;
455 total_size += computed_size;
456 }
457
458 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
459 }
460 Ok(total_size)
461 }
462}
463
464#[cfg(feature = "client")]
465impl Decodable for ApiVersionsResponse {
466 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
467 let error_code = types::Int16.decode(buf)?;
468 let api_keys = if version >= 3 {
469 types::CompactArray(types::Struct { version }).decode(buf)?
470 } else {
471 types::Array(types::Struct { version }).decode(buf)?
472 };
473 let throttle_time_ms = if version >= 1 {
474 types::Int32.decode(buf)?
475 } else {
476 0
477 };
478 let mut supported_features = Default::default();
479 let mut finalized_features_epoch = -1;
480 let mut finalized_features = Default::default();
481 let mut zk_migration_ready = false;
482 let mut unknown_tagged_fields = BTreeMap::new();
483 if version >= 3 {
484 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
485 for _ in 0..num_tagged_fields {
486 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
487 let size: u32 = types::UnsignedVarInt.decode(buf)?;
488 match tag {
489 0 => {
490 supported_features =
491 types::CompactArray(types::Struct { version }).decode(buf)?;
492 }
493 1 => {
494 finalized_features_epoch = types::Int64.decode(buf)?;
495 }
496 2 => {
497 finalized_features =
498 types::CompactArray(types::Struct { version }).decode(buf)?;
499 }
500 3 => {
501 zk_migration_ready = types::Boolean.decode(buf)?;
502 }
503 _ => {
504 let unknown_value = buf.try_get_bytes(size as usize)?;
505 unknown_tagged_fields.insert(tag as i32, unknown_value);
506 }
507 }
508 }
509 }
510 Ok(Self {
511 error_code,
512 api_keys,
513 throttle_time_ms,
514 supported_features,
515 finalized_features_epoch,
516 finalized_features,
517 zk_migration_ready,
518 unknown_tagged_fields,
519 })
520 }
521}
522
523impl Default for ApiVersionsResponse {
524 fn default() -> Self {
525 Self {
526 error_code: 0,
527 api_keys: Default::default(),
528 throttle_time_ms: 0,
529 supported_features: Default::default(),
530 finalized_features_epoch: -1,
531 finalized_features: Default::default(),
532 zk_migration_ready: false,
533 unknown_tagged_fields: BTreeMap::new(),
534 }
535 }
536}
537
538impl Message for ApiVersionsResponse {
539 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
540 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
541}
542
543#[non_exhaustive]
545#[derive(Debug, Clone, PartialEq)]
546pub struct FinalizedFeatureKey {
547 pub name: StrBytes,
551
552 pub max_version_level: i16,
556
557 pub min_version_level: i16,
561
562 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
564}
565
566impl FinalizedFeatureKey {
567 pub fn with_name(mut self, value: StrBytes) -> Self {
573 self.name = value;
574 self
575 }
576 pub fn with_max_version_level(mut self, value: i16) -> Self {
582 self.max_version_level = value;
583 self
584 }
585 pub fn with_min_version_level(mut self, value: i16) -> Self {
591 self.min_version_level = value;
592 self
593 }
594 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
596 self.unknown_tagged_fields = value;
597 self
598 }
599 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
601 self.unknown_tagged_fields.insert(key, value);
602 self
603 }
604}
605
606#[cfg(feature = "broker")]
607impl Encodable for FinalizedFeatureKey {
608 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
609 if version >= 3 {
610 types::CompactString.encode(buf, &self.name)?;
611 } else {
612 if !self.name.is_empty() {
613 bail!("A field is set that is not available on the selected protocol version");
614 }
615 }
616 if version >= 3 {
617 types::Int16.encode(buf, &self.max_version_level)?;
618 } else {
619 if self.max_version_level != 0 {
620 bail!("A field is set that is not available on the selected protocol version");
621 }
622 }
623 if version >= 3 {
624 types::Int16.encode(buf, &self.min_version_level)?;
625 } else {
626 if self.min_version_level != 0 {
627 bail!("A field is set that is not available on the selected protocol version");
628 }
629 }
630 if version >= 3 {
631 let num_tagged_fields = self.unknown_tagged_fields.len();
632 if num_tagged_fields > std::u32::MAX as usize {
633 bail!(
634 "Too many tagged fields to encode ({} fields)",
635 num_tagged_fields
636 );
637 }
638 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
639
640 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
641 }
642 Ok(())
643 }
644 fn compute_size(&self, version: i16) -> Result<usize> {
645 let mut total_size = 0;
646 if version >= 3 {
647 total_size += types::CompactString.compute_size(&self.name)?;
648 } else {
649 if !self.name.is_empty() {
650 bail!("A field is set that is not available on the selected protocol version");
651 }
652 }
653 if version >= 3 {
654 total_size += types::Int16.compute_size(&self.max_version_level)?;
655 } else {
656 if self.max_version_level != 0 {
657 bail!("A field is set that is not available on the selected protocol version");
658 }
659 }
660 if version >= 3 {
661 total_size += types::Int16.compute_size(&self.min_version_level)?;
662 } else {
663 if self.min_version_level != 0 {
664 bail!("A field is set that is not available on the selected protocol version");
665 }
666 }
667 if version >= 3 {
668 let num_tagged_fields = self.unknown_tagged_fields.len();
669 if num_tagged_fields > std::u32::MAX as usize {
670 bail!(
671 "Too many tagged fields to encode ({} fields)",
672 num_tagged_fields
673 );
674 }
675 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
676
677 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
678 }
679 Ok(total_size)
680 }
681}
682
683#[cfg(feature = "client")]
684impl Decodable for FinalizedFeatureKey {
685 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
686 let name = if version >= 3 {
687 types::CompactString.decode(buf)?
688 } else {
689 Default::default()
690 };
691 let max_version_level = if version >= 3 {
692 types::Int16.decode(buf)?
693 } else {
694 0
695 };
696 let min_version_level = if version >= 3 {
697 types::Int16.decode(buf)?
698 } else {
699 0
700 };
701 let mut unknown_tagged_fields = BTreeMap::new();
702 if version >= 3 {
703 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
704 for _ in 0..num_tagged_fields {
705 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
706 let size: u32 = types::UnsignedVarInt.decode(buf)?;
707 let unknown_value = buf.try_get_bytes(size as usize)?;
708 unknown_tagged_fields.insert(tag as i32, unknown_value);
709 }
710 }
711 Ok(Self {
712 name,
713 max_version_level,
714 min_version_level,
715 unknown_tagged_fields,
716 })
717 }
718}
719
720impl Default for FinalizedFeatureKey {
721 fn default() -> Self {
722 Self {
723 name: Default::default(),
724 max_version_level: 0,
725 min_version_level: 0,
726 unknown_tagged_fields: BTreeMap::new(),
727 }
728 }
729}
730
731impl Message for FinalizedFeatureKey {
732 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
733 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
734}
735
736#[non_exhaustive]
738#[derive(Debug, Clone, PartialEq)]
739pub struct SupportedFeatureKey {
740 pub name: StrBytes,
744
745 pub min_version: i16,
749
750 pub max_version: i16,
754
755 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
757}
758
759impl SupportedFeatureKey {
760 pub fn with_name(mut self, value: StrBytes) -> Self {
766 self.name = value;
767 self
768 }
769 pub fn with_min_version(mut self, value: i16) -> Self {
775 self.min_version = value;
776 self
777 }
778 pub fn with_max_version(mut self, value: i16) -> Self {
784 self.max_version = value;
785 self
786 }
787 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
789 self.unknown_tagged_fields = value;
790 self
791 }
792 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
794 self.unknown_tagged_fields.insert(key, value);
795 self
796 }
797}
798
799#[cfg(feature = "broker")]
800impl Encodable for SupportedFeatureKey {
801 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
802 if version >= 3 {
803 types::CompactString.encode(buf, &self.name)?;
804 } else {
805 if !self.name.is_empty() {
806 bail!("A field is set that is not available on the selected protocol version");
807 }
808 }
809 if version >= 3 {
810 types::Int16.encode(buf, &self.min_version)?;
811 } else {
812 if self.min_version != 0 {
813 bail!("A field is set that is not available on the selected protocol version");
814 }
815 }
816 if version >= 3 {
817 types::Int16.encode(buf, &self.max_version)?;
818 } else {
819 if self.max_version != 0 {
820 bail!("A field is set that is not available on the selected protocol version");
821 }
822 }
823 if version >= 3 {
824 let num_tagged_fields = self.unknown_tagged_fields.len();
825 if num_tagged_fields > std::u32::MAX as usize {
826 bail!(
827 "Too many tagged fields to encode ({} fields)",
828 num_tagged_fields
829 );
830 }
831 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
832
833 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
834 }
835 Ok(())
836 }
837 fn compute_size(&self, version: i16) -> Result<usize> {
838 let mut total_size = 0;
839 if version >= 3 {
840 total_size += types::CompactString.compute_size(&self.name)?;
841 } else {
842 if !self.name.is_empty() {
843 bail!("A field is set that is not available on the selected protocol version");
844 }
845 }
846 if version >= 3 {
847 total_size += types::Int16.compute_size(&self.min_version)?;
848 } else {
849 if self.min_version != 0 {
850 bail!("A field is set that is not available on the selected protocol version");
851 }
852 }
853 if version >= 3 {
854 total_size += types::Int16.compute_size(&self.max_version)?;
855 } else {
856 if self.max_version != 0 {
857 bail!("A field is set that is not available on the selected protocol version");
858 }
859 }
860 if version >= 3 {
861 let num_tagged_fields = self.unknown_tagged_fields.len();
862 if num_tagged_fields > std::u32::MAX as usize {
863 bail!(
864 "Too many tagged fields to encode ({} fields)",
865 num_tagged_fields
866 );
867 }
868 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
869
870 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
871 }
872 Ok(total_size)
873 }
874}
875
876#[cfg(feature = "client")]
877impl Decodable for SupportedFeatureKey {
878 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
879 let name = if version >= 3 {
880 types::CompactString.decode(buf)?
881 } else {
882 Default::default()
883 };
884 let min_version = if version >= 3 {
885 types::Int16.decode(buf)?
886 } else {
887 0
888 };
889 let max_version = if version >= 3 {
890 types::Int16.decode(buf)?
891 } else {
892 0
893 };
894 let mut unknown_tagged_fields = BTreeMap::new();
895 if version >= 3 {
896 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
897 for _ in 0..num_tagged_fields {
898 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
899 let size: u32 = types::UnsignedVarInt.decode(buf)?;
900 let unknown_value = buf.try_get_bytes(size as usize)?;
901 unknown_tagged_fields.insert(tag as i32, unknown_value);
902 }
903 }
904 Ok(Self {
905 name,
906 min_version,
907 max_version,
908 unknown_tagged_fields,
909 })
910 }
911}
912
913impl Default for SupportedFeatureKey {
914 fn default() -> Self {
915 Self {
916 name: Default::default(),
917 min_version: 0,
918 max_version: 0,
919 unknown_tagged_fields: BTreeMap::new(),
920 }
921 }
922}
923
924impl Message for SupportedFeatureKey {
925 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
926 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
927}
928
929impl HeaderVersion for ApiVersionsResponse {
930 fn header_version(version: i16) -> i16 {
931 0
932 }
933}