-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add helper methods to RequestKind and ResponseKind #70
Add helper methods to RequestKind and ResponseKind #70
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
Per your comment about features and compile times, I think that makes a ton of sense. The enums also tend to be less useful for clients. I'm going to put this in a 0.12
milestone with the assumption we can start at least with those features and maybe a client/broker feature later if you have time. 👍
Thanks for the work!
module_file, | ||
r#" | ||
fn decode<T: Decodable>(bytes: &mut bytes::Bytes, version: i16) -> Result<T> {{ | ||
T::decode(bytes, version).with_context(|| {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: needs indentation
e6bf84a
to
3659a77
Compare
Thanks for feedback, should be addressed now. |
3659a77
to
4364265
Compare
4364265
to
1406639
Compare
@@ -32,4 +32,5 @@ jobs: | |||
- uses: dtolnay/rust-toolchain@stable | |||
with: | |||
components: clippy | |||
- run: cargo clippy --workspace -- -D warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@rukai any other changes you have on the horizon or do you want me to release |
I'll have a look into the client and broker features first |
This PR is a first step towards providing a higher level API for encoding and decoding messages.
Given the existence of the RequestKind and ResponseKind enums which has a variant for every possible request/response, it makes sense that the user would be matching on these enums and calling methods on the contained objects.
So this PR generates encode, decode and header_version methods on RequestKind/ResponseKind, to easily call into the contained object.
As an example, it will drastically simplify the implementation of the project I work on, which previously had these matches written out by hand: https://github.com/shotover/shotover-proxy/pull/1736/files
I think that a further high level API can be written on top of this to simplify header/body encoding/decoding.
Also worth noting that its actually impossible to implement such a match on
RequestKind
/ResponseKind
outside of the kafka-protocol crate due to the#[non_exhaustive]
.We currently have to use our own enums instead of kafka-protocol to ensure that we exhaustively handle encoding/decoding every message type.
Compile times
I've measured that this PR increases release build time of kafka-protocol from 7s to 14s.
I dont believe this would impact compile time of the final binary, if these methods are not used.
Still, for cold builds this is pretty bad.
So, wow do you feel about putting
RequestKind
/ResponseKind
behind a feature flag so this doesnt impact users who dont touchRequestKind
/ResponseKind
?I think that
RequestKind
/ResponseKind
, doesnt really provide any value without these new methods, so I think including them all in a single feature flag sounds reasonable to me.Another possible compile time win
Another improvement to compile time that could help here is to add a
client
feature and abroker
feature such that.client
enables encoding for requests and decoding for responsesbroker
enables encoding for responses and decoding for requests.Both features can be enabled for proxy use cases.
This would have the impact for client or broker implementations.
But it would go a in a follow up PR and while it shouldnt be difficult, it will take some time to implement.