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

Rename messages_enum -> messages_enums #72

Merged
merged 1 commit into from
Sep 4, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ keywords = ["kafka"]
[features]
# adds the ResponseKind + RequestKind enums with variants for every message type.
# disabled by default since it doubles clean release build times due to lots of generated code.
messages_enum = []
messages_enums = []
# Enable this feature if you are implementing a kafka client.
# It will enable encoding of requests and decoding of responses.
client = []
Expand Down
22 changes: 11 additions & 11 deletions protocol_codegen/src/generate_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ pub fn run() -> Result<(), Error> {
)?;
writeln!(module_file, "use crate::protocol::Request;")?;
writeln!(module_file, "use std::convert::TryFrom;")?;
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(
module_file,
"#[cfg(any(feature = \"client\", feature = \"broker\"))]"
)?;
writeln!(module_file, "use crate::protocol::Encodable;")?;
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(
module_file,
"#[cfg(any(feature = \"client\", feature = \"broker\"))]"
)?;
writeln!(module_file, "use crate::protocol::Decodable;")?;
writeln!(module_file, "use anyhow::Result;")?;
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(
module_file,
"#[cfg(any(feature = \"client\", feature = \"broker\"))]"
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn run() -> Result<(), Error> {
module_file,
"/// Wrapping enum for all requests in the Kafka protocol."
)?;
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(module_file, "#[non_exhaustive]")?;
writeln!(module_file, "#[derive(Debug, Clone, PartialEq)]")?;
writeln!(module_file, "pub enum RequestKind {{")?;
Expand All @@ -296,7 +296,7 @@ pub fn run() -> Result<(), Error> {
writeln!(module_file, "}}")?;
writeln!(module_file)?;

writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(module_file, "impl RequestKind {{")?;
writeln!(module_file, "/// Encode the message into the target buffer")?;
writeln!(module_file, "#[cfg(feature = \"client\")]")?;
Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn run() -> Result<(), Error> {
writeln!(module_file, "}}")?;

for (_, request_type) in request_types.iter() {
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(module_file, "impl From<{request_type}> for RequestKind {{")?;
writeln!(
module_file,
Expand All @@ -354,7 +354,7 @@ pub fn run() -> Result<(), Error> {
writeln!(
module_file,
r#"
#[cfg(feature = "messages_enum")]
#[cfg(feature = "messages_enums")]
#[cfg(any(feature = "client", feature = "broker"))]
fn decode<T: Decodable>(bytes: &mut bytes::Bytes, version: i16) -> Result<T> {{
T::decode(bytes, version).with_context(|| {{
Expand All @@ -366,7 +366,7 @@ fn decode<T: Decodable>(bytes: &mut bytes::Bytes, version: i16) -> Result<T> {{
}})
}}

#[cfg(feature = "messages_enum")]
#[cfg(feature = "messages_enums")]
#[cfg(any(feature = "client", feature = "broker"))]
fn encode<T: Encodable>(encodable: &T, bytes: &mut bytes::BytesMut, version: i16) -> Result<()> {{
encodable.encode(bytes, version).with_context(|| {{
Expand All @@ -386,7 +386,7 @@ fn encode<T: Encodable>(encodable: &T, bytes: &mut bytes::BytesMut, version: i16
)?;
writeln!(module_file, "#[non_exhaustive]")?;
writeln!(module_file, "#[derive(Debug, Clone, PartialEq)]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(module_file, "pub enum ResponseKind {{")?;
for (_, response_type) in response_types.iter() {
writeln!(module_file, " /// {},", response_type)?;
Expand All @@ -400,7 +400,7 @@ fn encode<T: Encodable>(encodable: &T, bytes: &mut bytes::BytesMut, version: i16
writeln!(module_file, "}}")?;
writeln!(module_file)?;

writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(module_file, "impl ResponseKind {{")?;
writeln!(module_file, "/// Encode the message into the target buffer")?;
writeln!(module_file, "#[cfg(feature = \"broker\")]")?;
Expand Down Expand Up @@ -461,7 +461,7 @@ fn encode<T: Encodable>(encodable: &T, bytes: &mut bytes::BytesMut, version: i16
writeln!(module_file)?;

for (_, response_type) in response_types.iter() {
writeln!(module_file, "#[cfg(feature = \"messages_enum\")]")?;
writeln!(module_file, "#[cfg(feature = \"messages_enums\")]")?;
writeln!(
module_file,
"impl From<{response_type}> for ResponseKind {{"
Expand Down
Loading