Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change] remove "Key" suffix from ApiKey variants #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use kafka_protocol::protocol::StrBytes;

let mut header = RequestHeader::default();
header.client_id = Some(StrBytes::from_static_str("my-client"));
header.request_api_key = ApiKey::MetadataKey as i16;
header.request_api_key = ApiKey::Metadata as i16;
header.request_api_version = 12;

let mut request = MetadataRequest::default();
Expand All @@ -38,7 +38,7 @@ use kafka_protocol::protocol::StrBytes;

let header = RequestHeader::default()
.with_client_id(Some(StrBytes::from_static_str("my-client")))
.with_request_api_key(ApiKey::MetadataKey as i16)
.with_request_api_key(ApiKey::Metadata as i16)
.with_request_api_version(12);

let request = MetadataRequest::default()
Expand Down
12 changes: 6 additions & 6 deletions protocol_codegen/src/generate_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn run(messages_module_dir: &str, mut input_file_paths: Vec<PathBuf>) -> Res
writeln!(
m,
" {} = {},",
request_type.replace("Request", "Key"),
request_type.replace("Request", ""),
api_key
)?;
}
Expand All @@ -153,7 +153,7 @@ pub fn run(messages_module_dir: &str, mut input_file_paths: Vec<PathBuf>) -> Res
writeln!(
m,
" ApiKey::{} => {}::header_version(version),",
request_type.replace("Request", "Key"),
request_type.replace("Request", ""),
request_type
)?;
}
Expand All @@ -173,7 +173,7 @@ pub fn run(messages_module_dir: &str, mut input_file_paths: Vec<PathBuf>) -> Res
writeln!(
m,
" ApiKey::{} => {}::header_version(version),",
response_type.replace("Response", "Key"),
response_type.replace("Response", ""),
response_type
)?;
}
Expand All @@ -187,7 +187,7 @@ pub fn run(messages_module_dir: &str, mut input_file_paths: Vec<PathBuf>) -> Res
writeln!(m, " fn try_from(v: i16) -> Result<Self, Self::Error> {{")?;
writeln!(m, " match v {{")?;
for (_, request_type) in request_types.iter() {
let key = request_type.replace("Request", "Key");
let key = request_type.replace("Request", "");
writeln!(
m,
" x if x == ApiKey::{} as i16 => Ok(ApiKey::{}),",
Expand Down Expand Up @@ -250,7 +250,7 @@ pub fn run(messages_module_dir: &str, mut input_file_paths: Vec<PathBuf>) -> Res
let variant = request_type.trim_end_matches("Request");
writeln!(
m,
"ApiKey::{variant}Key => Ok(RequestKind::{variant}(decode(bytes, version)?)),"
"ApiKey::{variant} => Ok(RequestKind::{variant}(decode(bytes, version)?)),"
)?;
}
writeln!(m, "}}")?;
Expand Down Expand Up @@ -351,7 +351,7 @@ fn encode<T: Encodable>(encodable: &T, bytes: &mut bytes::BytesMut, version: i16
let variant = response_type.trim_end_matches("Response");
writeln!(
m,
"ApiKey::{variant}Key => Ok(ResponseKind::{variant}(decode(bytes, version)?)),"
"ApiKey::{variant} => Ok(ResponseKind::{variant}(decode(bytes, version)?)),"
)?;
}
writeln!(m, "}}")?;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//! let mut buf = BytesMut::new();
//! let mut req_header = RequestHeader::default();
//! req_header.request_api_version = 3;
//! req_header.request_api_key = ApiKey::ApiVersionsKey as i16;
//! req_header.request_api_key = ApiKey::ApiVersions as i16;
//! req_header.client_id = Some(StrBytes::from_static_str("example"));
//! req_header.encode(&mut buf, ApiVersionsRequest::header_version(req_header.request_api_version)).unwrap();
//! let mut api_versions_req = ApiVersionsRequest::default();
Expand Down Expand Up @@ -76,7 +76,7 @@
//! # let mut buf = BytesMut::new();
//! # let mut req_header = RequestHeader::default();
//! # req_header.request_api_version = 3;
//! # req_header.request_api_key = ApiKey::ApiVersionsKey as i16;
//! # req_header.request_api_key = ApiKey::ApiVersions as i16;
//! # req_header.client_id = Some(StrBytes::from_static_str("example"));
//! # req_header.encode(&mut buf, ApiVersionsRequest::header_version(req_header.request_api_version)).unwrap();
//! # let mut api_versions_req = ApiVersionsRequest::default();
Expand Down
Loading