From 0550caaeecfecb2022bcc89e8b0ee152e725dd04 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Mon, 30 Sep 2024 15:57:36 +1000 Subject: [PATCH 1/2] Remove map generation logic so everything uses a vec even when map_key is provided --- .../src/generate_messages/generate.rs | 162 ++++++------------ src/protocol/mod.rs | 11 -- src/protocol/types.rs | 19 +- 3 files changed, 55 insertions(+), 137 deletions(-) diff --git a/protocol_codegen/src/generate_messages/generate.rs b/protocol_codegen/src/generate_messages/generate.rs index af69274..895139d 100644 --- a/protocol_codegen/src/generate_messages/generate.rs +++ b/protocol_codegen/src/generate_messages/generate.rs @@ -15,7 +15,6 @@ use std::cmp::Ordering; struct PreparedStruct { spec_type: SpecType, name: String, - map_key: Option>, prepared_fields: Vec, valid_versions: VersionSpec, flexible_msg_versions: VersionSpec, @@ -83,7 +82,6 @@ enum PreparedType { Entity(EntityType), Struct(PreparedStruct), Array(Box), - Map(Box, String), } impl PreparedType { @@ -93,7 +91,6 @@ impl PreparedType { Self::Entity(entity_type) => format!("super::{}", entity_type.name), Self::Struct(inner) => inner.name.clone(), Self::Array(inner) => format!("Vec<{}>", inner.rust_name()), - Self::Map(key, value) => format!("indexmap::IndexMap<{}, {}>", key.rust_name(), value), } } fn name(&self, flexible: bool, optional: bool) -> String { @@ -114,13 +111,6 @@ impl PreparedType { format!("types::Array({})", inner.name(flexible, false)) } } - Self::Map(_, _) => { - if flexible { - "types::CompactArray(types::Struct { version })".into() - } else { - "types::Array(types::Struct { version })".into() - } - } } } pub fn has_compact_form(&self) -> bool { @@ -129,7 +119,6 @@ impl PreparedType { Self::Entity(entity_type) => entity_type.inner.has_compact_form(), Self::Struct(_) => false, Self::Array(_) => true, - Self::Map(_, _) => true, } } fn default(&self) -> PreparedDefault { @@ -137,7 +126,7 @@ impl PreparedType { Self::Primitive(prim) => primitive_default(*prim), Self::Entity(entity_type) => primitive_default(entity_type.inner), Self::Struct(_) => PreparedDefault::EmptyStruct, - Self::Array(_) | Self::Map(_, _) => PreparedDefault::Empty, + Self::Array(_) => PreparedDefault::Empty, } } fn is_entity(&self) -> bool { @@ -224,18 +213,13 @@ struct PreparedField { default: PreparedDefault, ignorable: bool, _entity_type: Option, - map_key: bool, about: String, flexible_versions: VersionSpec, } impl PreparedField { fn var_name(&self) -> Expr { - if self.map_key { - Expr::new_atom("key") - } else { - Expr::new_atom("self").field(&self.name).by_ref() - } + Expr::new_atom("self").field(&self.name).by_ref() } } @@ -275,7 +259,6 @@ fn prepare_field_type( } else { PreparedStruct { name: name.clone(), - map_key: None, prepared_fields: vec![], valid_versions, flexible_msg_versions, @@ -313,14 +296,7 @@ fn prepare_field_type( prepared_structs_output, spec_type, )?; - match prepared_field { - PreparedType::Struct(PreparedStruct { - name, - map_key: Some(map_key), - .. - }) => PreparedType::Map(map_key, name), - other => PreparedType::Array(Box::new(other)), - } + PreparedType::Array(Box::new(prepared_field)) } }) } @@ -755,11 +731,7 @@ fn write_decode_field( field: &PreparedField, valid_versions: VersionSpec, ) -> Result<(), Error> { - let var_name = if field.map_key { - "key_field" - } else { - &field.name - }; + let var_name = &field.name; if field.tagged_versions.is_none() { write!(w, "let {} = ", var_name)?; @@ -884,11 +856,7 @@ fn write_decode_tag_buffer( write!(w, "match tag ")?; w.block(|w| { for (&k, field) in &sorted_tagged_fields { - let var_name = if field.map_key { - "key_field" - } else { - &field.name - }; + let var_name = &field.name; write!(w, "{} => ", k)?; w.block(|w| { let tagged_field_versions = @@ -985,9 +953,6 @@ fn prepared_struct_def( spec_type: SpecType, ) -> Result { let mut prepared_fields = Vec::new(); - let mut map_key = None; - - let num_map_keys = fields.iter().filter(|field| field.map_key).count(); for field in fields { let type_ = prepare_field_type( @@ -1003,10 +968,6 @@ fn prepared_struct_def( spec_type, )?; - if field.map_key && num_map_keys == 1 { - map_key = Some(Box::new(type_.clone())) - } - let mut name = field.name.to_snake_case(); if name == "type" { name = "_type".to_string(); @@ -1068,7 +1029,6 @@ fn prepared_struct_def( default, ignorable: field.ignorable, _entity_type: field.entity_type.clone(), - map_key: field.map_key && num_map_keys == 1, about: field.about.clone(), flexible_versions, }); @@ -1077,7 +1037,6 @@ fn prepared_struct_def( let prepared_struct = PreparedStruct { spec_type, name: name.into(), - map_key, prepared_fields, valid_versions, flexible_msg_versions, @@ -1095,9 +1054,6 @@ impl PreparedStruct { write!(w, "pub struct {} ", self.name)?; w.block(|w| { for prepared_field in &self.prepared_fields { - if prepared_field.map_key { - continue; - } writeln!(w, "/// {}", prepared_field.about)?; writeln!(w, "/// ")?; writeln!(w, "/// Supported API versions: {}", prepared_field.versions)?; @@ -1132,10 +1088,6 @@ impl PreparedStruct { write!(w, "impl {} ", self.name)?; w.block(|w| { for prepared_field in &self.prepared_fields { - if prepared_field.map_key { - continue; - } - writeln!(w, "/// Sets `{}` to the passed value.", prepared_field.name)?; writeln!(w, "/// ")?; writeln!(w, "/// {}", prepared_field.about)?; @@ -1200,38 +1152,41 @@ impl PreparedStruct { SpecType::Response => writeln!(w, "#[cfg(feature = \"broker\")]")?, _ => {} } - if self.map_key.is_some() { - write!(w, "impl MapEncodable for {} ", self.name)?; - } else { - write!(w, "impl Encodable for {} ", self.name)?; - } + + write!(w, "impl Encodable for {} ", self.name)?; w.block(|w| { - if let Some(key) = &self.map_key { - writeln!(w, "type Key = {};", key.rust_name())?; - write!(w, "fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> ")?; - } else { - write!(w, "fn encode(&self, buf: &mut B, version: i16) -> Result<()> ")?; - } + write!( + w, + "fn encode(&self, buf: &mut B, version: i16) -> Result<()> " + )?; w.block(|w| { for prepared_field in &self.prepared_fields { write_encode_field(w, prepared_field, self.valid_versions, false)?; } - write_encode_tag_buffer(w, &self.prepared_fields, self.valid_versions, self.flexible_msg_versions, false)?; + write_encode_tag_buffer( + w, + &self.prepared_fields, + self.valid_versions, + self.flexible_msg_versions, + false, + )?; write!(w, "Ok(())")?; Ok(()) })?; writeln!(w)?; - if self.map_key.is_some() { - write!(w, "fn compute_size(&self, key: &Self::Key, version: i16) -> Result ")?; - } else { - write!(w, "fn compute_size(&self, version: i16) -> Result ")?; - } + write!(w, "fn compute_size(&self, version: i16) -> Result ")?; w.block(|w| { writeln!(w, "let mut total_size = 0;")?; for prepared_field in &self.prepared_fields { write_encode_field(w, prepared_field, self.valid_versions, true)?; } - write_encode_tag_buffer(w, &self.prepared_fields, self.valid_versions, self.flexible_msg_versions, true)?; + write_encode_tag_buffer( + w, + &self.prepared_fields, + self.valid_versions, + self.flexible_msg_versions, + true, + )?; write!(w, "Ok(total_size)")?; Ok(()) })?; @@ -1245,36 +1200,29 @@ impl PreparedStruct { SpecType::Response => writeln!(w, "#[cfg(feature = \"client\")]")?, _ => {} } - if self.map_key.is_some() { - write!(w, "impl MapDecodable for {} ", self.name)?; - } else { - write!(w, "impl Decodable for {} ", self.name)?; - } + write!(w, "impl Decodable for {} ", self.name)?; w.block(|w| { - if let Some(key) = &self.map_key { - writeln!(w, "type Key = {};", key.rust_name())?; - write!(w, "fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> ")?; - } else { - write!(w, "fn decode(buf: &mut B, version: i16) -> Result ")?; - } + write!( + w, + "fn decode(buf: &mut B, version: i16) -> Result " + )?; w.block(|w| { for prepared_field in &self.prepared_fields { write_decode_field(w, prepared_field, self.valid_versions)?; } if !self.flexible_msg_versions.is_none() { writeln!(w, "let mut unknown_tagged_fields = BTreeMap::new();")?; - write_decode_tag_buffer(w, &self.prepared_fields, self.valid_versions, self.flexible_msg_versions)?; - } - if self.map_key.is_some() { - write!(w, "Ok((key_field, Self ")?; - } else { - write!(w, "Ok(Self ")?; + write_decode_tag_buffer( + w, + &self.prepared_fields, + self.valid_versions, + self.flexible_msg_versions, + )?; } + write!(w, "Ok(Self ")?; w.block(|w| { for prepared_field in &self.prepared_fields { - if !prepared_field.map_key { - writeln!(w, "{},", prepared_field.name)?; - } + writeln!(w, "{},", prepared_field.name)?; } if !self.flexible_msg_versions.is_none() { @@ -1283,11 +1231,8 @@ impl PreparedStruct { Ok(()) })?; - if self.map_key.is_some() { - write!(w, "))")?; - } else { - write!(w, ")")?; - } + + write!(w, ")")?; Ok(()) }) })?; @@ -1301,17 +1246,15 @@ impl PreparedStruct { write!(w, "Self ")?; w.block(|w| { for prepared_field in &self.prepared_fields { - if !prepared_field.map_key { - writeln!( - w, - "{}: {},", - prepared_field.name, - prepared_field.default.gen_default( - prepared_field.optional, - prepared_field.type_.is_entity(), - ) - )?; - } + writeln!( + w, + "{}: {},", + prepared_field.name, + prepared_field.default.gen_default( + prepared_field.optional, + prepared_field.type_.is_entity(), + ) + )?; } if !self.flexible_msg_versions.is_none() { @@ -1373,7 +1316,10 @@ fn write_file_header(w: &mut CodeWriter, name: &str) -> Result<(), writeln!(w, "use anyhow::{{bail, Result}};")?; writeln!(w)?; writeln!(w, "use crate::protocol::{{")?; - writeln!(w, " Encodable, Decodable, MapEncodable, MapDecodable, Encoder, Decoder, Message, HeaderVersion, VersionRange,")?; + writeln!( + w, + " Encodable, Decodable, Encoder, Decoder, Message, HeaderVersion, VersionRange," + )?; writeln!(w, " types, write_unknown_tagged_fields, compute_unknown_tagged_fields_size, StrBytes, buf::{{ByteBuf, ByteBufMut}}")?; writeln!(w, "}};")?; writeln!(w)?; diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 2d1e969..ddf211b 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -175,17 +175,6 @@ pub trait Decodable: Sized { fn decode(buf: &mut B, version: i16) -> Result; } -pub(crate) trait MapEncodable: Sized { - type Key; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()>; - fn compute_size(&self, key: &Self::Key, version: i16) -> Result; -} - -pub(crate) trait MapDecodable: Sized { - type Key; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)>; -} - /// Every message has a set of versions valid for a given header version. pub trait HeaderVersion { /// Maps a header version to a given version for a particular API message. diff --git a/src/protocol/types.rs b/src/protocol/types.rs index b430187..baefe38 100644 --- a/src/protocol/types.rs +++ b/src/protocol/types.rs @@ -4,9 +4,7 @@ //! types that use zigzag encoded to represent length as a "compact" representation. //! //! It is unnecessary to interact directly with these types for most use cases. -use super::{ - Decodable, Decoder, Encodable, Encoder, MapDecodable, MapEncodable, NewType, StrBytes, -}; +use super::{Decodable, Decoder, Encodable, Encoder, NewType, StrBytes}; use crate::protocol::buf::{ByteBuf, ByteBufMut}; use anyhow::{bail, Result}; use indexmap::IndexMap; @@ -908,21 +906,6 @@ impl Decoder> for OptionStruct { } } -impl Encoder<(&T::Key, &T)> for Struct { - fn encode(&self, buf: &mut B, (key, value): (&T::Key, &T)) -> Result<()> { - value.encode(key, buf, self.version) - } - fn compute_size(&self, (key, value): (&T::Key, &T)) -> Result { - value.compute_size(key, self.version) - } -} - -impl Decoder<(T::Key, T)> for Struct { - fn decode(&self, buf: &mut B) -> Result<(T::Key, T)> { - T::decode(buf, self.version) - } -} - /// An array whose length is encoded with an `i32`. #[derive(Debug, Copy, Clone)] pub struct Array(pub E); From 6f924cd027b4ff1b7cff8905ff8908d8effb119d Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Mon, 30 Sep 2024 16:03:43 +1000 Subject: [PATCH 2/2] codegen --- src/messages/add_offsets_to_txn_request.rs | 2 +- src/messages/add_offsets_to_txn_response.rs | 2 +- src/messages/add_partitions_to_txn_request.rs | 127 +++++++------ .../add_partitions_to_txn_response.rs | 169 +++++++++-------- src/messages/allocate_producer_ids_request.rs | 2 +- .../allocate_producer_ids_response.rs | 2 +- src/messages/alter_client_quotas_request.rs | 2 +- src/messages/alter_client_quotas_response.rs | 2 +- src/messages/alter_configs_request.rs | 55 +++--- src/messages/alter_configs_response.rs | 2 +- .../alter_partition_reassignments_request.rs | 2 +- .../alter_partition_reassignments_response.rs | 2 +- src/messages/alter_partition_request.rs | 2 +- src/messages/alter_partition_response.rs | 2 +- .../alter_replica_log_dirs_request.rs | 111 ++++++----- .../alter_replica_log_dirs_response.rs | 2 +- .../alter_user_scram_credentials_request.rs | 2 +- .../alter_user_scram_credentials_response.rs | 2 +- src/messages/api_versions_request.rs | 2 +- src/messages/api_versions_response.rs | 169 +++++++++-------- .../assign_replicas_to_dirs_request.rs | 2 +- .../assign_replicas_to_dirs_response.rs | 2 +- src/messages/begin_quorum_epoch_request.rs | 2 +- src/messages/begin_quorum_epoch_response.rs | 2 +- src/messages/broker_heartbeat_request.rs | 2 +- src/messages/broker_heartbeat_response.rs | 2 +- src/messages/broker_registration_request.rs | 106 ++++++----- src/messages/broker_registration_response.rs | 2 +- .../consumer_group_describe_request.rs | 2 +- .../consumer_group_describe_response.rs | 2 +- .../consumer_group_heartbeat_request.rs | 2 +- .../consumer_group_heartbeat_response.rs | 2 +- src/messages/consumer_protocol_assignment.rs | 44 +++-- .../consumer_protocol_subscription.rs | 48 +++-- src/messages/controlled_shutdown_request.rs | 2 +- src/messages/controlled_shutdown_response.rs | 2 +- .../controller_registration_request.rs | 106 ++++++----- .../controller_registration_response.rs | 2 +- src/messages/create_acls_request.rs | 2 +- src/messages/create_acls_response.rs | 2 +- .../create_delegation_token_request.rs | 2 +- .../create_delegation_token_response.rs | 2 +- src/messages/create_partitions_request.rs | 60 +++--- src/messages/create_partitions_response.rs | 2 +- src/messages/create_topics_request.rs | 172 ++++++++++-------- src/messages/create_topics_response.rs | 70 +++---- src/messages/default_principal_data.rs | 2 +- src/messages/delete_acls_request.rs | 2 +- src/messages/delete_acls_response.rs | 2 +- src/messages/delete_groups_request.rs | 2 +- src/messages/delete_groups_response.rs | 58 +++--- src/messages/delete_records_request.rs | 2 +- src/messages/delete_records_response.rs | 112 +++++++----- src/messages/delete_topics_request.rs | 2 +- src/messages/delete_topics_response.rs | 62 ++++--- src/messages/describe_acls_request.rs | 2 +- src/messages/describe_acls_response.rs | 2 +- .../describe_client_quotas_request.rs | 2 +- .../describe_client_quotas_response.rs | 2 +- src/messages/describe_cluster_request.rs | 2 +- src/messages/describe_cluster_response.rs | 58 +++--- src/messages/describe_configs_request.rs | 2 +- src/messages/describe_configs_response.rs | 2 +- .../describe_delegation_token_request.rs | 2 +- .../describe_delegation_token_response.rs | 2 +- src/messages/describe_groups_request.rs | 2 +- src/messages/describe_groups_response.rs | 2 +- src/messages/describe_log_dirs_request.rs | 58 +++--- src/messages/describe_log_dirs_response.rs | 2 +- src/messages/describe_producers_request.rs | 2 +- src/messages/describe_producers_response.rs | 2 +- src/messages/describe_quorum_request.rs | 2 +- src/messages/describe_quorum_response.rs | 2 +- .../describe_topic_partitions_request.rs | 2 +- .../describe_topic_partitions_response.rs | 62 ++++--- src/messages/describe_transactions_request.rs | 2 +- .../describe_transactions_response.rs | 51 ++++-- ...describe_user_scram_credentials_request.rs | 2 +- ...escribe_user_scram_credentials_response.rs | 2 +- src/messages/elect_leaders_request.rs | 58 +++--- src/messages/elect_leaders_response.rs | 2 +- src/messages/end_quorum_epoch_request.rs | 2 +- src/messages/end_quorum_epoch_response.rs | 2 +- src/messages/end_txn_request.rs | 2 +- src/messages/end_txn_response.rs | 2 +- src/messages/envelope_request.rs | 2 +- src/messages/envelope_response.rs | 2 +- .../expire_delegation_token_request.rs | 2 +- .../expire_delegation_token_response.rs | 2 +- src/messages/fetch_request.rs | 2 +- src/messages/fetch_response.rs | 62 ++++--- src/messages/fetch_snapshot_request.rs | 2 +- src/messages/fetch_snapshot_response.rs | 2 +- src/messages/find_coordinator_request.rs | 2 +- src/messages/find_coordinator_response.rs | 2 +- .../get_telemetry_subscriptions_request.rs | 2 +- .../get_telemetry_subscriptions_response.rs | 2 +- src/messages/heartbeat_request.rs | 2 +- src/messages/heartbeat_response.rs | 2 +- .../incremental_alter_configs_request.rs | 2 +- .../incremental_alter_configs_response.rs | 2 +- src/messages/init_producer_id_request.rs | 2 +- src/messages/init_producer_id_response.rs | 2 +- src/messages/join_group_request.rs | 58 +++--- src/messages/join_group_response.rs | 2 +- src/messages/k_raft_version_record.rs | 2 +- src/messages/leader_and_isr_request.rs | 2 +- src/messages/leader_and_isr_response.rs | 55 +++--- src/messages/leader_change_message.rs | 2 +- src/messages/leave_group_request.rs | 2 +- src/messages/leave_group_response.rs | 2 +- .../list_client_metrics_resources_request.rs | 2 +- .../list_client_metrics_resources_response.rs | 2 +- src/messages/list_groups_request.rs | 2 +- src/messages/list_groups_response.rs | 2 +- src/messages/list_offsets_request.rs | 2 +- src/messages/list_offsets_response.rs | 2 +- .../list_partition_reassignments_request.rs | 2 +- .../list_partition_reassignments_response.rs | 2 +- src/messages/list_transactions_request.rs | 2 +- src/messages/list_transactions_response.rs | 2 +- src/messages/metadata_request.rs | 2 +- src/messages/metadata_response.rs | 122 +++++++------ src/messages/offset_commit_request.rs | 2 +- src/messages/offset_commit_response.rs | 2 +- src/messages/offset_delete_request.rs | 44 +++-- src/messages/offset_delete_response.rs | 93 ++++++---- src/messages/offset_fetch_request.rs | 2 +- src/messages/offset_fetch_response.rs | 2 +- .../offset_for_leader_epoch_request.rs | 58 +++--- .../offset_for_leader_epoch_response.rs | 58 +++--- src/messages/produce_request.rs | 58 +++--- src/messages/produce_response.rs | 118 ++++++------ src/messages/push_telemetry_request.rs | 2 +- src/messages/push_telemetry_response.rs | 2 +- .../renew_delegation_token_request.rs | 2 +- .../renew_delegation_token_response.rs | 2 +- src/messages/request_header.rs | 2 +- src/messages/response_header.rs | 2 +- src/messages/sasl_authenticate_request.rs | 2 +- src/messages/sasl_authenticate_response.rs | 2 +- src/messages/sasl_handshake_request.rs | 2 +- src/messages/sasl_handshake_response.rs | 2 +- src/messages/snapshot_footer_record.rs | 2 +- src/messages/snapshot_header_record.rs | 2 +- src/messages/stop_replica_request.rs | 2 +- src/messages/stop_replica_response.rs | 2 +- src/messages/sync_group_request.rs | 2 +- src/messages/sync_group_response.rs | 2 +- src/messages/txn_offset_commit_request.rs | 2 +- src/messages/txn_offset_commit_response.rs | 2 +- src/messages/unregister_broker_request.rs | 2 +- src/messages/unregister_broker_response.rs | 2 +- src/messages/update_features_request.rs | 58 +++--- src/messages/update_features_response.rs | 56 +++--- src/messages/update_metadata_request.rs | 2 +- src/messages/update_metadata_response.rs | 2 +- src/messages/vote_request.rs | 2 +- src/messages/vote_response.rs | 2 +- src/messages/voters_record.rs | 53 +++--- src/messages/write_txn_markers_request.rs | 2 +- src/messages/write_txn_markers_response.rs | 2 +- tests/all_tests/produce_fetch.rs | 38 ++-- 163 files changed, 1679 insertions(+), 1266 deletions(-) diff --git a/src/messages/add_offsets_to_txn_request.rs b/src/messages/add_offsets_to_txn_request.rs index f1e8f7c..5f271ae 100644 --- a/src/messages/add_offsets_to_txn_request.rs +++ b/src/messages/add_offsets_to_txn_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/add_offsets_to_txn_response.rs b/src/messages/add_offsets_to_txn_response.rs index 70e84e0..06e0709 100644 --- a/src/messages/add_offsets_to_txn_response.rs +++ b/src/messages/add_offsets_to_txn_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/add_partitions_to_txn_request.rs b/src/messages/add_partitions_to_txn_request.rs index 5759fae..fc61957 100644 --- a/src/messages/add_partitions_to_txn_request.rs +++ b/src/messages/add_partitions_to_txn_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 @@ -24,7 +24,7 @@ pub struct AddPartitionsToTxnRequest { /// List of transactions to add partitions to. /// /// Supported API versions: 4-5 - pub transactions: indexmap::IndexMap, + pub transactions: Vec, /// The transactional id corresponding to the transaction. /// @@ -44,7 +44,7 @@ pub struct AddPartitionsToTxnRequest { /// The partitions to add to the transaction. /// /// Supported API versions: 0-3 - pub v3_and_below_topics: indexmap::IndexMap, + pub v3_and_below_topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -56,10 +56,7 @@ impl AddPartitionsToTxnRequest { /// List of transactions to add partitions to. /// /// Supported API versions: 4-5 - pub fn with_transactions( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_transactions(mut self, value: Vec) -> Self { self.transactions = value; self } @@ -95,10 +92,7 @@ impl AddPartitionsToTxnRequest { /// The partitions to add to the transaction. /// /// Supported API versions: 0-3 - pub fn with_v3_and_below_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_v3_and_below_topics(mut self, value: Vec) -> Self { self.v3_and_below_topics = value; self } @@ -319,6 +313,11 @@ impl Message for AddPartitionsToTxnRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AddPartitionsToTxnTopic { + /// The name of the topic. + /// + /// Supported API versions: 0-5 + pub name: super::TopicName, + /// The partition indexes to add to the transaction /// /// Supported API versions: 0-5 @@ -329,6 +328,15 @@ pub struct AddPartitionsToTxnTopic { } impl AddPartitionsToTxnTopic { + /// Sets `name` to the passed value. + /// + /// The name of the topic. + /// + /// Supported API versions: 0-5 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partitions` to the passed value. /// /// The partition indexes to add to the transaction @@ -351,13 +359,12 @@ impl AddPartitionsToTxnTopic { } #[cfg(feature = "client")] -impl MapEncodable for AddPartitionsToTxnTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AddPartitionsToTxnTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 3 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 3 { types::CompactArray(types::Int32).encode(buf, &self.partitions)?; @@ -378,12 +385,12 @@ impl MapEncodable for AddPartitionsToTxnTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 3 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 3 { total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?; @@ -407,10 +414,9 @@ impl MapEncodable for AddPartitionsToTxnTopic { } #[cfg(feature = "broker")] -impl MapDecodable for AddPartitionsToTxnTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 3 { +impl Decodable for AddPartitionsToTxnTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 3 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -430,19 +436,18 @@ impl MapDecodable for AddPartitionsToTxnTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + partitions, + unknown_tagged_fields, + }) } } impl Default for AddPartitionsToTxnTopic { fn default() -> Self { Self { + name: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -458,6 +463,11 @@ impl Message for AddPartitionsToTxnTopic { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AddPartitionsToTxnTransaction { + /// The transactional id corresponding to the transaction. + /// + /// Supported API versions: 4-5 + pub transactional_id: super::TransactionalId, + /// Current producer id in use by the transactional id. /// /// Supported API versions: 4-5 @@ -476,13 +486,22 @@ pub struct AddPartitionsToTxnTransaction { /// The partitions to add to the transaction. /// /// Supported API versions: 4-5 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl AddPartitionsToTxnTransaction { + /// Sets `transactional_id` to the passed value. + /// + /// The transactional id corresponding to the transaction. + /// + /// Supported API versions: 4-5 + pub fn with_transactional_id(mut self, value: super::TransactionalId) -> Self { + self.transactional_id = value; + self + } /// Sets `producer_id` to the passed value. /// /// Current producer id in use by the transactional id. @@ -515,10 +534,7 @@ impl AddPartitionsToTxnTransaction { /// The partitions to add to the transaction. /// /// Supported API versions: 4-5 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -535,13 +551,12 @@ impl AddPartitionsToTxnTransaction { } #[cfg(feature = "client")] -impl MapEncodable for AddPartitionsToTxnTransaction { - type Key = super::TransactionalId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AddPartitionsToTxnTransaction { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 4 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.transactional_id)?; } else { - if !key.is_empty() { + if !self.transactional_id.is_empty() { bail!("failed to encode"); } } @@ -587,12 +602,12 @@ impl MapEncodable for AddPartitionsToTxnTransaction { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 4 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.transactional_id)?; } else { - if !key.is_empty() { + if !self.transactional_id.is_empty() { bail!("failed to encode"); } } @@ -642,10 +657,9 @@ impl MapEncodable for AddPartitionsToTxnTransaction { } #[cfg(feature = "broker")] -impl MapDecodable for AddPartitionsToTxnTransaction { - type Key = super::TransactionalId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 4 { +impl Decodable for AddPartitionsToTxnTransaction { + fn decode(buf: &mut B, version: i16) -> Result { + let transactional_id = if version >= 4 { types::CompactString.decode(buf)? } else { Default::default() @@ -680,22 +694,21 @@ impl MapDecodable for AddPartitionsToTxnTransaction { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - producer_id, - producer_epoch, - verify_only, - topics, - unknown_tagged_fields, - }, - )) + Ok(Self { + transactional_id, + producer_id, + producer_epoch, + verify_only, + topics, + unknown_tagged_fields, + }) } } impl Default for AddPartitionsToTxnTransaction { fn default() -> Self { Self { + transactional_id: Default::default(), producer_id: (0).into(), producer_epoch: 0, verify_only: false, diff --git a/src/messages/add_partitions_to_txn_response.rs b/src/messages/add_partitions_to_txn_response.rs index b8c9691..de1b99e 100644 --- a/src/messages/add_partitions_to_txn_response.rs +++ b/src/messages/add_partitions_to_txn_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AddPartitionsToTxnPartitionResult { + /// The partition indexes. + /// + /// Supported API versions: 0-5 + pub partition_index: i32, + /// The response error code. /// /// Supported API versions: 0-5 @@ -31,6 +36,15 @@ pub struct AddPartitionsToTxnPartitionResult { } impl AddPartitionsToTxnPartitionResult { + /// Sets `partition_index` to the passed value. + /// + /// The partition indexes. + /// + /// Supported API versions: 0-5 + pub fn with_partition_index(mut self, value: i32) -> Self { + self.partition_index = value; + self + } /// Sets `partition_error_code` to the passed value. /// /// The response error code. @@ -53,10 +67,9 @@ impl AddPartitionsToTxnPartitionResult { } #[cfg(feature = "broker")] -impl MapEncodable for AddPartitionsToTxnPartitionResult { - type Key = i32; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for AddPartitionsToTxnPartitionResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.partition_index)?; types::Int16.encode(buf, &self.partition_error_code)?; if version >= 3 { let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -72,9 +85,9 @@ impl MapEncodable for AddPartitionsToTxnPartitionResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.partition_index)?; total_size += types::Int16.compute_size(&self.partition_error_code)?; if version >= 3 { let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -93,10 +106,9 @@ impl MapEncodable for AddPartitionsToTxnPartitionResult { } #[cfg(feature = "client")] -impl MapDecodable for AddPartitionsToTxnPartitionResult { - type Key = i32; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for AddPartitionsToTxnPartitionResult { + fn decode(buf: &mut B, version: i16) -> Result { + let partition_index = types::Int32.decode(buf)?; let partition_error_code = types::Int16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); if version >= 3 { @@ -108,19 +120,18 @@ impl MapDecodable for AddPartitionsToTxnPartitionResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partition_error_code, - unknown_tagged_fields, - }, - )) + Ok(Self { + partition_index, + partition_error_code, + unknown_tagged_fields, + }) } } impl Default for AddPartitionsToTxnPartitionResult { fn default() -> Self { Self { + partition_index: 0, partition_error_code: 0, unknown_tagged_fields: BTreeMap::new(), } @@ -149,14 +160,12 @@ pub struct AddPartitionsToTxnResponse { /// Results categorized by transactional ID. /// /// Supported API versions: 4-5 - pub results_by_transaction: - indexmap::IndexMap, + pub results_by_transaction: Vec, /// The results for each topic. /// /// Supported API versions: 0-3 - pub results_by_topic_v3_and_below: - indexmap::IndexMap, + pub results_by_topic_v3_and_below: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -186,10 +195,7 @@ impl AddPartitionsToTxnResponse { /// Results categorized by transactional ID. /// /// Supported API versions: 4-5 - pub fn with_results_by_transaction( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_results_by_transaction(mut self, value: Vec) -> Self { self.results_by_transaction = value; self } @@ -200,7 +206,7 @@ impl AddPartitionsToTxnResponse { /// Supported API versions: 0-3 pub fn with_results_by_topic_v3_and_below( mut self, - value: indexmap::IndexMap, + value: Vec, ) -> Self { self.results_by_topic_v3_and_below = value; self @@ -366,25 +372,36 @@ impl Message for AddPartitionsToTxnResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AddPartitionsToTxnResult { + /// The transactional id corresponding to the transaction. + /// + /// Supported API versions: 4-5 + pub transactional_id: super::TransactionalId, + /// The results for each topic. /// /// Supported API versions: 4-5 - pub topic_results: indexmap::IndexMap, + pub topic_results: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl AddPartitionsToTxnResult { + /// Sets `transactional_id` to the passed value. + /// + /// The transactional id corresponding to the transaction. + /// + /// Supported API versions: 4-5 + pub fn with_transactional_id(mut self, value: super::TransactionalId) -> Self { + self.transactional_id = value; + self + } /// Sets `topic_results` to the passed value. /// /// The results for each topic. /// /// Supported API versions: 4-5 - pub fn with_topic_results( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topic_results(mut self, value: Vec) -> Self { self.topic_results = value; self } @@ -401,13 +418,12 @@ impl AddPartitionsToTxnResult { } #[cfg(feature = "broker")] -impl MapEncodable for AddPartitionsToTxnResult { - type Key = super::TransactionalId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AddPartitionsToTxnResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 4 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.transactional_id)?; } else { - if !key.is_empty() { + if !self.transactional_id.is_empty() { bail!("failed to encode"); } } @@ -432,12 +448,12 @@ impl MapEncodable for AddPartitionsToTxnResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 4 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.transactional_id)?; } else { - if !key.is_empty() { + if !self.transactional_id.is_empty() { bail!("failed to encode"); } } @@ -466,10 +482,9 @@ impl MapEncodable for AddPartitionsToTxnResult { } #[cfg(feature = "client")] -impl MapDecodable for AddPartitionsToTxnResult { - type Key = super::TransactionalId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 4 { +impl Decodable for AddPartitionsToTxnResult { + fn decode(buf: &mut B, version: i16) -> Result { + let transactional_id = if version >= 4 { types::CompactString.decode(buf)? } else { Default::default() @@ -489,19 +504,18 @@ impl MapDecodable for AddPartitionsToTxnResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - topic_results, - unknown_tagged_fields, - }, - )) + Ok(Self { + transactional_id, + topic_results, + unknown_tagged_fields, + }) } } impl Default for AddPartitionsToTxnResult { fn default() -> Self { Self { + transactional_id: Default::default(), topic_results: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -517,16 +531,30 @@ impl Message for AddPartitionsToTxnResult { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AddPartitionsToTxnTopicResult { + /// The topic name. + /// + /// Supported API versions: 0-5 + pub name: super::TopicName, + /// The results for each partition /// /// Supported API versions: 0-5 - pub results_by_partition: indexmap::IndexMap, + pub results_by_partition: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl AddPartitionsToTxnTopicResult { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-5 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `results_by_partition` to the passed value. /// /// The results for each partition @@ -534,7 +562,7 @@ impl AddPartitionsToTxnTopicResult { /// Supported API versions: 0-5 pub fn with_results_by_partition( mut self, - value: indexmap::IndexMap, + value: Vec, ) -> Self { self.results_by_partition = value; self @@ -552,13 +580,12 @@ impl AddPartitionsToTxnTopicResult { } #[cfg(feature = "broker")] -impl MapEncodable for AddPartitionsToTxnTopicResult { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AddPartitionsToTxnTopicResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 3 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 3 { types::CompactArray(types::Struct { version }) @@ -580,12 +607,12 @@ impl MapEncodable for AddPartitionsToTxnTopicResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 3 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 3 { total_size += types::CompactArray(types::Struct { version }) @@ -611,10 +638,9 @@ impl MapEncodable for AddPartitionsToTxnTopicResult { } #[cfg(feature = "client")] -impl MapDecodable for AddPartitionsToTxnTopicResult { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 3 { +impl Decodable for AddPartitionsToTxnTopicResult { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 3 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -634,19 +660,18 @@ impl MapDecodable for AddPartitionsToTxnTopicResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - results_by_partition, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + results_by_partition, + unknown_tagged_fields, + }) } } impl Default for AddPartitionsToTxnTopicResult { fn default() -> Self { Self { + name: Default::default(), results_by_partition: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/allocate_producer_ids_request.rs b/src/messages/allocate_producer_ids_request.rs index a3ed8d5..56ffcc2 100644 --- a/src/messages/allocate_producer_ids_request.rs +++ b/src/messages/allocate_producer_ids_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/allocate_producer_ids_response.rs b/src/messages/allocate_producer_ids_response.rs index e414486..f20a924 100644 --- a/src/messages/allocate_producer_ids_response.rs +++ b/src/messages/allocate_producer_ids_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/alter_client_quotas_request.rs b/src/messages/alter_client_quotas_request.rs index 817a7ba..2c7d81c 100644 --- a/src/messages/alter_client_quotas_request.rs +++ b/src/messages/alter_client_quotas_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/alter_client_quotas_response.rs b/src/messages/alter_client_quotas_response.rs index 4b7ebb8..49b085a 100644 --- a/src/messages/alter_client_quotas_response.rs +++ b/src/messages/alter_client_quotas_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/alter_configs_request.rs b/src/messages/alter_configs_request.rs index e4261c6..b0c5e7a 100644 --- a/src/messages/alter_configs_request.rs +++ b/src/messages/alter_configs_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 @@ -173,7 +173,7 @@ pub struct AlterConfigsResource { /// The configurations. /// /// Supported API versions: 0-2 - pub configs: indexmap::IndexMap, + pub configs: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -203,7 +203,7 @@ impl AlterConfigsResource { /// The configurations. /// /// Supported API versions: 0-2 - pub fn with_configs(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_configs(mut self, value: Vec) -> Self { self.configs = value; self } @@ -330,6 +330,11 @@ impl Message for AlterConfigsResource { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AlterableConfig { + /// The configuration key name. + /// + /// Supported API versions: 0-2 + pub name: StrBytes, + /// The value to set for the configuration key. /// /// Supported API versions: 0-2 @@ -340,6 +345,15 @@ pub struct AlterableConfig { } impl AlterableConfig { + /// Sets `name` to the passed value. + /// + /// The configuration key name. + /// + /// Supported API versions: 0-2 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `value` to the passed value. /// /// The value to set for the configuration key. @@ -362,13 +376,12 @@ impl AlterableConfig { } #[cfg(feature = "client")] -impl MapEncodable for AlterableConfig { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AlterableConfig { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 2 { types::CompactString.encode(buf, &self.value)?; @@ -389,12 +402,12 @@ impl MapEncodable for AlterableConfig { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 2 { total_size += types::CompactString.compute_size(&self.value)?; @@ -418,10 +431,9 @@ impl MapEncodable for AlterableConfig { } #[cfg(feature = "broker")] -impl MapDecodable for AlterableConfig { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for AlterableConfig { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -441,19 +453,18 @@ impl MapDecodable for AlterableConfig { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - value, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + value, + unknown_tagged_fields, + }) } } impl Default for AlterableConfig { fn default() -> Self { Self { + name: Default::default(), value: Some(Default::default()), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/alter_configs_response.rs b/src/messages/alter_configs_response.rs index 3d7da19..3ec5133 100644 --- a/src/messages/alter_configs_response.rs +++ b/src/messages/alter_configs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/alter_partition_reassignments_request.rs b/src/messages/alter_partition_reassignments_request.rs index d192209..bdbb7e1 100644 --- a/src/messages/alter_partition_reassignments_request.rs +++ b/src/messages/alter_partition_reassignments_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/alter_partition_reassignments_response.rs b/src/messages/alter_partition_reassignments_response.rs index 3b5e5de..c30f652 100644 --- a/src/messages/alter_partition_reassignments_response.rs +++ b/src/messages/alter_partition_reassignments_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/alter_partition_request.rs b/src/messages/alter_partition_request.rs index c33536a..72f047a 100644 --- a/src/messages/alter_partition_request.rs +++ b/src/messages/alter_partition_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/alter_partition_response.rs b/src/messages/alter_partition_response.rs index fb9e011..be99a42 100644 --- a/src/messages/alter_partition_response.rs +++ b/src/messages/alter_partition_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/alter_replica_log_dirs_request.rs b/src/messages/alter_replica_log_dirs_request.rs index fb5ef8a..0e27819 100644 --- a/src/messages/alter_replica_log_dirs_request.rs +++ b/src/messages/alter_replica_log_dirs_request.rs @@ -14,32 +14,43 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AlterReplicaLogDir { + /// The absolute directory path. + /// + /// Supported API versions: 0-2 + pub path: StrBytes, + /// The topics to add to the directory. /// /// Supported API versions: 0-2 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl AlterReplicaLogDir { + /// Sets `path` to the passed value. + /// + /// The absolute directory path. + /// + /// Supported API versions: 0-2 + pub fn with_path(mut self, value: StrBytes) -> Self { + self.path = value; + self + } /// Sets `topics` to the passed value. /// /// The topics to add to the directory. /// /// Supported API versions: 0-2 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -56,13 +67,12 @@ impl AlterReplicaLogDir { } #[cfg(feature = "client")] -impl MapEncodable for AlterReplicaLogDir { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AlterReplicaLogDir { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.path)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.path)?; } if version >= 2 { types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?; @@ -83,12 +93,12 @@ impl MapEncodable for AlterReplicaLogDir { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.path)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.path)?; } if version >= 2 { total_size += @@ -113,10 +123,9 @@ impl MapEncodable for AlterReplicaLogDir { } #[cfg(feature = "broker")] -impl MapDecodable for AlterReplicaLogDir { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for AlterReplicaLogDir { + fn decode(buf: &mut B, version: i16) -> Result { + let path = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -136,19 +145,18 @@ impl MapDecodable for AlterReplicaLogDir { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - topics, - unknown_tagged_fields, - }, - )) + Ok(Self { + path, + topics, + unknown_tagged_fields, + }) } } impl Default for AlterReplicaLogDir { fn default() -> Self { Self { + path: Default::default(), topics: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -164,6 +172,11 @@ impl Message for AlterReplicaLogDir { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct AlterReplicaLogDirTopic { + /// The topic name. + /// + /// Supported API versions: 0-2 + pub name: super::TopicName, + /// The partition indexes. /// /// Supported API versions: 0-2 @@ -174,6 +187,15 @@ pub struct AlterReplicaLogDirTopic { } impl AlterReplicaLogDirTopic { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-2 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partitions` to the passed value. /// /// The partition indexes. @@ -196,13 +218,12 @@ impl AlterReplicaLogDirTopic { } #[cfg(feature = "client")] -impl MapEncodable for AlterReplicaLogDirTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for AlterReplicaLogDirTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 2 { types::CompactArray(types::Int32).encode(buf, &self.partitions)?; @@ -223,12 +244,12 @@ impl MapEncodable for AlterReplicaLogDirTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 2 { total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?; @@ -252,10 +273,9 @@ impl MapEncodable for AlterReplicaLogDirTopic { } #[cfg(feature = "broker")] -impl MapDecodable for AlterReplicaLogDirTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for AlterReplicaLogDirTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -275,19 +295,18 @@ impl MapDecodable for AlterReplicaLogDirTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + partitions, + unknown_tagged_fields, + }) } } impl Default for AlterReplicaLogDirTopic { fn default() -> Self { Self { + name: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -306,7 +325,7 @@ pub struct AlterReplicaLogDirsRequest { /// The alterations to make for each directory. /// /// Supported API versions: 0-2 - pub dirs: indexmap::IndexMap, + pub dirs: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -318,7 +337,7 @@ impl AlterReplicaLogDirsRequest { /// The alterations to make for each directory. /// /// Supported API versions: 0-2 - pub fn with_dirs(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_dirs(mut self, value: Vec) -> Self { self.dirs = value; self } diff --git a/src/messages/alter_replica_log_dirs_response.rs b/src/messages/alter_replica_log_dirs_response.rs index 4c025fa..12d0842 100644 --- a/src/messages/alter_replica_log_dirs_response.rs +++ b/src/messages/alter_replica_log_dirs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/alter_user_scram_credentials_request.rs b/src/messages/alter_user_scram_credentials_request.rs index ecaddb7..66ee251 100644 --- a/src/messages/alter_user_scram_credentials_request.rs +++ b/src/messages/alter_user_scram_credentials_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/alter_user_scram_credentials_response.rs b/src/messages/alter_user_scram_credentials_response.rs index 05d3280..d4dfb7c 100644 --- a/src/messages/alter_user_scram_credentials_response.rs +++ b/src/messages/alter_user_scram_credentials_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/api_versions_request.rs b/src/messages/api_versions_request.rs index b48aba2..34f55f5 100644 --- a/src/messages/api_versions_request.rs +++ b/src/messages/api_versions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/api_versions_response.rs b/src/messages/api_versions_response.rs index 1438326..3bc2178 100644 --- a/src/messages/api_versions_response.rs +++ b/src/messages/api_versions_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ApiVersion { + /// The API index. + /// + /// Supported API versions: 0-3 + pub api_key: i16, + /// The minimum supported version, inclusive. /// /// Supported API versions: 0-3 @@ -36,6 +41,15 @@ pub struct ApiVersion { } impl ApiVersion { + /// Sets `api_key` to the passed value. + /// + /// The API index. + /// + /// Supported API versions: 0-3 + pub fn with_api_key(mut self, value: i16) -> Self { + self.api_key = value; + self + } /// Sets `min_version` to the passed value. /// /// The minimum supported version, inclusive. @@ -67,10 +81,9 @@ impl ApiVersion { } #[cfg(feature = "broker")] -impl MapEncodable for ApiVersion { - type Key = i16; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int16.encode(buf, key)?; +impl Encodable for ApiVersion { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int16.encode(buf, &self.api_key)?; types::Int16.encode(buf, &self.min_version)?; types::Int16.encode(buf, &self.max_version)?; if version >= 3 { @@ -87,9 +100,9 @@ impl MapEncodable for ApiVersion { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int16.compute_size(key)?; + total_size += types::Int16.compute_size(&self.api_key)?; total_size += types::Int16.compute_size(&self.min_version)?; total_size += types::Int16.compute_size(&self.max_version)?; if version >= 3 { @@ -109,10 +122,9 @@ impl MapEncodable for ApiVersion { } #[cfg(feature = "client")] -impl MapDecodable for ApiVersion { - type Key = i16; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int16.decode(buf)?; +impl Decodable for ApiVersion { + fn decode(buf: &mut B, version: i16) -> Result { + let api_key = types::Int16.decode(buf)?; let min_version = types::Int16.decode(buf)?; let max_version = types::Int16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -125,20 +137,19 @@ impl MapDecodable for ApiVersion { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - min_version, - max_version, - unknown_tagged_fields, - }, - )) + Ok(Self { + api_key, + min_version, + max_version, + unknown_tagged_fields, + }) } } impl Default for ApiVersion { fn default() -> Self { Self { + api_key: 0, min_version: 0, max_version: 0, unknown_tagged_fields: BTreeMap::new(), @@ -163,7 +174,7 @@ pub struct ApiVersionsResponse { /// The APIs supported by the broker. /// /// Supported API versions: 0-3 - pub api_keys: indexmap::IndexMap, + pub api_keys: Vec, /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota. /// @@ -173,7 +184,7 @@ pub struct ApiVersionsResponse { /// Features supported by the broker. /// /// Supported API versions: 3 - pub supported_features: indexmap::IndexMap, + pub supported_features: Vec, /// The monotonically increasing epoch for the finalized features information. Valid values are >= 0. A value of -1 is special and represents unknown epoch. /// @@ -183,7 +194,7 @@ pub struct ApiVersionsResponse { /// List of cluster-wide finalized features. The information is valid only if FinalizedFeaturesEpoch >= 0. /// /// Supported API versions: 3 - pub finalized_features: indexmap::IndexMap, + pub finalized_features: Vec, /// Set by a KRaft controller if the required configurations for ZK migration are present /// @@ -209,7 +220,7 @@ impl ApiVersionsResponse { /// The APIs supported by the broker. /// /// Supported API versions: 0-3 - pub fn with_api_keys(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_api_keys(mut self, value: Vec) -> Self { self.api_keys = value; self } @@ -227,10 +238,7 @@ impl ApiVersionsResponse { /// Features supported by the broker. /// /// Supported API versions: 3 - pub fn with_supported_features( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_supported_features(mut self, value: Vec) -> Self { self.supported_features = value; self } @@ -248,10 +256,7 @@ impl ApiVersionsResponse { /// List of cluster-wide finalized features. The information is valid only if FinalizedFeaturesEpoch >= 0. /// /// Supported API versions: 3 - pub fn with_finalized_features( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_finalized_features(mut self, value: Vec) -> Self { self.finalized_features = value; self } @@ -539,6 +544,11 @@ impl Message for ApiVersionsResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct FinalizedFeatureKey { + /// The name of the feature. + /// + /// Supported API versions: 3 + pub name: StrBytes, + /// The cluster-wide finalized max version level for the feature. /// /// Supported API versions: 3 @@ -554,6 +564,15 @@ pub struct FinalizedFeatureKey { } impl FinalizedFeatureKey { + /// Sets `name` to the passed value. + /// + /// The name of the feature. + /// + /// Supported API versions: 3 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `max_version_level` to the passed value. /// /// The cluster-wide finalized max version level for the feature. @@ -585,13 +604,12 @@ impl FinalizedFeatureKey { } #[cfg(feature = "broker")] -impl MapEncodable for FinalizedFeatureKey { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for FinalizedFeatureKey { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 3 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - if !key.is_empty() { + if !self.name.is_empty() { bail!("failed to encode"); } } @@ -623,12 +641,12 @@ impl MapEncodable for FinalizedFeatureKey { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 3 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - if !key.is_empty() { + if !self.name.is_empty() { bail!("failed to encode"); } } @@ -663,10 +681,9 @@ impl MapEncodable for FinalizedFeatureKey { } #[cfg(feature = "client")] -impl MapDecodable for FinalizedFeatureKey { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 3 { +impl Decodable for FinalizedFeatureKey { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 3 { types::CompactString.decode(buf)? } else { Default::default() @@ -691,20 +708,19 @@ impl MapDecodable for FinalizedFeatureKey { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - max_version_level, - min_version_level, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + max_version_level, + min_version_level, + unknown_tagged_fields, + }) } } impl Default for FinalizedFeatureKey { fn default() -> Self { Self { + name: Default::default(), max_version_level: 0, min_version_level: 0, unknown_tagged_fields: BTreeMap::new(), @@ -721,6 +737,11 @@ impl Message for FinalizedFeatureKey { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct SupportedFeatureKey { + /// The name of the feature. + /// + /// Supported API versions: 3 + pub name: StrBytes, + /// The minimum supported version for the feature. /// /// Supported API versions: 3 @@ -736,6 +757,15 @@ pub struct SupportedFeatureKey { } impl SupportedFeatureKey { + /// Sets `name` to the passed value. + /// + /// The name of the feature. + /// + /// Supported API versions: 3 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `min_version` to the passed value. /// /// The minimum supported version for the feature. @@ -767,13 +797,12 @@ impl SupportedFeatureKey { } #[cfg(feature = "broker")] -impl MapEncodable for SupportedFeatureKey { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for SupportedFeatureKey { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 3 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - if !key.is_empty() { + if !self.name.is_empty() { bail!("failed to encode"); } } @@ -805,12 +834,12 @@ impl MapEncodable for SupportedFeatureKey { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 3 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - if !key.is_empty() { + if !self.name.is_empty() { bail!("failed to encode"); } } @@ -845,10 +874,9 @@ impl MapEncodable for SupportedFeatureKey { } #[cfg(feature = "client")] -impl MapDecodable for SupportedFeatureKey { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 3 { +impl Decodable for SupportedFeatureKey { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 3 { types::CompactString.decode(buf)? } else { Default::default() @@ -873,20 +901,19 @@ impl MapDecodable for SupportedFeatureKey { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - min_version, - max_version, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + min_version, + max_version, + unknown_tagged_fields, + }) } } impl Default for SupportedFeatureKey { fn default() -> Self { Self { + name: Default::default(), min_version: 0, max_version: 0, unknown_tagged_fields: BTreeMap::new(), diff --git a/src/messages/assign_replicas_to_dirs_request.rs b/src/messages/assign_replicas_to_dirs_request.rs index b868b84..3272a0b 100644 --- a/src/messages/assign_replicas_to_dirs_request.rs +++ b/src/messages/assign_replicas_to_dirs_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/assign_replicas_to_dirs_response.rs b/src/messages/assign_replicas_to_dirs_response.rs index e354a6a..d3ec448 100644 --- a/src/messages/assign_replicas_to_dirs_response.rs +++ b/src/messages/assign_replicas_to_dirs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/begin_quorum_epoch_request.rs b/src/messages/begin_quorum_epoch_request.rs index b39cf35..4464bb0 100644 --- a/src/messages/begin_quorum_epoch_request.rs +++ b/src/messages/begin_quorum_epoch_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/begin_quorum_epoch_response.rs b/src/messages/begin_quorum_epoch_response.rs index ad932a8..1cfbd9b 100644 --- a/src/messages/begin_quorum_epoch_response.rs +++ b/src/messages/begin_quorum_epoch_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/broker_heartbeat_request.rs b/src/messages/broker_heartbeat_request.rs index 48a9ba0..0206c0c 100644 --- a/src/messages/broker_heartbeat_request.rs +++ b/src/messages/broker_heartbeat_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/broker_heartbeat_response.rs b/src/messages/broker_heartbeat_response.rs index e37d7a7..4d1132d 100644 --- a/src/messages/broker_heartbeat_response.rs +++ b/src/messages/broker_heartbeat_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/broker_registration_request.rs b/src/messages/broker_registration_request.rs index f97537e..5900764 100644 --- a/src/messages/broker_registration_request.rs +++ b/src/messages/broker_registration_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 @@ -39,12 +39,12 @@ pub struct BrokerRegistrationRequest { /// The listeners of this broker /// /// Supported API versions: 0-3 - pub listeners: indexmap::IndexMap, + pub listeners: Vec, /// The features on this broker /// /// Supported API versions: 0-3 - pub features: indexmap::IndexMap, + pub features: Vec, /// The rack which this broker is in. /// @@ -103,7 +103,7 @@ impl BrokerRegistrationRequest { /// The listeners of this broker /// /// Supported API versions: 0-3 - pub fn with_listeners(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_listeners(mut self, value: Vec) -> Self { self.listeners = value; self } @@ -112,7 +112,7 @@ impl BrokerRegistrationRequest { /// The features on this broker /// /// Supported API versions: 0-3 - pub fn with_features(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_features(mut self, value: Vec) -> Self { self.features = value; self } @@ -308,6 +308,11 @@ impl Message for BrokerRegistrationRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Feature { + /// The feature name. + /// + /// Supported API versions: 0-3 + pub name: StrBytes, + /// The minimum supported feature level. /// /// Supported API versions: 0-3 @@ -323,6 +328,15 @@ pub struct Feature { } impl Feature { + /// Sets `name` to the passed value. + /// + /// The feature name. + /// + /// Supported API versions: 0-3 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `min_supported_version` to the passed value. /// /// The minimum supported feature level. @@ -354,10 +368,9 @@ impl Feature { } #[cfg(feature = "client")] -impl MapEncodable for Feature { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for Feature { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.name)?; types::Int16.encode(buf, &self.min_supported_version)?; types::Int16.encode(buf, &self.max_supported_version)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -372,9 +385,9 @@ impl MapEncodable for Feature { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::Int16.compute_size(&self.min_supported_version)?; total_size += types::Int16.compute_size(&self.max_supported_version)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -392,10 +405,9 @@ impl MapEncodable for Feature { } #[cfg(feature = "broker")] -impl MapDecodable for Feature { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for Feature { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::CompactString.decode(buf)?; let min_supported_version = types::Int16.decode(buf)?; let max_supported_version = types::Int16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -406,20 +418,19 @@ impl MapDecodable for Feature { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - min_supported_version, - max_supported_version, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + min_supported_version, + max_supported_version, + unknown_tagged_fields, + }) } } impl Default for Feature { fn default() -> Self { Self { + name: Default::default(), min_supported_version: 0, max_supported_version: 0, unknown_tagged_fields: BTreeMap::new(), @@ -436,6 +447,11 @@ impl Message for Feature { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Listener { + /// The name of the endpoint. + /// + /// Supported API versions: 0-3 + pub name: StrBytes, + /// The hostname. /// /// Supported API versions: 0-3 @@ -456,6 +472,15 @@ pub struct Listener { } impl Listener { + /// Sets `name` to the passed value. + /// + /// The name of the endpoint. + /// + /// Supported API versions: 0-3 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `host` to the passed value. /// /// The hostname. @@ -496,10 +521,9 @@ impl Listener { } #[cfg(feature = "client")] -impl MapEncodable for Listener { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for Listener { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.name)?; types::CompactString.encode(buf, &self.host)?; types::UInt16.encode(buf, &self.port)?; types::Int16.encode(buf, &self.security_protocol)?; @@ -515,9 +539,9 @@ impl MapEncodable for Listener { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::CompactString.compute_size(&self.host)?; total_size += types::UInt16.compute_size(&self.port)?; total_size += types::Int16.compute_size(&self.security_protocol)?; @@ -536,10 +560,9 @@ impl MapEncodable for Listener { } #[cfg(feature = "broker")] -impl MapDecodable for Listener { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for Listener { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::CompactString.decode(buf)?; let host = types::CompactString.decode(buf)?; let port = types::UInt16.decode(buf)?; let security_protocol = types::Int16.decode(buf)?; @@ -551,21 +574,20 @@ impl MapDecodable for Listener { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - host, - port, - security_protocol, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + host, + port, + security_protocol, + unknown_tagged_fields, + }) } } impl Default for Listener { fn default() -> Self { Self { + name: Default::default(), host: Default::default(), port: 0, security_protocol: 0, diff --git a/src/messages/broker_registration_response.rs b/src/messages/broker_registration_response.rs index a47a238..dbc2df4 100644 --- a/src/messages/broker_registration_response.rs +++ b/src/messages/broker_registration_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/consumer_group_describe_request.rs b/src/messages/consumer_group_describe_request.rs index 86910fd..ce1a2da 100644 --- a/src/messages/consumer_group_describe_request.rs +++ b/src/messages/consumer_group_describe_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/consumer_group_describe_response.rs b/src/messages/consumer_group_describe_response.rs index baccce2..90a88e8 100644 --- a/src/messages/consumer_group_describe_response.rs +++ b/src/messages/consumer_group_describe_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/consumer_group_heartbeat_request.rs b/src/messages/consumer_group_heartbeat_request.rs index 6c324ef..56f521e 100644 --- a/src/messages/consumer_group_heartbeat_request.rs +++ b/src/messages/consumer_group_heartbeat_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/consumer_group_heartbeat_response.rs b/src/messages/consumer_group_heartbeat_response.rs index e04cfd0..c69bfba 100644 --- a/src/messages/consumer_group_heartbeat_response.rs +++ b/src/messages/consumer_group_heartbeat_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/consumer_protocol_assignment.rs b/src/messages/consumer_protocol_assignment.rs index a4fabc7..69bf8b1 100644 --- a/src/messages/consumer_protocol_assignment.rs +++ b/src/messages/consumer_protocol_assignment.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 @@ -24,7 +24,7 @@ pub struct ConsumerProtocolAssignment { /// /// /// Supported API versions: 0-3 - pub assigned_partitions: indexmap::IndexMap, + pub assigned_partitions: Vec, /// /// @@ -38,10 +38,7 @@ impl ConsumerProtocolAssignment { /// /// /// Supported API versions: 0-3 - pub fn with_assigned_partitions( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_assigned_partitions(mut self, value: Vec) -> Self { self.assigned_partitions = value; self } @@ -102,6 +99,11 @@ impl Message for ConsumerProtocolAssignment { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicPartition { + /// + /// + /// Supported API versions: 0-3 + pub topic: super::TopicName, + /// /// /// Supported API versions: 0-3 @@ -109,6 +111,15 @@ pub struct TopicPartition { } impl TopicPartition { + /// Sets `topic` to the passed value. + /// + /// + /// + /// Supported API versions: 0-3 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// @@ -120,35 +131,34 @@ impl TopicPartition { } } -impl MapEncodable for TopicPartition { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::String.encode(buf, key)?; +impl Encodable for TopicPartition { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::String.encode(buf, &self.topic)?; types::Array(types::Int32).encode(buf, &self.partitions)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; total_size += types::Array(types::Int32).compute_size(&self.partitions)?; Ok(total_size) } } -impl MapDecodable for TopicPartition { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::String.decode(buf)?; +impl Decodable for TopicPartition { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = types::String.decode(buf)?; let partitions = types::Array(types::Int32).decode(buf)?; - Ok((key_field, Self { partitions })) + Ok(Self { topic, partitions }) } } impl Default for TopicPartition { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), } } diff --git a/src/messages/consumer_protocol_subscription.rs b/src/messages/consumer_protocol_subscription.rs index dcb3cf2..23ace1e 100644 --- a/src/messages/consumer_protocol_subscription.rs +++ b/src/messages/consumer_protocol_subscription.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 @@ -34,7 +34,7 @@ pub struct ConsumerProtocolSubscription { /// /// /// Supported API versions: 1-3 - pub owned_partitions: indexmap::IndexMap, + pub owned_partitions: Vec, /// /// @@ -71,10 +71,7 @@ impl ConsumerProtocolSubscription { /// /// /// Supported API versions: 1-3 - pub fn with_owned_partitions( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_owned_partitions(mut self, value: Vec) -> Self { self.owned_partitions = value; self } @@ -183,6 +180,11 @@ impl Message for ConsumerProtocolSubscription { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicPartition { + /// + /// + /// Supported API versions: 1-3 + pub topic: super::TopicName, + /// /// /// Supported API versions: 1-3 @@ -190,6 +192,15 @@ pub struct TopicPartition { } impl TopicPartition { + /// Sets `topic` to the passed value. + /// + /// + /// + /// Supported API versions: 1-3 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// @@ -201,13 +212,12 @@ impl TopicPartition { } } -impl MapEncodable for TopicPartition { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for TopicPartition { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 1 { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.topic)?; } else { - if !key.is_empty() { + if !self.topic.is_empty() { bail!("failed to encode"); } } @@ -221,12 +231,12 @@ impl MapEncodable for TopicPartition { Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 1 { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; } else { - if !key.is_empty() { + if !self.topic.is_empty() { bail!("failed to encode"); } } @@ -242,10 +252,9 @@ impl MapEncodable for TopicPartition { } } -impl MapDecodable for TopicPartition { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 1 { +impl Decodable for TopicPartition { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = if version >= 1 { types::String.decode(buf)? } else { Default::default() @@ -255,13 +264,14 @@ impl MapDecodable for TopicPartition { } else { Default::default() }; - Ok((key_field, Self { partitions })) + Ok(Self { topic, partitions }) } } impl Default for TopicPartition { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), } } diff --git a/src/messages/controlled_shutdown_request.rs b/src/messages/controlled_shutdown_request.rs index a0ec6e4..4ae3f88 100644 --- a/src/messages/controlled_shutdown_request.rs +++ b/src/messages/controlled_shutdown_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/controlled_shutdown_response.rs b/src/messages/controlled_shutdown_response.rs index 72062ad..e08747b 100644 --- a/src/messages/controlled_shutdown_response.rs +++ b/src/messages/controlled_shutdown_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/controller_registration_request.rs b/src/messages/controller_registration_request.rs index ef0f2c1..f85b376 100644 --- a/src/messages/controller_registration_request.rs +++ b/src/messages/controller_registration_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 @@ -39,12 +39,12 @@ pub struct ControllerRegistrationRequest { /// The listeners of this controller /// /// Supported API versions: 0 - pub listeners: indexmap::IndexMap, + pub listeners: Vec, /// The features on this controller /// /// Supported API versions: 0 - pub features: indexmap::IndexMap, + pub features: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -83,7 +83,7 @@ impl ControllerRegistrationRequest { /// The listeners of this controller /// /// Supported API versions: 0 - pub fn with_listeners(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_listeners(mut self, value: Vec) -> Self { self.listeners = value; self } @@ -92,7 +92,7 @@ impl ControllerRegistrationRequest { /// The features on this controller /// /// Supported API versions: 0 - pub fn with_features(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_features(mut self, value: Vec) -> Self { self.features = value; self } @@ -200,6 +200,11 @@ impl Message for ControllerRegistrationRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Feature { + /// The feature name. + /// + /// Supported API versions: 0 + pub name: StrBytes, + /// The minimum supported feature level. /// /// Supported API versions: 0 @@ -215,6 +220,15 @@ pub struct Feature { } impl Feature { + /// Sets `name` to the passed value. + /// + /// The feature name. + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `min_supported_version` to the passed value. /// /// The minimum supported feature level. @@ -246,10 +260,9 @@ impl Feature { } #[cfg(feature = "client")] -impl MapEncodable for Feature { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for Feature { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.name)?; types::Int16.encode(buf, &self.min_supported_version)?; types::Int16.encode(buf, &self.max_supported_version)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -264,9 +277,9 @@ impl MapEncodable for Feature { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::Int16.compute_size(&self.min_supported_version)?; total_size += types::Int16.compute_size(&self.max_supported_version)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -284,10 +297,9 @@ impl MapEncodable for Feature { } #[cfg(feature = "broker")] -impl MapDecodable for Feature { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for Feature { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::CompactString.decode(buf)?; let min_supported_version = types::Int16.decode(buf)?; let max_supported_version = types::Int16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -298,20 +310,19 @@ impl MapDecodable for Feature { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - min_supported_version, - max_supported_version, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + min_supported_version, + max_supported_version, + unknown_tagged_fields, + }) } } impl Default for Feature { fn default() -> Self { Self { + name: Default::default(), min_supported_version: 0, max_supported_version: 0, unknown_tagged_fields: BTreeMap::new(), @@ -328,6 +339,11 @@ impl Message for Feature { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Listener { + /// The name of the endpoint. + /// + /// Supported API versions: 0 + pub name: StrBytes, + /// The hostname. /// /// Supported API versions: 0 @@ -348,6 +364,15 @@ pub struct Listener { } impl Listener { + /// Sets `name` to the passed value. + /// + /// The name of the endpoint. + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `host` to the passed value. /// /// The hostname. @@ -388,10 +413,9 @@ impl Listener { } #[cfg(feature = "client")] -impl MapEncodable for Listener { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for Listener { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.name)?; types::CompactString.encode(buf, &self.host)?; types::UInt16.encode(buf, &self.port)?; types::Int16.encode(buf, &self.security_protocol)?; @@ -407,9 +431,9 @@ impl MapEncodable for Listener { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::CompactString.compute_size(&self.host)?; total_size += types::UInt16.compute_size(&self.port)?; total_size += types::Int16.compute_size(&self.security_protocol)?; @@ -428,10 +452,9 @@ impl MapEncodable for Listener { } #[cfg(feature = "broker")] -impl MapDecodable for Listener { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for Listener { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::CompactString.decode(buf)?; let host = types::CompactString.decode(buf)?; let port = types::UInt16.decode(buf)?; let security_protocol = types::Int16.decode(buf)?; @@ -443,21 +466,20 @@ impl MapDecodable for Listener { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - host, - port, - security_protocol, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + host, + port, + security_protocol, + unknown_tagged_fields, + }) } } impl Default for Listener { fn default() -> Self { Self { + name: Default::default(), host: Default::default(), port: 0, security_protocol: 0, diff --git a/src/messages/controller_registration_response.rs b/src/messages/controller_registration_response.rs index 5e2af9d..b315ad2 100644 --- a/src/messages/controller_registration_response.rs +++ b/src/messages/controller_registration_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/create_acls_request.rs b/src/messages/create_acls_request.rs index a7ed67d..8f5db7b 100644 --- a/src/messages/create_acls_request.rs +++ b/src/messages/create_acls_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/create_acls_response.rs b/src/messages/create_acls_response.rs index c5aa772..318a68f 100644 --- a/src/messages/create_acls_response.rs +++ b/src/messages/create_acls_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/create_delegation_token_request.rs b/src/messages/create_delegation_token_request.rs index 474957e..ee9a958 100644 --- a/src/messages/create_delegation_token_request.rs +++ b/src/messages/create_delegation_token_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/create_delegation_token_response.rs b/src/messages/create_delegation_token_response.rs index 0e653e2..1927571 100644 --- a/src/messages/create_delegation_token_response.rs +++ b/src/messages/create_delegation_token_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/create_partitions_request.rs b/src/messages/create_partitions_request.rs index d3be0ab..4fad7f1 100644 --- a/src/messages/create_partitions_request.rs +++ b/src/messages/create_partitions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 @@ -143,7 +143,7 @@ pub struct CreatePartitionsRequest { /// Each topic that we want to create new partitions inside. /// /// Supported API versions: 0-3 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// The time in ms to wait for the partitions to be created. /// @@ -165,10 +165,7 @@ impl CreatePartitionsRequest { /// Each topic that we want to create new partitions inside. /// /// Supported API versions: 0-3 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -301,6 +298,11 @@ impl Message for CreatePartitionsRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct CreatePartitionsTopic { + /// The topic name. + /// + /// Supported API versions: 0-3 + pub name: super::TopicName, + /// The new partition count. /// /// Supported API versions: 0-3 @@ -316,6 +318,15 @@ pub struct CreatePartitionsTopic { } impl CreatePartitionsTopic { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-3 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `count` to the passed value. /// /// The new partition count. @@ -347,13 +358,12 @@ impl CreatePartitionsTopic { } #[cfg(feature = "client")] -impl MapEncodable for CreatePartitionsTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for CreatePartitionsTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } types::Int32.encode(buf, &self.count)?; if version >= 2 { @@ -375,12 +385,12 @@ impl MapEncodable for CreatePartitionsTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } total_size += types::Int32.compute_size(&self.count)?; if version >= 2 { @@ -407,10 +417,9 @@ impl MapEncodable for CreatePartitionsTopic { } #[cfg(feature = "broker")] -impl MapDecodable for CreatePartitionsTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for CreatePartitionsTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -431,20 +440,19 @@ impl MapDecodable for CreatePartitionsTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - count, - assignments, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + count, + assignments, + unknown_tagged_fields, + }) } } impl Default for CreatePartitionsTopic { fn default() -> Self { Self { + name: Default::default(), count: 0, assignments: Some(Default::default()), unknown_tagged_fields: BTreeMap::new(), diff --git a/src/messages/create_partitions_response.rs b/src/messages/create_partitions_response.rs index 7f1ffe7..164b8c9 100644 --- a/src/messages/create_partitions_response.rs +++ b/src/messages/create_partitions_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/create_topics_request.rs b/src/messages/create_topics_request.rs index 75d7ad8..1c2a5ce 100644 --- a/src/messages/create_topics_request.rs +++ b/src/messages/create_topics_request.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-7 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct CreatableReplicaAssignment { + /// The partition index. + /// + /// Supported API versions: 0-7 + pub partition_index: i32, + /// The brokers to place the partition on. /// /// Supported API versions: 0-7 @@ -31,6 +36,15 @@ pub struct CreatableReplicaAssignment { } impl CreatableReplicaAssignment { + /// Sets `partition_index` to the passed value. + /// + /// The partition index. + /// + /// Supported API versions: 0-7 + pub fn with_partition_index(mut self, value: i32) -> Self { + self.partition_index = value; + self + } /// Sets `broker_ids` to the passed value. /// /// The brokers to place the partition on. @@ -53,10 +67,9 @@ impl CreatableReplicaAssignment { } #[cfg(feature = "client")] -impl MapEncodable for CreatableReplicaAssignment { - type Key = i32; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for CreatableReplicaAssignment { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.partition_index)?; if version >= 5 { types::CompactArray(types::Int32).encode(buf, &self.broker_ids)?; } else { @@ -76,9 +89,9 @@ impl MapEncodable for CreatableReplicaAssignment { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.partition_index)?; if version >= 5 { total_size += types::CompactArray(types::Int32).compute_size(&self.broker_ids)?; } else { @@ -101,10 +114,9 @@ impl MapEncodable for CreatableReplicaAssignment { } #[cfg(feature = "broker")] -impl MapDecodable for CreatableReplicaAssignment { - type Key = i32; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for CreatableReplicaAssignment { + fn decode(buf: &mut B, version: i16) -> Result { + let partition_index = types::Int32.decode(buf)?; let broker_ids = if version >= 5 { types::CompactArray(types::Int32).decode(buf)? } else { @@ -120,19 +132,18 @@ impl MapDecodable for CreatableReplicaAssignment { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - broker_ids, - unknown_tagged_fields, - }, - )) + Ok(Self { + partition_index, + broker_ids, + unknown_tagged_fields, + }) } } impl Default for CreatableReplicaAssignment { fn default() -> Self { Self { + partition_index: 0, broker_ids: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -148,6 +159,11 @@ impl Message for CreatableReplicaAssignment { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct CreatableTopic { + /// The topic name. + /// + /// Supported API versions: 0-7 + pub name: super::TopicName, + /// The number of partitions to create in the topic, or -1 if we are either specifying a manual partition assignment or using the default partitions. /// /// Supported API versions: 0-7 @@ -161,18 +177,27 @@ pub struct CreatableTopic { /// The manual partition assignment, or the empty array if we are using automatic assignment. /// /// Supported API versions: 0-7 - pub assignments: indexmap::IndexMap, + pub assignments: Vec, /// The custom topic configurations to set. /// /// Supported API versions: 0-7 - pub configs: indexmap::IndexMap, + pub configs: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl CreatableTopic { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-7 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `num_partitions` to the passed value. /// /// The number of partitions to create in the topic, or -1 if we are either specifying a manual partition assignment or using the default partitions. @@ -196,10 +221,7 @@ impl CreatableTopic { /// The manual partition assignment, or the empty array if we are using automatic assignment. /// /// Supported API versions: 0-7 - pub fn with_assignments( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_assignments(mut self, value: Vec) -> Self { self.assignments = value; self } @@ -208,10 +230,7 @@ impl CreatableTopic { /// The custom topic configurations to set. /// /// Supported API versions: 0-7 - pub fn with_configs( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_configs(mut self, value: Vec) -> Self { self.configs = value; self } @@ -228,13 +247,12 @@ impl CreatableTopic { } #[cfg(feature = "client")] -impl MapEncodable for CreatableTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for CreatableTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 5 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } types::Int32.encode(buf, &self.num_partitions)?; types::Int16.encode(buf, &self.replication_factor)?; @@ -262,12 +280,12 @@ impl MapEncodable for CreatableTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 5 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } total_size += types::Int32.compute_size(&self.num_partitions)?; total_size += types::Int16.compute_size(&self.replication_factor)?; @@ -301,10 +319,9 @@ impl MapEncodable for CreatableTopic { } #[cfg(feature = "broker")] -impl MapDecodable for CreatableTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 5 { +impl Decodable for CreatableTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 5 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -331,22 +348,21 @@ impl MapDecodable for CreatableTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - num_partitions, - replication_factor, - assignments, - configs, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + num_partitions, + replication_factor, + assignments, + configs, + unknown_tagged_fields, + }) } } impl Default for CreatableTopic { fn default() -> Self { Self { + name: Default::default(), num_partitions: 0, replication_factor: 0, assignments: Default::default(), @@ -368,7 +384,7 @@ pub struct CreateTopicsRequest { /// The topics to create. /// /// Supported API versions: 0-7 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// How long to wait in milliseconds before timing out the request. /// @@ -390,10 +406,7 @@ impl CreateTopicsRequest { /// The topics to create. /// /// Supported API versions: 0-7 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -542,6 +555,11 @@ impl Message for CreateTopicsRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct CreateableTopicConfig { + /// The configuration name. + /// + /// Supported API versions: 0-7 + pub name: StrBytes, + /// The configuration value. /// /// Supported API versions: 0-7 @@ -552,6 +570,15 @@ pub struct CreateableTopicConfig { } impl CreateableTopicConfig { + /// Sets `name` to the passed value. + /// + /// The configuration name. + /// + /// Supported API versions: 0-7 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `value` to the passed value. /// /// The configuration value. @@ -574,13 +601,12 @@ impl CreateableTopicConfig { } #[cfg(feature = "client")] -impl MapEncodable for CreateableTopicConfig { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for CreateableTopicConfig { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 5 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 5 { types::CompactString.encode(buf, &self.value)?; @@ -601,12 +627,12 @@ impl MapEncodable for CreateableTopicConfig { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 5 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 5 { total_size += types::CompactString.compute_size(&self.value)?; @@ -630,10 +656,9 @@ impl MapEncodable for CreateableTopicConfig { } #[cfg(feature = "broker")] -impl MapDecodable for CreateableTopicConfig { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 5 { +impl Decodable for CreateableTopicConfig { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 5 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -653,19 +678,18 @@ impl MapDecodable for CreateableTopicConfig { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - value, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + value, + unknown_tagged_fields, + }) } } impl Default for CreateableTopicConfig { fn default() -> Self { Self { + name: Default::default(), value: Some(Default::default()), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/create_topics_response.rs b/src/messages/create_topics_response.rs index 03657a8..c6a2c4a 100644 --- a/src/messages/create_topics_response.rs +++ b/src/messages/create_topics_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-7 @@ -286,6 +286,11 @@ impl Message for CreatableTopicConfigs { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct CreatableTopicResult { + /// The topic name. + /// + /// Supported API versions: 0-7 + pub name: super::TopicName, + /// The unique topic ID /// /// Supported API versions: 7 @@ -326,6 +331,15 @@ pub struct CreatableTopicResult { } impl CreatableTopicResult { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-7 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `topic_id` to the passed value. /// /// The unique topic ID @@ -402,13 +416,12 @@ impl CreatableTopicResult { } #[cfg(feature = "broker")] -impl MapEncodable for CreatableTopicResult { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for CreatableTopicResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 5 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 7 { types::Uuid.encode(buf, &self.topic_id)?; @@ -459,12 +472,12 @@ impl MapEncodable for CreatableTopicResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 5 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 7 { total_size += types::Uuid.compute_size(&self.topic_id)?; @@ -519,10 +532,9 @@ impl MapEncodable for CreatableTopicResult { } #[cfg(feature = "client")] -impl MapDecodable for CreatableTopicResult { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 5 { +impl Decodable for CreatableTopicResult { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 5 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -575,25 +587,24 @@ impl MapDecodable for CreatableTopicResult { } } } - Ok(( - key_field, - Self { - topic_id, - error_code, - error_message, - topic_config_error_code, - num_partitions, - replication_factor, - configs, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + topic_id, + error_code, + error_message, + topic_config_error_code, + num_partitions, + replication_factor, + configs, + unknown_tagged_fields, + }) } } impl Default for CreatableTopicResult { fn default() -> Self { Self { + name: Default::default(), topic_id: Uuid::nil(), error_code: 0, error_message: Some(Default::default()), @@ -623,7 +634,7 @@ pub struct CreateTopicsResponse { /// Results for each topic we tried to create. /// /// Supported API versions: 0-7 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -644,10 +655,7 @@ impl CreateTopicsResponse { /// Results for each topic we tried to create. /// /// Supported API versions: 0-7 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } diff --git a/src/messages/default_principal_data.rs b/src/messages/default_principal_data.rs index 6830471..4e3d8fe 100644 --- a/src/messages/default_principal_data.rs +++ b/src/messages/default_principal_data.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/delete_acls_request.rs b/src/messages/delete_acls_request.rs index 3b07196..1881652 100644 --- a/src/messages/delete_acls_request.rs +++ b/src/messages/delete_acls_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/delete_acls_response.rs b/src/messages/delete_acls_response.rs index 60566ce..79d1707 100644 --- a/src/messages/delete_acls_response.rs +++ b/src/messages/delete_acls_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/delete_groups_request.rs b/src/messages/delete_groups_request.rs index b6f712e..63f16a2 100644 --- a/src/messages/delete_groups_request.rs +++ b/src/messages/delete_groups_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/delete_groups_response.rs b/src/messages/delete_groups_response.rs index 4c708b3..b570957 100644 --- a/src/messages/delete_groups_response.rs +++ b/src/messages/delete_groups_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DeletableGroupResult { + /// The group id + /// + /// Supported API versions: 0-2 + pub group_id: super::GroupId, + /// The deletion error, or 0 if the deletion succeeded. /// /// Supported API versions: 0-2 @@ -31,6 +36,15 @@ pub struct DeletableGroupResult { } impl DeletableGroupResult { + /// Sets `group_id` to the passed value. + /// + /// The group id + /// + /// Supported API versions: 0-2 + pub fn with_group_id(mut self, value: super::GroupId) -> Self { + self.group_id = value; + self + } /// Sets `error_code` to the passed value. /// /// The deletion error, or 0 if the deletion succeeded. @@ -53,13 +67,12 @@ impl DeletableGroupResult { } #[cfg(feature = "broker")] -impl MapEncodable for DeletableGroupResult { - type Key = super::GroupId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for DeletableGroupResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.group_id)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.group_id)?; } types::Int16.encode(buf, &self.error_code)?; if version >= 2 { @@ -76,12 +89,12 @@ impl MapEncodable for DeletableGroupResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.group_id)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.group_id)?; } total_size += types::Int16.compute_size(&self.error_code)?; if version >= 2 { @@ -101,10 +114,9 @@ impl MapEncodable for DeletableGroupResult { } #[cfg(feature = "client")] -impl MapDecodable for DeletableGroupResult { - type Key = super::GroupId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for DeletableGroupResult { + fn decode(buf: &mut B, version: i16) -> Result { + let group_id = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -120,19 +132,18 @@ impl MapDecodable for DeletableGroupResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - error_code, - unknown_tagged_fields, - }, - )) + Ok(Self { + group_id, + error_code, + unknown_tagged_fields, + }) } } impl Default for DeletableGroupResult { fn default() -> Self { Self { + group_id: Default::default(), error_code: 0, unknown_tagged_fields: BTreeMap::new(), } @@ -156,7 +167,7 @@ pub struct DeleteGroupsResponse { /// The deletion results /// /// Supported API versions: 0-2 - pub results: indexmap::IndexMap, + pub results: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -177,10 +188,7 @@ impl DeleteGroupsResponse { /// The deletion results /// /// Supported API versions: 0-2 - pub fn with_results( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_results(mut self, value: Vec) -> Self { self.results = value; self } diff --git a/src/messages/delete_records_request.rs b/src/messages/delete_records_request.rs index a4af9a4..1dd1588 100644 --- a/src/messages/delete_records_request.rs +++ b/src/messages/delete_records_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/delete_records_response.rs b/src/messages/delete_records_response.rs index d5ad7d0..0d9b86e 100644 --- a/src/messages/delete_records_response.rs +++ b/src/messages/delete_records_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DeleteRecordsPartitionResult { + /// The partition index. + /// + /// Supported API versions: 0-2 + pub partition_index: i32, + /// The partition low water mark. /// /// Supported API versions: 0-2 @@ -36,6 +41,15 @@ pub struct DeleteRecordsPartitionResult { } impl DeleteRecordsPartitionResult { + /// Sets `partition_index` to the passed value. + /// + /// The partition index. + /// + /// Supported API versions: 0-2 + pub fn with_partition_index(mut self, value: i32) -> Self { + self.partition_index = value; + self + } /// Sets `low_watermark` to the passed value. /// /// The partition low water mark. @@ -67,10 +81,9 @@ impl DeleteRecordsPartitionResult { } #[cfg(feature = "broker")] -impl MapEncodable for DeleteRecordsPartitionResult { - type Key = i32; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for DeleteRecordsPartitionResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.partition_index)?; types::Int64.encode(buf, &self.low_watermark)?; types::Int16.encode(buf, &self.error_code)?; if version >= 2 { @@ -87,9 +100,9 @@ impl MapEncodable for DeleteRecordsPartitionResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.partition_index)?; total_size += types::Int64.compute_size(&self.low_watermark)?; total_size += types::Int16.compute_size(&self.error_code)?; if version >= 2 { @@ -109,10 +122,9 @@ impl MapEncodable for DeleteRecordsPartitionResult { } #[cfg(feature = "client")] -impl MapDecodable for DeleteRecordsPartitionResult { - type Key = i32; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for DeleteRecordsPartitionResult { + fn decode(buf: &mut B, version: i16) -> Result { + let partition_index = types::Int32.decode(buf)?; let low_watermark = types::Int64.decode(buf)?; let error_code = types::Int16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -125,20 +137,19 @@ impl MapDecodable for DeleteRecordsPartitionResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - low_watermark, - error_code, - unknown_tagged_fields, - }, - )) + Ok(Self { + partition_index, + low_watermark, + error_code, + unknown_tagged_fields, + }) } } impl Default for DeleteRecordsPartitionResult { fn default() -> Self { Self { + partition_index: 0, low_watermark: 0, error_code: 0, unknown_tagged_fields: BTreeMap::new(), @@ -163,7 +174,7 @@ pub struct DeleteRecordsResponse { /// Each topic that we wanted to delete records from. /// /// Supported API versions: 0-2 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -184,10 +195,7 @@ impl DeleteRecordsResponse { /// Each topic that we wanted to delete records from. /// /// Supported API versions: 0-2 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -297,25 +305,36 @@ impl Message for DeleteRecordsResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DeleteRecordsTopicResult { + /// The topic name. + /// + /// Supported API versions: 0-2 + pub name: super::TopicName, + /// Each partition that we wanted to delete records from. /// /// Supported API versions: 0-2 - pub partitions: indexmap::IndexMap, + pub partitions: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, } impl DeleteRecordsTopicResult { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-2 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partitions` to the passed value. /// /// Each partition that we wanted to delete records from. /// /// Supported API versions: 0-2 - pub fn with_partitions( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_partitions(mut self, value: Vec) -> Self { self.partitions = value; self } @@ -332,13 +351,12 @@ impl DeleteRecordsTopicResult { } #[cfg(feature = "broker")] -impl MapEncodable for DeleteRecordsTopicResult { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for DeleteRecordsTopicResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 2 { types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?; @@ -359,12 +377,12 @@ impl MapEncodable for DeleteRecordsTopicResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 2 { total_size += @@ -389,10 +407,9 @@ impl MapEncodable for DeleteRecordsTopicResult { } #[cfg(feature = "client")] -impl MapDecodable for DeleteRecordsTopicResult { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for DeleteRecordsTopicResult { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -412,19 +429,18 @@ impl MapDecodable for DeleteRecordsTopicResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + partitions, + unknown_tagged_fields, + }) } } impl Default for DeleteRecordsTopicResult { fn default() -> Self { Self { + name: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/delete_topics_request.rs b/src/messages/delete_topics_request.rs index 1a7f8c7..8d96fc2 100644 --- a/src/messages/delete_topics_request.rs +++ b/src/messages/delete_topics_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-6 diff --git a/src/messages/delete_topics_response.rs b/src/messages/delete_topics_response.rs index 3802f8a..d07f98c 100644 --- a/src/messages/delete_topics_response.rs +++ b/src/messages/delete_topics_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-6 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DeletableTopicResult { + /// The topic name + /// + /// Supported API versions: 0-6 + pub name: Option, + /// the unique topic ID /// /// Supported API versions: 6 @@ -41,6 +46,15 @@ pub struct DeletableTopicResult { } impl DeletableTopicResult { + /// Sets `name` to the passed value. + /// + /// The topic name + /// + /// Supported API versions: 0-6 + pub fn with_name(mut self, value: Option) -> Self { + self.name = value; + self + } /// Sets `topic_id` to the passed value. /// /// the unique topic ID @@ -81,13 +95,12 @@ impl DeletableTopicResult { } #[cfg(feature = "broker")] -impl MapEncodable for DeletableTopicResult { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for DeletableTopicResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 4 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 6 { types::Uuid.encode(buf, &self.topic_id)?; @@ -110,12 +123,12 @@ impl MapEncodable for DeletableTopicResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 4 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 6 { total_size += types::Uuid.compute_size(&self.topic_id)?; @@ -141,10 +154,9 @@ impl MapEncodable for DeletableTopicResult { } #[cfg(feature = "client")] -impl MapDecodable for DeletableTopicResult { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 4 { +impl Decodable for DeletableTopicResult { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 4 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -170,21 +182,20 @@ impl MapDecodable for DeletableTopicResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - topic_id, - error_code, - error_message, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + topic_id, + error_code, + error_message, + unknown_tagged_fields, + }) } } impl Default for DeletableTopicResult { fn default() -> Self { Self { + name: Some(Default::default()), topic_id: Uuid::nil(), error_code: 0, error_message: None, @@ -210,7 +221,7 @@ pub struct DeleteTopicsResponse { /// The results for each topic we tried to delete. /// /// Supported API versions: 0-6 - pub responses: indexmap::IndexMap, + pub responses: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -231,10 +242,7 @@ impl DeleteTopicsResponse { /// The results for each topic we tried to delete. /// /// Supported API versions: 0-6 - pub fn with_responses( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_responses(mut self, value: Vec) -> Self { self.responses = value; self } diff --git a/src/messages/describe_acls_request.rs b/src/messages/describe_acls_request.rs index 24b59c7..a486b2f 100644 --- a/src/messages/describe_acls_request.rs +++ b/src/messages/describe_acls_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/describe_acls_response.rs b/src/messages/describe_acls_response.rs index 5daf30d..abf0213 100644 --- a/src/messages/describe_acls_response.rs +++ b/src/messages/describe_acls_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/describe_client_quotas_request.rs b/src/messages/describe_client_quotas_request.rs index 6737074..a2e4874 100644 --- a/src/messages/describe_client_quotas_request.rs +++ b/src/messages/describe_client_quotas_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/describe_client_quotas_response.rs b/src/messages/describe_client_quotas_response.rs index 16e5b4b..9b16a8a 100644 --- a/src/messages/describe_client_quotas_response.rs +++ b/src/messages/describe_client_quotas_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/describe_cluster_request.rs b/src/messages/describe_cluster_request.rs index 4f1d068..d60aa1c 100644 --- a/src/messages/describe_cluster_request.rs +++ b/src/messages/describe_cluster_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/describe_cluster_response.rs b/src/messages/describe_cluster_response.rs index b99dee4..4a9bcaf 100644 --- a/src/messages/describe_cluster_response.rs +++ b/src/messages/describe_cluster_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DescribeClusterBroker { + /// The broker ID. + /// + /// Supported API versions: 0-1 + pub broker_id: super::BrokerId, + /// The broker hostname. /// /// Supported API versions: 0-1 @@ -41,6 +46,15 @@ pub struct DescribeClusterBroker { } impl DescribeClusterBroker { + /// Sets `broker_id` to the passed value. + /// + /// The broker ID. + /// + /// Supported API versions: 0-1 + pub fn with_broker_id(mut self, value: super::BrokerId) -> Self { + self.broker_id = value; + self + } /// Sets `host` to the passed value. /// /// The broker hostname. @@ -81,10 +95,9 @@ impl DescribeClusterBroker { } #[cfg(feature = "broker")] -impl MapEncodable for DescribeClusterBroker { - type Key = super::BrokerId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for DescribeClusterBroker { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.broker_id)?; types::CompactString.encode(buf, &self.host)?; types::Int32.encode(buf, &self.port)?; types::CompactString.encode(buf, &self.rack)?; @@ -100,9 +113,9 @@ impl MapEncodable for DescribeClusterBroker { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.broker_id)?; total_size += types::CompactString.compute_size(&self.host)?; total_size += types::Int32.compute_size(&self.port)?; total_size += types::CompactString.compute_size(&self.rack)?; @@ -121,10 +134,9 @@ impl MapEncodable for DescribeClusterBroker { } #[cfg(feature = "client")] -impl MapDecodable for DescribeClusterBroker { - type Key = super::BrokerId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for DescribeClusterBroker { + fn decode(buf: &mut B, version: i16) -> Result { + let broker_id = types::Int32.decode(buf)?; let host = types::CompactString.decode(buf)?; let port = types::Int32.decode(buf)?; let rack = types::CompactString.decode(buf)?; @@ -136,21 +148,20 @@ impl MapDecodable for DescribeClusterBroker { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - host, - port, - rack, - unknown_tagged_fields, - }, - )) + Ok(Self { + broker_id, + host, + port, + rack, + unknown_tagged_fields, + }) } } impl Default for DescribeClusterBroker { fn default() -> Self { Self { + broker_id: (0).into(), host: Default::default(), port: 0, rack: None, @@ -201,7 +212,7 @@ pub struct DescribeClusterResponse { /// Each broker in the response. /// /// Supported API versions: 0-1 - pub brokers: indexmap::IndexMap, + pub brokers: Vec, /// 32-bit bitfield to represent authorized operations for this cluster. /// @@ -272,10 +283,7 @@ impl DescribeClusterResponse { /// Each broker in the response. /// /// Supported API versions: 0-1 - pub fn with_brokers( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_brokers(mut self, value: Vec) -> Self { self.brokers = value; self } diff --git a/src/messages/describe_configs_request.rs b/src/messages/describe_configs_request.rs index 73b3c18..10745be 100644 --- a/src/messages/describe_configs_request.rs +++ b/src/messages/describe_configs_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/describe_configs_response.rs b/src/messages/describe_configs_response.rs index 622e398..4aa10af 100644 --- a/src/messages/describe_configs_response.rs +++ b/src/messages/describe_configs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/describe_delegation_token_request.rs b/src/messages/describe_delegation_token_request.rs index 861b9b5..7aee842 100644 --- a/src/messages/describe_delegation_token_request.rs +++ b/src/messages/describe_delegation_token_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/describe_delegation_token_response.rs b/src/messages/describe_delegation_token_response.rs index bb93ecc..90187b3 100644 --- a/src/messages/describe_delegation_token_response.rs +++ b/src/messages/describe_delegation_token_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-3 diff --git a/src/messages/describe_groups_request.rs b/src/messages/describe_groups_request.rs index 3929610..d451922 100644 --- a/src/messages/describe_groups_request.rs +++ b/src/messages/describe_groups_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/describe_groups_response.rs b/src/messages/describe_groups_response.rs index c2d1d38..9876c77 100644 --- a/src/messages/describe_groups_response.rs +++ b/src/messages/describe_groups_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/describe_log_dirs_request.rs b/src/messages/describe_log_dirs_request.rs index 41deb6d..2bac2ca 100644 --- a/src/messages/describe_log_dirs_request.rs +++ b/src/messages/describe_log_dirs_request.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct DescribableLogDirTopic { + /// The topic name + /// + /// Supported API versions: 0-4 + pub topic: super::TopicName, + /// The partition indexes. /// /// Supported API versions: 0-4 @@ -31,6 +36,15 @@ pub struct DescribableLogDirTopic { } impl DescribableLogDirTopic { + /// Sets `topic` to the passed value. + /// + /// The topic name + /// + /// Supported API versions: 0-4 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// The partition indexes. @@ -53,13 +67,12 @@ impl DescribableLogDirTopic { } #[cfg(feature = "client")] -impl MapEncodable for DescribableLogDirTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for DescribableLogDirTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.topic)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.topic)?; } if version >= 2 { types::CompactArray(types::Int32).encode(buf, &self.partitions)?; @@ -80,12 +93,12 @@ impl MapEncodable for DescribableLogDirTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.topic)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; } if version >= 2 { total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?; @@ -109,10 +122,9 @@ impl MapEncodable for DescribableLogDirTopic { } #[cfg(feature = "broker")] -impl MapDecodable for DescribableLogDirTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for DescribableLogDirTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -132,19 +144,18 @@ impl MapDecodable for DescribableLogDirTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic, + partitions, + unknown_tagged_fields, + }) } } impl Default for DescribableLogDirTopic { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -163,7 +174,7 @@ pub struct DescribeLogDirsRequest { /// Each topic that we want to describe log directories for, or null for all topics. /// /// Supported API versions: 0-4 - pub topics: Option>, + pub topics: Option>, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -175,10 +186,7 @@ impl DescribeLogDirsRequest { /// Each topic that we want to describe log directories for, or null for all topics. /// /// Supported API versions: 0-4 - pub fn with_topics( - mut self, - value: Option>, - ) -> Self { + pub fn with_topics(mut self, value: Option>) -> Self { self.topics = value; self } diff --git a/src/messages/describe_log_dirs_response.rs b/src/messages/describe_log_dirs_response.rs index b1342cd..9c9b483 100644 --- a/src/messages/describe_log_dirs_response.rs +++ b/src/messages/describe_log_dirs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/describe_producers_request.rs b/src/messages/describe_producers_request.rs index c7a5e07..b387ac0 100644 --- a/src/messages/describe_producers_request.rs +++ b/src/messages/describe_producers_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/describe_producers_response.rs b/src/messages/describe_producers_response.rs index 9ddf274..d19ad30 100644 --- a/src/messages/describe_producers_response.rs +++ b/src/messages/describe_producers_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/describe_quorum_request.rs b/src/messages/describe_quorum_request.rs index c08e5d7..3efa8e6 100644 --- a/src/messages/describe_quorum_request.rs +++ b/src/messages/describe_quorum_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/describe_quorum_response.rs b/src/messages/describe_quorum_response.rs index 9cb91f7..a2f4974 100644 --- a/src/messages/describe_quorum_response.rs +++ b/src/messages/describe_quorum_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/describe_topic_partitions_request.rs b/src/messages/describe_topic_partitions_request.rs index 61521ea..554fa0a 100644 --- a/src/messages/describe_topic_partitions_request.rs +++ b/src/messages/describe_topic_partitions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/describe_topic_partitions_response.rs b/src/messages/describe_topic_partitions_response.rs index f479faf..aa44b6a 100644 --- a/src/messages/describe_topic_partitions_response.rs +++ b/src/messages/describe_topic_partitions_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 @@ -149,7 +149,7 @@ pub struct DescribeTopicPartitionsResponse { /// Each topic in the response. /// /// Supported API versions: 0 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// The next topic and partition index to fetch details for. /// @@ -175,10 +175,7 @@ impl DescribeTopicPartitionsResponse { /// Each topic in the response. /// /// Supported API versions: 0 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -542,6 +539,11 @@ pub struct DescribeTopicPartitionsResponseTopic { /// Supported API versions: 0 pub error_code: i16, + /// The topic name. + /// + /// Supported API versions: 0 + pub name: Option, + /// The topic id. /// /// Supported API versions: 0 @@ -576,6 +578,15 @@ impl DescribeTopicPartitionsResponseTopic { self.error_code = value; self } + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: Option) -> Self { + self.name = value; + self + } /// Sets `topic_id` to the passed value. /// /// The topic id. @@ -625,11 +636,10 @@ impl DescribeTopicPartitionsResponseTopic { } #[cfg(feature = "broker")] -impl MapEncodable for DescribeTopicPartitionsResponseTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for DescribeTopicPartitionsResponseTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { types::Int16.encode(buf, &self.error_code)?; - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; types::Uuid.encode(buf, &self.topic_id)?; types::Boolean.encode(buf, &self.is_internal)?; types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?; @@ -646,10 +656,10 @@ impl MapEncodable for DescribeTopicPartitionsResponseTopic { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; total_size += types::Int16.compute_size(&self.error_code)?; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::Uuid.compute_size(&self.topic_id)?; total_size += types::Boolean.compute_size(&self.is_internal)?; total_size += @@ -670,11 +680,10 @@ impl MapEncodable for DescribeTopicPartitionsResponseTopic { } #[cfg(feature = "client")] -impl MapDecodable for DescribeTopicPartitionsResponseTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { +impl Decodable for DescribeTopicPartitionsResponseTopic { + fn decode(buf: &mut B, version: i16) -> Result { let error_code = types::Int16.decode(buf)?; - let key_field = types::CompactString.decode(buf)?; + let name = types::CompactString.decode(buf)?; let topic_id = types::Uuid.decode(buf)?; let is_internal = types::Boolean.decode(buf)?; let partitions = types::CompactArray(types::Struct { version }).decode(buf)?; @@ -687,17 +696,15 @@ impl MapDecodable for DescribeTopicPartitionsResponseTopic { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - error_code, - topic_id, - is_internal, - partitions, - topic_authorized_operations, - unknown_tagged_fields, - }, - )) + Ok(Self { + error_code, + name, + topic_id, + is_internal, + partitions, + topic_authorized_operations, + unknown_tagged_fields, + }) } } @@ -705,6 +712,7 @@ impl Default for DescribeTopicPartitionsResponseTopic { fn default() -> Self { Self { error_code: 0, + name: Some(Default::default()), topic_id: Uuid::nil(), is_internal: false, partitions: Default::default(), diff --git a/src/messages/describe_transactions_request.rs b/src/messages/describe_transactions_request.rs index 6f7ec48..2271922 100644 --- a/src/messages/describe_transactions_request.rs +++ b/src/messages/describe_transactions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/describe_transactions_response.rs b/src/messages/describe_transactions_response.rs index fa7ee65..07aa858 100644 --- a/src/messages/describe_transactions_response.rs +++ b/src/messages/describe_transactions_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 @@ -142,6 +142,11 @@ impl Message for DescribeTransactionsResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicData { + /// + /// + /// Supported API versions: 0 + pub topic: super::TopicName, + /// /// /// Supported API versions: 0 @@ -152,6 +157,15 @@ pub struct TopicData { } impl TopicData { + /// Sets `topic` to the passed value. + /// + /// + /// + /// Supported API versions: 0 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// @@ -174,10 +188,9 @@ impl TopicData { } #[cfg(feature = "broker")] -impl MapEncodable for TopicData { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for TopicData { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.topic)?; types::CompactArray(types::Int32).encode(buf, &self.partitions)?; let num_tagged_fields = self.unknown_tagged_fields.len(); if num_tagged_fields > std::u32::MAX as usize { @@ -191,9 +204,9 @@ impl MapEncodable for TopicData { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.topic)?; total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?; let num_tagged_fields = self.unknown_tagged_fields.len(); if num_tagged_fields > std::u32::MAX as usize { @@ -210,10 +223,9 @@ impl MapEncodable for TopicData { } #[cfg(feature = "client")] -impl MapDecodable for TopicData { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for TopicData { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = types::CompactString.decode(buf)?; let partitions = types::CompactArray(types::Int32).decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); let num_tagged_fields = types::UnsignedVarInt.decode(buf)?; @@ -223,19 +235,18 @@ impl MapDecodable for TopicData { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic, + partitions, + unknown_tagged_fields, + }) } } impl Default for TopicData { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } @@ -289,7 +300,7 @@ pub struct TransactionState { /// The set of partitions included in the current transaction (if active). When a transaction is preparing to commit or abort, this will include only partitions which do not have markers. /// /// Supported API versions: 0 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -364,7 +375,7 @@ impl TransactionState { /// The set of partitions included in the current transaction (if active). When a transaction is preparing to commit or abort, this will include only partitions which do not have markers. /// /// Supported API versions: 0 - pub fn with_topics(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } diff --git a/src/messages/describe_user_scram_credentials_request.rs b/src/messages/describe_user_scram_credentials_request.rs index e8e9da3..682711c 100644 --- a/src/messages/describe_user_scram_credentials_request.rs +++ b/src/messages/describe_user_scram_credentials_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/describe_user_scram_credentials_response.rs b/src/messages/describe_user_scram_credentials_response.rs index 58692c0..1f10a13 100644 --- a/src/messages/describe_user_scram_credentials_response.rs +++ b/src/messages/describe_user_scram_credentials_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/elect_leaders_request.rs b/src/messages/elect_leaders_request.rs index 4dc8995..e484850 100644 --- a/src/messages/elect_leaders_request.rs +++ b/src/messages/elect_leaders_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 @@ -29,7 +29,7 @@ pub struct ElectLeadersRequest { /// The topic partitions to elect leaders. /// /// Supported API versions: 0-2 - pub topic_partitions: Option>, + pub topic_partitions: Option>, /// The time in ms to wait for the election to complete. /// @@ -55,10 +55,7 @@ impl ElectLeadersRequest { /// The topic partitions to elect leaders. /// /// Supported API versions: 0-2 - pub fn with_topic_partitions( - mut self, - value: Option>, - ) -> Self { + pub fn with_topic_partitions(mut self, value: Option>) -> Self { self.topic_partitions = value; self } @@ -199,6 +196,11 @@ impl Message for ElectLeadersRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicPartitions { + /// The name of a topic. + /// + /// Supported API versions: 0-2 + pub topic: super::TopicName, + /// The partitions of this topic whose leader should be elected. /// /// Supported API versions: 0-2 @@ -209,6 +211,15 @@ pub struct TopicPartitions { } impl TopicPartitions { + /// Sets `topic` to the passed value. + /// + /// The name of a topic. + /// + /// Supported API versions: 0-2 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// The partitions of this topic whose leader should be elected. @@ -231,13 +242,12 @@ impl TopicPartitions { } #[cfg(feature = "client")] -impl MapEncodable for TopicPartitions { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for TopicPartitions { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 2 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.topic)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.topic)?; } if version >= 2 { types::CompactArray(types::Int32).encode(buf, &self.partitions)?; @@ -258,12 +268,12 @@ impl MapEncodable for TopicPartitions { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 2 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.topic)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; } if version >= 2 { total_size += types::CompactArray(types::Int32).compute_size(&self.partitions)?; @@ -287,10 +297,9 @@ impl MapEncodable for TopicPartitions { } #[cfg(feature = "broker")] -impl MapDecodable for TopicPartitions { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 2 { +impl Decodable for TopicPartitions { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = if version >= 2 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -310,19 +319,18 @@ impl MapDecodable for TopicPartitions { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic, + partitions, + unknown_tagged_fields, + }) } } impl Default for TopicPartitions { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/elect_leaders_response.rs b/src/messages/elect_leaders_response.rs index c8a4fbb..909345d 100644 --- a/src/messages/elect_leaders_response.rs +++ b/src/messages/elect_leaders_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/end_quorum_epoch_request.rs b/src/messages/end_quorum_epoch_request.rs index 7e93c7b..692d226 100644 --- a/src/messages/end_quorum_epoch_request.rs +++ b/src/messages/end_quorum_epoch_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/end_quorum_epoch_response.rs b/src/messages/end_quorum_epoch_response.rs index 095e315..b79850c 100644 --- a/src/messages/end_quorum_epoch_response.rs +++ b/src/messages/end_quorum_epoch_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/end_txn_request.rs b/src/messages/end_txn_request.rs index 659f95a..8793d83 100644 --- a/src/messages/end_txn_request.rs +++ b/src/messages/end_txn_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/end_txn_response.rs b/src/messages/end_txn_response.rs index e8e3bb6..331e800 100644 --- a/src/messages/end_txn_response.rs +++ b/src/messages/end_txn_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/envelope_request.rs b/src/messages/envelope_request.rs index f8db5ac..bb7b006 100644 --- a/src/messages/envelope_request.rs +++ b/src/messages/envelope_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/envelope_response.rs b/src/messages/envelope_response.rs index 2781432..d6321e2 100644 --- a/src/messages/envelope_response.rs +++ b/src/messages/envelope_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/expire_delegation_token_request.rs b/src/messages/expire_delegation_token_request.rs index 9eb19b3..0236a88 100644 --- a/src/messages/expire_delegation_token_request.rs +++ b/src/messages/expire_delegation_token_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/expire_delegation_token_response.rs b/src/messages/expire_delegation_token_response.rs index 6a16d44..a070328 100644 --- a/src/messages/expire_delegation_token_response.rs +++ b/src/messages/expire_delegation_token_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/fetch_request.rs b/src/messages/fetch_request.rs index 8d4aba2..d8285d9 100644 --- a/src/messages/fetch_request.rs +++ b/src/messages/fetch_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-16 diff --git a/src/messages/fetch_response.rs b/src/messages/fetch_response.rs index d0c2a53..1b87b6a 100644 --- a/src/messages/fetch_response.rs +++ b/src/messages/fetch_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-16 @@ -360,7 +360,7 @@ pub struct FetchResponse { /// Endpoints for all current-leaders enumerated in PartitionData, with errors NOT_LEADER_OR_FOLLOWER & FENCED_LEADER_EPOCH. /// /// Supported API versions: 16 - pub node_endpoints: indexmap::IndexMap, + pub node_endpoints: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -408,10 +408,7 @@ impl FetchResponse { /// Endpoints for all current-leaders enumerated in PartitionData, with errors NOT_LEADER_OR_FOLLOWER & FENCED_LEADER_EPOCH. /// /// Supported API versions: 16 - pub fn with_node_endpoints( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_node_endpoints(mut self, value: Vec) -> Self { self.node_endpoints = value; self } @@ -961,6 +958,11 @@ impl Message for LeaderIdAndEpoch { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct NodeEndpoint { + /// The ID of the associated node. + /// + /// Supported API versions: 16 + pub node_id: super::BrokerId, + /// The node's hostname. /// /// Supported API versions: 16 @@ -981,6 +983,15 @@ pub struct NodeEndpoint { } impl NodeEndpoint { + /// Sets `node_id` to the passed value. + /// + /// The ID of the associated node. + /// + /// Supported API versions: 16 + pub fn with_node_id(mut self, value: super::BrokerId) -> Self { + self.node_id = value; + self + } /// Sets `host` to the passed value. /// /// The node's hostname. @@ -1021,13 +1032,12 @@ impl NodeEndpoint { } #[cfg(feature = "broker")] -impl MapEncodable for NodeEndpoint { - type Key = super::BrokerId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for NodeEndpoint { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 16 { - types::Int32.encode(buf, key)?; + types::Int32.encode(buf, &self.node_id)?; } else { - if *key != 0 { + if self.node_id != 0 { bail!("failed to encode"); } } @@ -1066,12 +1076,12 @@ impl MapEncodable for NodeEndpoint { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 16 { - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.node_id)?; } else { - if *key != 0 { + if self.node_id != 0 { bail!("failed to encode"); } } @@ -1113,10 +1123,9 @@ impl MapEncodable for NodeEndpoint { } #[cfg(feature = "client")] -impl MapDecodable for NodeEndpoint { - type Key = super::BrokerId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 16 { +impl Decodable for NodeEndpoint { + fn decode(buf: &mut B, version: i16) -> Result { + let node_id = if version >= 16 { types::Int32.decode(buf)? } else { (0).into() @@ -1146,21 +1155,20 @@ impl MapDecodable for NodeEndpoint { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - host, - port, - rack, - unknown_tagged_fields, - }, - )) + Ok(Self { + node_id, + host, + port, + rack, + unknown_tagged_fields, + }) } } impl Default for NodeEndpoint { fn default() -> Self { Self { + node_id: (0).into(), host: Default::default(), port: 0, rack: None, diff --git a/src/messages/fetch_snapshot_request.rs b/src/messages/fetch_snapshot_request.rs index 5655e36..b99f0f3 100644 --- a/src/messages/fetch_snapshot_request.rs +++ b/src/messages/fetch_snapshot_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/fetch_snapshot_response.rs b/src/messages/fetch_snapshot_response.rs index 88750ac..c4d8976 100644 --- a/src/messages/fetch_snapshot_response.rs +++ b/src/messages/fetch_snapshot_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/find_coordinator_request.rs b/src/messages/find_coordinator_request.rs index be8f0b1..e1c8cb0 100644 --- a/src/messages/find_coordinator_request.rs +++ b/src/messages/find_coordinator_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/find_coordinator_response.rs b/src/messages/find_coordinator_response.rs index 876100e..7b6e9ef 100644 --- a/src/messages/find_coordinator_response.rs +++ b/src/messages/find_coordinator_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/get_telemetry_subscriptions_request.rs b/src/messages/get_telemetry_subscriptions_request.rs index 7519dfc..d5945f5 100644 --- a/src/messages/get_telemetry_subscriptions_request.rs +++ b/src/messages/get_telemetry_subscriptions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/get_telemetry_subscriptions_response.rs b/src/messages/get_telemetry_subscriptions_response.rs index 670848b..cc4daed 100644 --- a/src/messages/get_telemetry_subscriptions_response.rs +++ b/src/messages/get_telemetry_subscriptions_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/heartbeat_request.rs b/src/messages/heartbeat_request.rs index c15e15e..7a79003 100644 --- a/src/messages/heartbeat_request.rs +++ b/src/messages/heartbeat_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/heartbeat_response.rs b/src/messages/heartbeat_response.rs index fb22944..dd280c7 100644 --- a/src/messages/heartbeat_response.rs +++ b/src/messages/heartbeat_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/incremental_alter_configs_request.rs b/src/messages/incremental_alter_configs_request.rs index ed34d46..4b12d19 100644 --- a/src/messages/incremental_alter_configs_request.rs +++ b/src/messages/incremental_alter_configs_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/incremental_alter_configs_response.rs b/src/messages/incremental_alter_configs_response.rs index 7ca015c..21d8f59 100644 --- a/src/messages/incremental_alter_configs_response.rs +++ b/src/messages/incremental_alter_configs_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/init_producer_id_request.rs b/src/messages/init_producer_id_request.rs index 37352c1..fc000f8 100644 --- a/src/messages/init_producer_id_request.rs +++ b/src/messages/init_producer_id_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/init_producer_id_response.rs b/src/messages/init_producer_id_response.rs index 648d8ea..247ddf3 100644 --- a/src/messages/init_producer_id_response.rs +++ b/src/messages/init_producer_id_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/join_group_request.rs b/src/messages/join_group_request.rs index c585bd5..81a595a 100644 --- a/src/messages/join_group_request.rs +++ b/src/messages/join_group_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 @@ -54,7 +54,7 @@ pub struct JoinGroupRequest { /// The list of protocols that the member supports. /// /// Supported API versions: 0-9 - pub protocols: indexmap::IndexMap, + pub protocols: Vec, /// The reason why the member (re-)joins the group. /// @@ -125,10 +125,7 @@ impl JoinGroupRequest { /// The list of protocols that the member supports. /// /// Supported API versions: 0-9 - pub fn with_protocols( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_protocols(mut self, value: Vec) -> Self { self.protocols = value; self } @@ -357,6 +354,11 @@ impl Message for JoinGroupRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct JoinGroupRequestProtocol { + /// The protocol name. + /// + /// Supported API versions: 0-9 + pub name: StrBytes, + /// The protocol metadata. /// /// Supported API versions: 0-9 @@ -367,6 +369,15 @@ pub struct JoinGroupRequestProtocol { } impl JoinGroupRequestProtocol { + /// Sets `name` to the passed value. + /// + /// The protocol name. + /// + /// Supported API versions: 0-9 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `metadata` to the passed value. /// /// The protocol metadata. @@ -389,13 +400,12 @@ impl JoinGroupRequestProtocol { } #[cfg(feature = "client")] -impl MapEncodable for JoinGroupRequestProtocol { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for JoinGroupRequestProtocol { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 6 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 6 { types::CompactBytes.encode(buf, &self.metadata)?; @@ -416,12 +426,12 @@ impl MapEncodable for JoinGroupRequestProtocol { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 6 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 6 { total_size += types::CompactBytes.compute_size(&self.metadata)?; @@ -445,10 +455,9 @@ impl MapEncodable for JoinGroupRequestProtocol { } #[cfg(feature = "broker")] -impl MapDecodable for JoinGroupRequestProtocol { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 6 { +impl Decodable for JoinGroupRequestProtocol { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 6 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -468,19 +477,18 @@ impl MapDecodable for JoinGroupRequestProtocol { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - metadata, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + metadata, + unknown_tagged_fields, + }) } } impl Default for JoinGroupRequestProtocol { fn default() -> Self { Self { + name: Default::default(), metadata: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/join_group_response.rs b/src/messages/join_group_response.rs index ff28678..ff482b8 100644 --- a/src/messages/join_group_response.rs +++ b/src/messages/join_group_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 diff --git a/src/messages/k_raft_version_record.rs b/src/messages/k_raft_version_record.rs index e3982ac..bd435db 100644 --- a/src/messages/k_raft_version_record.rs +++ b/src/messages/k_raft_version_record.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/leader_and_isr_request.rs b/src/messages/leader_and_isr_request.rs index c0e2560..3b59ede 100644 --- a/src/messages/leader_and_isr_request.rs +++ b/src/messages/leader_and_isr_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-7 diff --git a/src/messages/leader_and_isr_response.rs b/src/messages/leader_and_isr_response.rs index 49ca118..8b5dc27 100644 --- a/src/messages/leader_and_isr_response.rs +++ b/src/messages/leader_and_isr_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-7 @@ -199,7 +199,7 @@ pub struct LeaderAndIsrResponse { /// Each topic /// /// Supported API versions: 5-7 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -229,7 +229,7 @@ impl LeaderAndIsrResponse { /// Each topic /// /// Supported API versions: 5-7 - pub fn with_topics(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -379,6 +379,11 @@ impl Message for LeaderAndIsrResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct LeaderAndIsrTopicError { + /// The unique topic ID + /// + /// Supported API versions: 5-7 + pub topic_id: Uuid, + /// Each partition. /// /// Supported API versions: 5-7 @@ -389,6 +394,15 @@ pub struct LeaderAndIsrTopicError { } impl LeaderAndIsrTopicError { + /// Sets `topic_id` to the passed value. + /// + /// The unique topic ID + /// + /// Supported API versions: 5-7 + pub fn with_topic_id(mut self, value: Uuid) -> Self { + self.topic_id = value; + self + } /// Sets `partition_errors` to the passed value. /// /// Each partition. @@ -411,13 +425,12 @@ impl LeaderAndIsrTopicError { } #[cfg(feature = "broker")] -impl MapEncodable for LeaderAndIsrTopicError { - type Key = Uuid; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for LeaderAndIsrTopicError { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 5 { - types::Uuid.encode(buf, key)?; + types::Uuid.encode(buf, &self.topic_id)?; } else { - if key != &Uuid::nil() { + if &self.topic_id != &Uuid::nil() { bail!("failed to encode"); } } @@ -442,12 +455,12 @@ impl MapEncodable for LeaderAndIsrTopicError { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 5 { - total_size += types::Uuid.compute_size(key)?; + total_size += types::Uuid.compute_size(&self.topic_id)?; } else { - if key != &Uuid::nil() { + if &self.topic_id != &Uuid::nil() { bail!("failed to encode"); } } @@ -476,10 +489,9 @@ impl MapEncodable for LeaderAndIsrTopicError { } #[cfg(feature = "client")] -impl MapDecodable for LeaderAndIsrTopicError { - type Key = Uuid; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 5 { +impl Decodable for LeaderAndIsrTopicError { + fn decode(buf: &mut B, version: i16) -> Result { + let topic_id = if version >= 5 { types::Uuid.decode(buf)? } else { Uuid::nil() @@ -499,19 +511,18 @@ impl MapDecodable for LeaderAndIsrTopicError { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partition_errors, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic_id, + partition_errors, + unknown_tagged_fields, + }) } } impl Default for LeaderAndIsrTopicError { fn default() -> Self { Self { + topic_id: Uuid::nil(), partition_errors: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/leader_change_message.rs b/src/messages/leader_change_message.rs index 713362e..c889606 100644 --- a/src/messages/leader_change_message.rs +++ b/src/messages/leader_change_message.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/leave_group_request.rs b/src/messages/leave_group_request.rs index 7de245d..b5abddb 100644 --- a/src/messages/leave_group_request.rs +++ b/src/messages/leave_group_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/leave_group_response.rs b/src/messages/leave_group_response.rs index 8740290..c3dd882 100644 --- a/src/messages/leave_group_response.rs +++ b/src/messages/leave_group_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/list_client_metrics_resources_request.rs b/src/messages/list_client_metrics_resources_request.rs index a98a5da..707285f 100644 --- a/src/messages/list_client_metrics_resources_request.rs +++ b/src/messages/list_client_metrics_resources_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/list_client_metrics_resources_response.rs b/src/messages/list_client_metrics_resources_response.rs index b276288..33f28a9 100644 --- a/src/messages/list_client_metrics_resources_response.rs +++ b/src/messages/list_client_metrics_resources_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/list_groups_request.rs b/src/messages/list_groups_request.rs index c1bf002..8f7b981 100644 --- a/src/messages/list_groups_request.rs +++ b/src/messages/list_groups_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/list_groups_response.rs b/src/messages/list_groups_response.rs index b9959b2..6b72bb4 100644 --- a/src/messages/list_groups_response.rs +++ b/src/messages/list_groups_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/list_offsets_request.rs b/src/messages/list_offsets_request.rs index 8719285..01ed96e 100644 --- a/src/messages/list_offsets_request.rs +++ b/src/messages/list_offsets_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-8 diff --git a/src/messages/list_offsets_response.rs b/src/messages/list_offsets_response.rs index 4881998..3a95732 100644 --- a/src/messages/list_offsets_response.rs +++ b/src/messages/list_offsets_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-8 diff --git a/src/messages/list_partition_reassignments_request.rs b/src/messages/list_partition_reassignments_request.rs index 64e3a0f..a6cb3c5 100644 --- a/src/messages/list_partition_reassignments_request.rs +++ b/src/messages/list_partition_reassignments_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/list_partition_reassignments_response.rs b/src/messages/list_partition_reassignments_response.rs index e373942..3edb662 100644 --- a/src/messages/list_partition_reassignments_response.rs +++ b/src/messages/list_partition_reassignments_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/list_transactions_request.rs b/src/messages/list_transactions_request.rs index 83a0f93..b9f6dcb 100644 --- a/src/messages/list_transactions_request.rs +++ b/src/messages/list_transactions_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/list_transactions_response.rs b/src/messages/list_transactions_response.rs index c659fd4..87b26a7 100644 --- a/src/messages/list_transactions_response.rs +++ b/src/messages/list_transactions_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/metadata_request.rs b/src/messages/metadata_request.rs index c7ab970..63b0dbb 100644 --- a/src/messages/metadata_request.rs +++ b/src/messages/metadata_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-12 diff --git a/src/messages/metadata_response.rs b/src/messages/metadata_response.rs index 2480e39..68a0004 100644 --- a/src/messages/metadata_response.rs +++ b/src/messages/metadata_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-12 @@ -29,7 +29,7 @@ pub struct MetadataResponse { /// A list of brokers present in the cluster. /// /// Supported API versions: 0-12 - pub brokers: indexmap::IndexMap, + pub brokers: Vec, /// The cluster ID that responding broker belongs to. /// @@ -44,7 +44,7 @@ pub struct MetadataResponse { /// Each topic in the response. /// /// Supported API versions: 0-12 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// 32-bit bitfield to represent authorized operations for this cluster. /// @@ -70,10 +70,7 @@ impl MetadataResponse { /// A list of brokers present in the cluster. /// /// Supported API versions: 0-12 - pub fn with_brokers( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_brokers(mut self, value: Vec) -> Self { self.brokers = value; self } @@ -100,10 +97,7 @@ impl MetadataResponse { /// Each topic in the response. /// /// Supported API versions: 0-12 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -307,6 +301,11 @@ impl Message for MetadataResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MetadataResponseBroker { + /// The broker ID. + /// + /// Supported API versions: 0-12 + pub node_id: super::BrokerId, + /// The broker hostname. /// /// Supported API versions: 0-12 @@ -327,6 +326,15 @@ pub struct MetadataResponseBroker { } impl MetadataResponseBroker { + /// Sets `node_id` to the passed value. + /// + /// The broker ID. + /// + /// Supported API versions: 0-12 + pub fn with_node_id(mut self, value: super::BrokerId) -> Self { + self.node_id = value; + self + } /// Sets `host` to the passed value. /// /// The broker hostname. @@ -367,10 +375,9 @@ impl MetadataResponseBroker { } #[cfg(feature = "broker")] -impl MapEncodable for MetadataResponseBroker { - type Key = super::BrokerId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for MetadataResponseBroker { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.node_id)?; if version >= 9 { types::CompactString.encode(buf, &self.host)?; } else { @@ -398,9 +405,9 @@ impl MapEncodable for MetadataResponseBroker { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.node_id)?; if version >= 9 { total_size += types::CompactString.compute_size(&self.host)?; } else { @@ -431,10 +438,9 @@ impl MapEncodable for MetadataResponseBroker { } #[cfg(feature = "client")] -impl MapDecodable for MetadataResponseBroker { - type Key = super::BrokerId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for MetadataResponseBroker { + fn decode(buf: &mut B, version: i16) -> Result { + let node_id = types::Int32.decode(buf)?; let host = if version >= 9 { types::CompactString.decode(buf)? } else { @@ -460,21 +466,20 @@ impl MapDecodable for MetadataResponseBroker { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - host, - port, - rack, - unknown_tagged_fields, - }, - )) + Ok(Self { + node_id, + host, + port, + rack, + unknown_tagged_fields, + }) } } impl Default for MetadataResponseBroker { fn default() -> Self { Self { + node_id: (0).into(), host: Default::default(), port: 0, rack: None, @@ -771,6 +776,11 @@ pub struct MetadataResponseTopic { /// Supported API versions: 0-12 pub error_code: i16, + /// The topic name. Null for non-existing topics queried by ID. This is never null when ErrorCode is zero. One of Name and TopicId is always populated. + /// + /// Supported API versions: 0-12 + pub name: Option, + /// The topic id. Zero for non-existing topics queried by name. This is never zero when ErrorCode is zero. One of Name and TopicId is always populated. /// /// Supported API versions: 10-12 @@ -805,6 +815,15 @@ impl MetadataResponseTopic { self.error_code = value; self } + /// Sets `name` to the passed value. + /// + /// The topic name. Null for non-existing topics queried by ID. This is never null when ErrorCode is zero. One of Name and TopicId is always populated. + /// + /// Supported API versions: 0-12 + pub fn with_name(mut self, value: Option) -> Self { + self.name = value; + self + } /// Sets `topic_id` to the passed value. /// /// The topic id. Zero for non-existing topics queried by name. This is never zero when ErrorCode is zero. One of Name and TopicId is always populated. @@ -854,14 +873,13 @@ impl MetadataResponseTopic { } #[cfg(feature = "broker")] -impl MapEncodable for MetadataResponseTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for MetadataResponseTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { types::Int16.encode(buf, &self.error_code)?; if version >= 9 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 10 { types::Uuid.encode(buf, &self.topic_id)?; @@ -895,13 +913,13 @@ impl MapEncodable for MetadataResponseTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; total_size += types::Int16.compute_size(&self.error_code)?; if version >= 9 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 10 { total_size += types::Uuid.compute_size(&self.topic_id)?; @@ -939,11 +957,10 @@ impl MapEncodable for MetadataResponseTopic { } #[cfg(feature = "client")] -impl MapDecodable for MetadataResponseTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { +impl Decodable for MetadataResponseTopic { + fn decode(buf: &mut B, version: i16) -> Result { let error_code = types::Int16.decode(buf)?; - let key_field = if version >= 9 { + let name = if version >= 9 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -978,17 +995,15 @@ impl MapDecodable for MetadataResponseTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - error_code, - topic_id, - is_internal, - partitions, - topic_authorized_operations, - unknown_tagged_fields, - }, - )) + Ok(Self { + error_code, + name, + topic_id, + is_internal, + partitions, + topic_authorized_operations, + unknown_tagged_fields, + }) } } @@ -996,6 +1011,7 @@ impl Default for MetadataResponseTopic { fn default() -> Self { Self { error_code: 0, + name: Some(Default::default()), topic_id: Uuid::nil(), is_internal: false, partitions: Default::default(), diff --git a/src/messages/offset_commit_request.rs b/src/messages/offset_commit_request.rs index e4658f4..357f8a1 100644 --- a/src/messages/offset_commit_request.rs +++ b/src/messages/offset_commit_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 diff --git a/src/messages/offset_commit_response.rs b/src/messages/offset_commit_response.rs index 1bae847..29d61fb 100644 --- a/src/messages/offset_commit_response.rs +++ b/src/messages/offset_commit_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 diff --git a/src/messages/offset_delete_request.rs b/src/messages/offset_delete_request.rs index 0569959..3c678ee 100644 --- a/src/messages/offset_delete_request.rs +++ b/src/messages/offset_delete_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 @@ -29,7 +29,7 @@ pub struct OffsetDeleteRequest { /// The topics to delete offsets for /// /// Supported API versions: 0 - pub topics: indexmap::IndexMap, + pub topics: Vec, } impl OffsetDeleteRequest { @@ -47,10 +47,7 @@ impl OffsetDeleteRequest { /// The topics to delete offsets for /// /// Supported API versions: 0 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -156,6 +153,11 @@ impl Message for OffsetDeleteRequestPartition { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct OffsetDeleteRequestTopic { + /// The topic name. + /// + /// Supported API versions: 0 + pub name: super::TopicName, + /// Each partition to delete offsets for. /// /// Supported API versions: 0 @@ -163,6 +165,15 @@ pub struct OffsetDeleteRequestTopic { } impl OffsetDeleteRequestTopic { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partitions` to the passed value. /// /// Each partition to delete offsets for. @@ -175,17 +186,16 @@ impl OffsetDeleteRequestTopic { } #[cfg(feature = "client")] -impl MapEncodable for OffsetDeleteRequestTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::String.encode(buf, key)?; +impl Encodable for OffsetDeleteRequestTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::String.encode(buf, &self.name)?; types::Array(types::Struct { version }).encode(buf, &self.partitions)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?; Ok(total_size) @@ -193,18 +203,18 @@ impl MapEncodable for OffsetDeleteRequestTopic { } #[cfg(feature = "broker")] -impl MapDecodable for OffsetDeleteRequestTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::String.decode(buf)?; +impl Decodable for OffsetDeleteRequestTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::String.decode(buf)?; let partitions = types::Array(types::Struct { version }).decode(buf)?; - Ok((key_field, Self { partitions })) + Ok(Self { name, partitions }) } } impl Default for OffsetDeleteRequestTopic { fn default() -> Self { Self { + name: Default::default(), partitions: Default::default(), } } diff --git a/src/messages/offset_delete_response.rs b/src/messages/offset_delete_response.rs index 6e63c7d..f88c7e6 100644 --- a/src/messages/offset_delete_response.rs +++ b/src/messages/offset_delete_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 @@ -34,7 +34,7 @@ pub struct OffsetDeleteResponse { /// The responses for each topic. /// /// Supported API versions: 0 - pub topics: indexmap::IndexMap, + pub topics: Vec, } impl OffsetDeleteResponse { @@ -61,10 +61,7 @@ impl OffsetDeleteResponse { /// The responses for each topic. /// /// Supported API versions: 0 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -122,6 +119,11 @@ impl Message for OffsetDeleteResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct OffsetDeleteResponsePartition { + /// The partition index. + /// + /// Supported API versions: 0 + pub partition_index: i32, + /// The error code, or 0 if there was no error. /// /// Supported API versions: 0 @@ -129,6 +131,15 @@ pub struct OffsetDeleteResponsePartition { } impl OffsetDeleteResponsePartition { + /// Sets `partition_index` to the passed value. + /// + /// The partition index. + /// + /// Supported API versions: 0 + pub fn with_partition_index(mut self, value: i32) -> Self { + self.partition_index = value; + self + } /// Sets `error_code` to the passed value. /// /// The error code, or 0 if there was no error. @@ -141,17 +152,16 @@ impl OffsetDeleteResponsePartition { } #[cfg(feature = "broker")] -impl MapEncodable for OffsetDeleteResponsePartition { - type Key = i32; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::Int32.encode(buf, key)?; +impl Encodable for OffsetDeleteResponsePartition { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::Int32.encode(buf, &self.partition_index)?; types::Int16.encode(buf, &self.error_code)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.partition_index)?; total_size += types::Int16.compute_size(&self.error_code)?; Ok(total_size) @@ -159,18 +169,23 @@ impl MapEncodable for OffsetDeleteResponsePartition { } #[cfg(feature = "client")] -impl MapDecodable for OffsetDeleteResponsePartition { - type Key = i32; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::Int32.decode(buf)?; +impl Decodable for OffsetDeleteResponsePartition { + fn decode(buf: &mut B, version: i16) -> Result { + let partition_index = types::Int32.decode(buf)?; let error_code = types::Int16.decode(buf)?; - Ok((key_field, Self { error_code })) + Ok(Self { + partition_index, + error_code, + }) } } impl Default for OffsetDeleteResponsePartition { fn default() -> Self { - Self { error_code: 0 } + Self { + partition_index: 0, + error_code: 0, + } } } @@ -183,39 +198,49 @@ impl Message for OffsetDeleteResponsePartition { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct OffsetDeleteResponseTopic { + /// The topic name. + /// + /// Supported API versions: 0 + pub name: super::TopicName, + /// The responses for each partition in the topic. /// /// Supported API versions: 0 - pub partitions: indexmap::IndexMap, + pub partitions: Vec, } impl OffsetDeleteResponseTopic { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partitions` to the passed value. /// /// The responses for each partition in the topic. /// /// Supported API versions: 0 - pub fn with_partitions( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_partitions(mut self, value: Vec) -> Self { self.partitions = value; self } } #[cfg(feature = "broker")] -impl MapEncodable for OffsetDeleteResponseTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::String.encode(buf, key)?; +impl Encodable for OffsetDeleteResponseTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::String.encode(buf, &self.name)?; types::Array(types::Struct { version }).encode(buf, &self.partitions)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?; Ok(total_size) @@ -223,18 +248,18 @@ impl MapEncodable for OffsetDeleteResponseTopic { } #[cfg(feature = "client")] -impl MapDecodable for OffsetDeleteResponseTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::String.decode(buf)?; +impl Decodable for OffsetDeleteResponseTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::String.decode(buf)?; let partitions = types::Array(types::Struct { version }).decode(buf)?; - Ok((key_field, Self { partitions })) + Ok(Self { name, partitions }) } } impl Default for OffsetDeleteResponseTopic { fn default() -> Self { Self { + name: Default::default(), partitions: Default::default(), } } diff --git a/src/messages/offset_fetch_request.rs b/src/messages/offset_fetch_request.rs index 018f58d..772352c 100644 --- a/src/messages/offset_fetch_request.rs +++ b/src/messages/offset_fetch_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 diff --git a/src/messages/offset_fetch_response.rs b/src/messages/offset_fetch_response.rs index 76a69d6..5c6acf3 100644 --- a/src/messages/offset_fetch_response.rs +++ b/src/messages/offset_fetch_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-9 diff --git a/src/messages/offset_for_leader_epoch_request.rs b/src/messages/offset_for_leader_epoch_request.rs index 86baf9c..247be98 100644 --- a/src/messages/offset_for_leader_epoch_request.rs +++ b/src/messages/offset_for_leader_epoch_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 @@ -29,7 +29,7 @@ pub struct OffsetForLeaderEpochRequest { /// Each topic to get offsets for. /// /// Supported API versions: 0-4 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -50,10 +50,7 @@ impl OffsetForLeaderEpochRequest { /// Each topic to get offsets for. /// /// Supported API versions: 0-4 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -324,6 +321,11 @@ impl Message for OffsetForLeaderPartition { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct OffsetForLeaderTopic { + /// The topic name. + /// + /// Supported API versions: 0-4 + pub topic: super::TopicName, + /// Each partition to get offsets for. /// /// Supported API versions: 0-4 @@ -334,6 +336,15 @@ pub struct OffsetForLeaderTopic { } impl OffsetForLeaderTopic { + /// Sets `topic` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-4 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// Each partition to get offsets for. @@ -356,13 +367,12 @@ impl OffsetForLeaderTopic { } #[cfg(feature = "client")] -impl MapEncodable for OffsetForLeaderTopic { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for OffsetForLeaderTopic { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 4 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.topic)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.topic)?; } if version >= 4 { types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?; @@ -383,12 +393,12 @@ impl MapEncodable for OffsetForLeaderTopic { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 4 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.topic)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; } if version >= 4 { total_size += @@ -413,10 +423,9 @@ impl MapEncodable for OffsetForLeaderTopic { } #[cfg(feature = "broker")] -impl MapDecodable for OffsetForLeaderTopic { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 4 { +impl Decodable for OffsetForLeaderTopic { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = if version >= 4 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -436,19 +445,18 @@ impl MapDecodable for OffsetForLeaderTopic { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic, + partitions, + unknown_tagged_fields, + }) } } impl Default for OffsetForLeaderTopic { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/offset_for_leader_epoch_response.rs b/src/messages/offset_for_leader_epoch_response.rs index 54f0201..9d58b35 100644 --- a/src/messages/offset_for_leader_epoch_response.rs +++ b/src/messages/offset_for_leader_epoch_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 @@ -201,7 +201,7 @@ pub struct OffsetForLeaderEpochResponse { /// Each topic we fetched offsets for. /// /// Supported API versions: 0-4 - pub topics: indexmap::IndexMap, + pub topics: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -222,10 +222,7 @@ impl OffsetForLeaderEpochResponse { /// Each topic we fetched offsets for. /// /// Supported API versions: 0-4 - pub fn with_topics( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topics(mut self, value: Vec) -> Self { self.topics = value; self } @@ -343,6 +340,11 @@ impl Message for OffsetForLeaderEpochResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct OffsetForLeaderTopicResult { + /// The topic name. + /// + /// Supported API versions: 0-4 + pub topic: super::TopicName, + /// Each partition in the topic we fetched offsets for. /// /// Supported API versions: 0-4 @@ -353,6 +355,15 @@ pub struct OffsetForLeaderTopicResult { } impl OffsetForLeaderTopicResult { + /// Sets `topic` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-4 + pub fn with_topic(mut self, value: super::TopicName) -> Self { + self.topic = value; + self + } /// Sets `partitions` to the passed value. /// /// Each partition in the topic we fetched offsets for. @@ -375,13 +386,12 @@ impl OffsetForLeaderTopicResult { } #[cfg(feature = "broker")] -impl MapEncodable for OffsetForLeaderTopicResult { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for OffsetForLeaderTopicResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 4 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.topic)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.topic)?; } if version >= 4 { types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?; @@ -402,12 +412,12 @@ impl MapEncodable for OffsetForLeaderTopicResult { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 4 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.topic)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.topic)?; } if version >= 4 { total_size += @@ -432,10 +442,9 @@ impl MapEncodable for OffsetForLeaderTopicResult { } #[cfg(feature = "client")] -impl MapDecodable for OffsetForLeaderTopicResult { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 4 { +impl Decodable for OffsetForLeaderTopicResult { + fn decode(buf: &mut B, version: i16) -> Result { + let topic = if version >= 4 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -455,19 +464,18 @@ impl MapDecodable for OffsetForLeaderTopicResult { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partitions, - unknown_tagged_fields, - }, - )) + Ok(Self { + topic, + partitions, + unknown_tagged_fields, + }) } } impl Default for OffsetForLeaderTopicResult { fn default() -> Self { Self { + topic: Default::default(), partitions: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/produce_request.rs b/src/messages/produce_request.rs index 7556cf7..fb48c72 100644 --- a/src/messages/produce_request.rs +++ b/src/messages/produce_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-11 @@ -177,7 +177,7 @@ pub struct ProduceRequest { /// Each topic to produce to. /// /// Supported API versions: 0-11 - pub topic_data: indexmap::IndexMap, + pub topic_data: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -216,10 +216,7 @@ impl ProduceRequest { /// Each topic to produce to. /// /// Supported API versions: 0-11 - pub fn with_topic_data( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_topic_data(mut self, value: Vec) -> Self { self.topic_data = value; self } @@ -367,6 +364,11 @@ impl Message for ProduceRequest { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicProduceData { + /// The topic name. + /// + /// Supported API versions: 0-11 + pub name: super::TopicName, + /// Each partition to produce to. /// /// Supported API versions: 0-11 @@ -377,6 +379,15 @@ pub struct TopicProduceData { } impl TopicProduceData { + /// Sets `name` to the passed value. + /// + /// The topic name. + /// + /// Supported API versions: 0-11 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partition_data` to the passed value. /// /// Each partition to produce to. @@ -399,13 +410,12 @@ impl TopicProduceData { } #[cfg(feature = "client")] -impl MapEncodable for TopicProduceData { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for TopicProduceData { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 9 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 9 { types::CompactArray(types::Struct { version }).encode(buf, &self.partition_data)?; @@ -426,12 +436,12 @@ impl MapEncodable for TopicProduceData { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 9 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 9 { total_size += types::CompactArray(types::Struct { version }) @@ -457,10 +467,9 @@ impl MapEncodable for TopicProduceData { } #[cfg(feature = "broker")] -impl MapDecodable for TopicProduceData { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 9 { +impl Decodable for TopicProduceData { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 9 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -480,19 +489,18 @@ impl MapDecodable for TopicProduceData { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partition_data, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + partition_data, + unknown_tagged_fields, + }) } } impl Default for TopicProduceData { fn default() -> Self { Self { + name: Default::default(), partition_data: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/produce_response.rs b/src/messages/produce_response.rs index b66f1a1..287c417 100644 --- a/src/messages/produce_response.rs +++ b/src/messages/produce_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-11 @@ -349,6 +349,11 @@ impl Message for LeaderIdAndEpoch { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct NodeEndpoint { + /// The ID of the associated node. + /// + /// Supported API versions: 10-11 + pub node_id: super::BrokerId, + /// The node's hostname. /// /// Supported API versions: 10-11 @@ -369,6 +374,15 @@ pub struct NodeEndpoint { } impl NodeEndpoint { + /// Sets `node_id` to the passed value. + /// + /// The ID of the associated node. + /// + /// Supported API versions: 10-11 + pub fn with_node_id(mut self, value: super::BrokerId) -> Self { + self.node_id = value; + self + } /// Sets `host` to the passed value. /// /// The node's hostname. @@ -409,13 +423,12 @@ impl NodeEndpoint { } #[cfg(feature = "broker")] -impl MapEncodable for NodeEndpoint { - type Key = super::BrokerId; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for NodeEndpoint { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 10 { - types::Int32.encode(buf, key)?; + types::Int32.encode(buf, &self.node_id)?; } else { - if *key != 0 { + if self.node_id != 0 { bail!("failed to encode"); } } @@ -454,12 +467,12 @@ impl MapEncodable for NodeEndpoint { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 10 { - total_size += types::Int32.compute_size(key)?; + total_size += types::Int32.compute_size(&self.node_id)?; } else { - if *key != 0 { + if self.node_id != 0 { bail!("failed to encode"); } } @@ -501,10 +514,9 @@ impl MapEncodable for NodeEndpoint { } #[cfg(feature = "client")] -impl MapDecodable for NodeEndpoint { - type Key = super::BrokerId; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 10 { +impl Decodable for NodeEndpoint { + fn decode(buf: &mut B, version: i16) -> Result { + let node_id = if version >= 10 { types::Int32.decode(buf)? } else { (0).into() @@ -534,21 +546,20 @@ impl MapDecodable for NodeEndpoint { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - host, - port, - rack, - unknown_tagged_fields, - }, - )) + Ok(Self { + node_id, + host, + port, + rack, + unknown_tagged_fields, + }) } } impl Default for NodeEndpoint { fn default() -> Self { Self { + node_id: (0).into(), host: Default::default(), port: 0, rack: None, @@ -914,7 +925,7 @@ pub struct ProduceResponse { /// Each produce response /// /// Supported API versions: 0-11 - pub responses: indexmap::IndexMap, + pub responses: Vec, /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota. /// @@ -924,7 +935,7 @@ pub struct ProduceResponse { /// Endpoints for all current-leaders enumerated in PartitionProduceResponses, with errors NOT_LEADER_OR_FOLLOWER. /// /// Supported API versions: 10-11 - pub node_endpoints: indexmap::IndexMap, + pub node_endpoints: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -936,10 +947,7 @@ impl ProduceResponse { /// Each produce response /// /// Supported API versions: 0-11 - pub fn with_responses( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_responses(mut self, value: Vec) -> Self { self.responses = value; self } @@ -957,10 +965,7 @@ impl ProduceResponse { /// Endpoints for all current-leaders enumerated in PartitionProduceResponses, with errors NOT_LEADER_OR_FOLLOWER. /// /// Supported API versions: 10-11 - pub fn with_node_endpoints( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_node_endpoints(mut self, value: Vec) -> Self { self.node_endpoints = value; self } @@ -1132,6 +1137,11 @@ impl Message for ProduceResponse { #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TopicProduceResponse { + /// The topic name + /// + /// Supported API versions: 0-11 + pub name: super::TopicName, + /// Each partition that we produced to within the topic. /// /// Supported API versions: 0-11 @@ -1142,6 +1152,15 @@ pub struct TopicProduceResponse { } impl TopicProduceResponse { + /// Sets `name` to the passed value. + /// + /// The topic name + /// + /// Supported API versions: 0-11 + pub fn with_name(mut self, value: super::TopicName) -> Self { + self.name = value; + self + } /// Sets `partition_responses` to the passed value. /// /// Each partition that we produced to within the topic. @@ -1164,13 +1183,12 @@ impl TopicProduceResponse { } #[cfg(feature = "broker")] -impl MapEncodable for TopicProduceResponse { - type Key = super::TopicName; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { +impl Encodable for TopicProduceResponse { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { if version >= 9 { - types::CompactString.encode(buf, key)?; + types::CompactString.encode(buf, &self.name)?; } else { - types::String.encode(buf, key)?; + types::String.encode(buf, &self.name)?; } if version >= 9 { types::CompactArray(types::Struct { version }) @@ -1192,12 +1210,12 @@ impl MapEncodable for TopicProduceResponse { } Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; if version >= 9 { - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; } else { - total_size += types::String.compute_size(key)?; + total_size += types::String.compute_size(&self.name)?; } if version >= 9 { total_size += types::CompactArray(types::Struct { version }) @@ -1223,10 +1241,9 @@ impl MapEncodable for TopicProduceResponse { } #[cfg(feature = "client")] -impl MapDecodable for TopicProduceResponse { - type Key = super::TopicName; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = if version >= 9 { +impl Decodable for TopicProduceResponse { + fn decode(buf: &mut B, version: i16) -> Result { + let name = if version >= 9 { types::CompactString.decode(buf)? } else { types::String.decode(buf)? @@ -1246,19 +1263,18 @@ impl MapDecodable for TopicProduceResponse { unknown_tagged_fields.insert(tag as i32, unknown_value); } } - Ok(( - key_field, - Self { - partition_responses, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + partition_responses, + unknown_tagged_fields, + }) } } impl Default for TopicProduceResponse { fn default() -> Self { Self { + name: Default::default(), partition_responses: Default::default(), unknown_tagged_fields: BTreeMap::new(), } diff --git a/src/messages/push_telemetry_request.rs b/src/messages/push_telemetry_request.rs index 74d2abd..310cd4d 100644 --- a/src/messages/push_telemetry_request.rs +++ b/src/messages/push_telemetry_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/push_telemetry_response.rs b/src/messages/push_telemetry_response.rs index 64651e4..2b3892e 100644 --- a/src/messages/push_telemetry_response.rs +++ b/src/messages/push_telemetry_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/renew_delegation_token_request.rs b/src/messages/renew_delegation_token_request.rs index 6a26ae2..4940283 100644 --- a/src/messages/renew_delegation_token_request.rs +++ b/src/messages/renew_delegation_token_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/renew_delegation_token_response.rs b/src/messages/renew_delegation_token_response.rs index c24b49f..57a2cc6 100644 --- a/src/messages/renew_delegation_token_response.rs +++ b/src/messages/renew_delegation_token_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/request_header.rs b/src/messages/request_header.rs index 35d18ff..04075a6 100644 --- a/src/messages/request_header.rs +++ b/src/messages/request_header.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/response_header.rs b/src/messages/response_header.rs index f994f79..675a6b5 100644 --- a/src/messages/response_header.rs +++ b/src/messages/response_header.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/sasl_authenticate_request.rs b/src/messages/sasl_authenticate_request.rs index dda4648..a0804e6 100644 --- a/src/messages/sasl_authenticate_request.rs +++ b/src/messages/sasl_authenticate_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/sasl_authenticate_response.rs b/src/messages/sasl_authenticate_response.rs index 7784088..7cd0fca 100644 --- a/src/messages/sasl_authenticate_response.rs +++ b/src/messages/sasl_authenticate_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-2 diff --git a/src/messages/sasl_handshake_request.rs b/src/messages/sasl_handshake_request.rs index 1a76ea5..f802034 100644 --- a/src/messages/sasl_handshake_request.rs +++ b/src/messages/sasl_handshake_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/sasl_handshake_response.rs b/src/messages/sasl_handshake_response.rs index e8d0d33..13a62d3 100644 --- a/src/messages/sasl_handshake_response.rs +++ b/src/messages/sasl_handshake_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/snapshot_footer_record.rs b/src/messages/snapshot_footer_record.rs index eb81684..a08eeea 100644 --- a/src/messages/snapshot_footer_record.rs +++ b/src/messages/snapshot_footer_record.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/snapshot_header_record.rs b/src/messages/snapshot_header_record.rs index 5daf5b8..a657e42 100644 --- a/src/messages/snapshot_header_record.rs +++ b/src/messages/snapshot_header_record.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/stop_replica_request.rs b/src/messages/stop_replica_request.rs index 405f230..d701a4c 100644 --- a/src/messages/stop_replica_request.rs +++ b/src/messages/stop_replica_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/stop_replica_response.rs b/src/messages/stop_replica_response.rs index fd2dc8a..f27487e 100644 --- a/src/messages/stop_replica_response.rs +++ b/src/messages/stop_replica_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/sync_group_request.rs b/src/messages/sync_group_request.rs index 09f4006..3c1d13b 100644 --- a/src/messages/sync_group_request.rs +++ b/src/messages/sync_group_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/sync_group_response.rs b/src/messages/sync_group_response.rs index 2e1e986..5a7afab 100644 --- a/src/messages/sync_group_response.rs +++ b/src/messages/sync_group_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-5 diff --git a/src/messages/txn_offset_commit_request.rs b/src/messages/txn_offset_commit_request.rs index e741361..5fe39d1 100644 --- a/src/messages/txn_offset_commit_request.rs +++ b/src/messages/txn_offset_commit_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/txn_offset_commit_response.rs b/src/messages/txn_offset_commit_response.rs index e0d6221..8336db5 100644 --- a/src/messages/txn_offset_commit_response.rs +++ b/src/messages/txn_offset_commit_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-4 diff --git a/src/messages/unregister_broker_request.rs b/src/messages/unregister_broker_request.rs index eddf37f..d235a40 100644 --- a/src/messages/unregister_broker_request.rs +++ b/src/messages/unregister_broker_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/unregister_broker_response.rs b/src/messages/unregister_broker_response.rs index 4f4a274..4cc402e 100644 --- a/src/messages/unregister_broker_response.rs +++ b/src/messages/unregister_broker_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/update_features_request.rs b/src/messages/update_features_request.rs index b95bb80..4731c8e 100644 --- a/src/messages/update_features_request.rs +++ b/src/messages/update_features_request.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct FeatureUpdateKey { + /// The name of the finalized feature to be updated. + /// + /// Supported API versions: 0-1 + pub feature: StrBytes, + /// The new maximum version level for the finalized feature. A value >= 1 is valid. A value < 1, is special, and can be used to request the deletion of the finalized feature. /// /// Supported API versions: 0-1 @@ -41,6 +46,15 @@ pub struct FeatureUpdateKey { } impl FeatureUpdateKey { + /// Sets `feature` to the passed value. + /// + /// The name of the finalized feature to be updated. + /// + /// Supported API versions: 0-1 + pub fn with_feature(mut self, value: StrBytes) -> Self { + self.feature = value; + self + } /// Sets `max_version_level` to the passed value. /// /// The new maximum version level for the finalized feature. A value >= 1 is valid. A value < 1, is special, and can be used to request the deletion of the finalized feature. @@ -81,10 +95,9 @@ impl FeatureUpdateKey { } #[cfg(feature = "client")] -impl MapEncodable for FeatureUpdateKey { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for FeatureUpdateKey { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.feature)?; types::Int16.encode(buf, &self.max_version_level)?; if version == 0 { types::Boolean.encode(buf, &self.allow_downgrade)?; @@ -112,9 +125,9 @@ impl MapEncodable for FeatureUpdateKey { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.feature)?; total_size += types::Int16.compute_size(&self.max_version_level)?; if version == 0 { total_size += types::Boolean.compute_size(&self.allow_downgrade)?; @@ -145,10 +158,9 @@ impl MapEncodable for FeatureUpdateKey { } #[cfg(feature = "broker")] -impl MapDecodable for FeatureUpdateKey { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for FeatureUpdateKey { + fn decode(buf: &mut B, version: i16) -> Result { + let feature = types::CompactString.decode(buf)?; let max_version_level = types::Int16.decode(buf)?; let allow_downgrade = if version == 0 { types::Boolean.decode(buf)? @@ -168,21 +180,20 @@ impl MapDecodable for FeatureUpdateKey { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - max_version_level, - allow_downgrade, - upgrade_type, - unknown_tagged_fields, - }, - )) + Ok(Self { + feature, + max_version_level, + allow_downgrade, + upgrade_type, + unknown_tagged_fields, + }) } } impl Default for FeatureUpdateKey { fn default() -> Self { Self { + feature: Default::default(), max_version_level: 0, allow_downgrade: false, upgrade_type: 1, @@ -208,7 +219,7 @@ pub struct UpdateFeaturesRequest { /// The list of updates to finalized features. /// /// Supported API versions: 0-1 - pub feature_updates: indexmap::IndexMap, + pub feature_updates: Vec, /// True if we should validate the request, but not perform the upgrade or downgrade. /// @@ -234,10 +245,7 @@ impl UpdateFeaturesRequest { /// The list of updates to finalized features. /// /// Supported API versions: 0-1 - pub fn with_feature_updates( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_feature_updates(mut self, value: Vec) -> Self { self.feature_updates = value; self } diff --git a/src/messages/update_features_response.rs b/src/messages/update_features_response.rs index d5194c6..6476456 100644 --- a/src/messages/update_features_response.rs +++ b/src/messages/update_features_response.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct UpdatableFeatureResult { + /// The name of the finalized feature. + /// + /// Supported API versions: 0-1 + pub feature: StrBytes, + /// The feature update error code or `0` if the feature update succeeded. /// /// Supported API versions: 0-1 @@ -36,6 +41,15 @@ pub struct UpdatableFeatureResult { } impl UpdatableFeatureResult { + /// Sets `feature` to the passed value. + /// + /// The name of the finalized feature. + /// + /// Supported API versions: 0-1 + pub fn with_feature(mut self, value: StrBytes) -> Self { + self.feature = value; + self + } /// Sets `error_code` to the passed value. /// /// The feature update error code or `0` if the feature update succeeded. @@ -67,10 +81,9 @@ impl UpdatableFeatureResult { } #[cfg(feature = "broker")] -impl MapEncodable for UpdatableFeatureResult { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for UpdatableFeatureResult { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.feature)?; types::Int16.encode(buf, &self.error_code)?; types::CompactString.encode(buf, &self.error_message)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -85,9 +98,9 @@ impl MapEncodable for UpdatableFeatureResult { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.feature)?; total_size += types::Int16.compute_size(&self.error_code)?; total_size += types::CompactString.compute_size(&self.error_message)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -105,10 +118,9 @@ impl MapEncodable for UpdatableFeatureResult { } #[cfg(feature = "client")] -impl MapDecodable for UpdatableFeatureResult { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for UpdatableFeatureResult { + fn decode(buf: &mut B, version: i16) -> Result { + let feature = types::CompactString.decode(buf)?; let error_code = types::Int16.decode(buf)?; let error_message = types::CompactString.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -119,20 +131,19 @@ impl MapDecodable for UpdatableFeatureResult { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - error_code, - error_message, - unknown_tagged_fields, - }, - )) + Ok(Self { + feature, + error_code, + error_message, + unknown_tagged_fields, + }) } } impl Default for UpdatableFeatureResult { fn default() -> Self { Self { + feature: Default::default(), error_code: 0, error_message: Some(Default::default()), unknown_tagged_fields: BTreeMap::new(), @@ -167,7 +178,7 @@ pub struct UpdateFeaturesResponse { /// Results for each feature update. /// /// Supported API versions: 0-1 - pub results: indexmap::IndexMap, + pub results: Vec, /// Other tagged fields pub unknown_tagged_fields: BTreeMap, @@ -206,10 +217,7 @@ impl UpdateFeaturesResponse { /// Results for each feature update. /// /// Supported API versions: 0-1 - pub fn with_results( - mut self, - value: indexmap::IndexMap, - ) -> Self { + pub fn with_results(mut self, value: Vec) -> Self { self.results = value; self } diff --git a/src/messages/update_metadata_request.rs b/src/messages/update_metadata_request.rs index fb411f2..8150e78 100644 --- a/src/messages/update_metadata_request.rs +++ b/src/messages/update_metadata_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-8 diff --git a/src/messages/update_metadata_response.rs b/src/messages/update_metadata_response.rs index 28e0741..3a27b7d 100644 --- a/src/messages/update_metadata_response.rs +++ b/src/messages/update_metadata_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-8 diff --git a/src/messages/vote_request.rs b/src/messages/vote_request.rs index 684def8..051dcba 100644 --- a/src/messages/vote_request.rs +++ b/src/messages/vote_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/vote_response.rs b/src/messages/vote_response.rs index 98f625d..557ae3a 100644 --- a/src/messages/vote_response.rs +++ b/src/messages/vote_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 diff --git a/src/messages/voters_record.rs b/src/messages/voters_record.rs index e140f4c..2590b89 100644 --- a/src/messages/voters_record.rs +++ b/src/messages/voters_record.rs @@ -14,13 +14,18 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0 #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Endpoint { + /// The name of the endpoint + /// + /// Supported API versions: 0 + pub name: StrBytes, + /// The hostname /// /// Supported API versions: 0 @@ -36,6 +41,15 @@ pub struct Endpoint { } impl Endpoint { + /// Sets `name` to the passed value. + /// + /// The name of the endpoint + /// + /// Supported API versions: 0 + pub fn with_name(mut self, value: StrBytes) -> Self { + self.name = value; + self + } /// Sets `host` to the passed value. /// /// The hostname @@ -66,10 +80,9 @@ impl Endpoint { } } -impl MapEncodable for Endpoint { - type Key = StrBytes; - fn encode(&self, key: &Self::Key, buf: &mut B, version: i16) -> Result<()> { - types::CompactString.encode(buf, key)?; +impl Encodable for Endpoint { + fn encode(&self, buf: &mut B, version: i16) -> Result<()> { + types::CompactString.encode(buf, &self.name)?; types::CompactString.encode(buf, &self.host)?; types::UInt16.encode(buf, &self.port)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -84,9 +97,9 @@ impl MapEncodable for Endpoint { write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?; Ok(()) } - fn compute_size(&self, key: &Self::Key, version: i16) -> Result { + fn compute_size(&self, version: i16) -> Result { let mut total_size = 0; - total_size += types::CompactString.compute_size(key)?; + total_size += types::CompactString.compute_size(&self.name)?; total_size += types::CompactString.compute_size(&self.host)?; total_size += types::UInt16.compute_size(&self.port)?; let num_tagged_fields = self.unknown_tagged_fields.len(); @@ -103,10 +116,9 @@ impl MapEncodable for Endpoint { } } -impl MapDecodable for Endpoint { - type Key = StrBytes; - fn decode(buf: &mut B, version: i16) -> Result<(Self::Key, Self)> { - let key_field = types::CompactString.decode(buf)?; +impl Decodable for Endpoint { + fn decode(buf: &mut B, version: i16) -> Result { + let name = types::CompactString.decode(buf)?; let host = types::CompactString.decode(buf)?; let port = types::UInt16.decode(buf)?; let mut unknown_tagged_fields = BTreeMap::new(); @@ -117,20 +129,19 @@ impl MapDecodable for Endpoint { let unknown_value = buf.try_get_bytes(size as usize)?; unknown_tagged_fields.insert(tag as i32, unknown_value); } - Ok(( - key_field, - Self { - host, - port, - unknown_tagged_fields, - }, - )) + Ok(Self { + name, + host, + port, + unknown_tagged_fields, + }) } } impl Default for Endpoint { fn default() -> Self { Self { + name: Default::default(), host: Default::default(), port: 0, unknown_tagged_fields: BTreeMap::new(), @@ -278,7 +289,7 @@ pub struct Voter { /// The endpoint that can be used to communicate with the voter /// /// Supported API versions: 0 - pub endpoints: indexmap::IndexMap, + pub endpoints: Vec, /// The range of versions of the protocol that the replica supports /// @@ -313,7 +324,7 @@ impl Voter { /// The endpoint that can be used to communicate with the voter /// /// Supported API versions: 0 - pub fn with_endpoints(mut self, value: indexmap::IndexMap) -> Self { + pub fn with_endpoints(mut self, value: Vec) -> Self { self.endpoints = value; self } diff --git a/src/messages/write_txn_markers_request.rs b/src/messages/write_txn_markers_request.rs index 2bfc0f0..f6cfd32 100644 --- a/src/messages/write_txn_markers_request.rs +++ b/src/messages/write_txn_markers_request.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/src/messages/write_txn_markers_response.rs b/src/messages/write_txn_markers_response.rs index 7156ff0..d49371a 100644 --- a/src/messages/write_txn_markers_response.rs +++ b/src/messages/write_txn_markers_response.rs @@ -14,7 +14,7 @@ use uuid::Uuid; use crate::protocol::{ buf::{ByteBuf, ByteBufMut}, compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder, - Encodable, Encoder, HeaderVersion, MapDecodable, MapEncodable, Message, StrBytes, VersionRange, + Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange, }; /// Valid versions: 0-1 diff --git a/tests/all_tests/produce_fetch.rs b/tests/all_tests/produce_fetch.rs index 259d101..13114b8 100644 --- a/tests/all_tests/produce_fetch.rs +++ b/tests/all_tests/produce_fetch.rs @@ -96,23 +96,19 @@ fn create_topic(topic_name: TopicName, socket: &mut TcpStream) { let request = CreateTopicsRequest::default() .with_timeout_ms(5000) - .with_topics( - [( - topic_name.clone(), - CreatableTopic::default() - .with_num_partitions(1) - .with_replication_factor(1), - )] - .into(), - ); + .with_topics(vec![CreatableTopic::default() + .with_num_partitions(1) + .with_name(topic_name.clone()) + .with_replication_factor(1)]); send_request(socket, header, request); let result: CreateTopicsResponse = receive_response(socket, version).1; assert_eq!(result.throttle_time_ms, 0, "response throttle time"); - let topic = result.topics.get(&topic_name).unwrap(); + let topic = result.topics.first().unwrap(); + assert_eq!(topic.name, topic_name, "topic name"); assert_eq!(topic.error_code, 0, "topic error code"); assert_eq!(topic.error_message, None, "topic error message"); } @@ -125,17 +121,11 @@ fn produce_records(topic_name: TopicName, version: i16, records: Bytes, socket: let request = ProduceRequest::default() .with_acks(1) .with_timeout_ms(5000) - .with_topic_data( - [( - topic_name.clone(), - TopicProduceData::default().with_partition_data(vec![ - PartitionProduceData::default() - .with_index(0) - .with_records(Some(records)), - ]), - )] - .into(), - ); + .with_topic_data(vec![TopicProduceData::default() + .with_name(topic_name.clone()) + .with_partition_data(vec![PartitionProduceData::default() + .with_index(0) + .with_records(Some(records))])]); send_request(socket, header, request); @@ -143,7 +133,11 @@ fn produce_records(topic_name: TopicName, version: i16, records: Bytes, socket: assert_eq!(result.throttle_time_ms, 0, "produce response throttle time"); - let topic_response = result.responses.get(&topic_name).unwrap(); + let topic_response = result.responses.first().unwrap(); + assert_eq!( + topic_response.name, topic_name, + "produce response partition index" + ); let partition_response = topic_response.partition_responses.first().unwrap(); assert_eq!(