-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(build): Better support for custom codecs #999
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.
I like this a lot! I think just need to add some docs and we can merge this. Thanks!
tonic-build/src/rust.rs
Outdated
} | ||
} | ||
|
||
#[test] |
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.
cfg test?
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.
Yeah i just whipped this together to see what you thought so now that I know you're interested i'll clean it up with docs and the like
Ok this should be ready for a serious review now. My main question is how you want to handle the module naming, right now its all just in a public module |
@bmwill how about |
@LucioFranco yeah |
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.
Overall looks great left a few comments/questions.
} | ||
} | ||
|
||
struct ServiceGenerator { |
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.
Do we actually need this extra struct? I don't mind keeping it just seems like we could just embed the code in the compile
method?
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.
I was sort of following the pattern as exists in the prost.rs
file. The extra struct sort of helps with the bookkeeping so it's probably worth keeping just for keeping the compile method simple.
This patch adds the `rust` module to tonic-build which provides utilities for declaratively defining services in rust code instead of via the traditional method of defining a service in a `proto` file. It also enables setting a custom `Codec` to in order to use a custom serialization format other than `protobuf`.
@LucioFranco Ok I've updated the PR, hopefully addressing all of your comments |
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.
Thanks! LGTM
@zbysir Ah interesting! Yeah one thing this change does not handle is looking at/changing the content-type header. I did ask @LucioFranco about it and he seemed to indicate that there were some implementations out that that couldn't handle a value of In order to handle multiple codecs, switching based on the content-type header I'd speculate that the best way to do that would be:
Please note though that I am not a maintainer of |
@LucioFranco after we chatted briefly on discord yesterday I did a bit more thinking about how improve accessibility of the code generation functionality in tonic-build. This is one potential approach. Its in a WIP state but I wanted to get your thoughts and see if this is something you'd be interested in as a contribution to tonic. If so I can spend some time actually making it usable.
Motivation
gRPC is a general purpose RPC framework that, while generally is paired with protobuf, is agnostic to the type of serialization format used for messages and in some cases it may be desired to use a different serialization format other than protobuf.
Solution
This PR takes a look at one possible way to enable using a custom, non-protobuf codec for serializing messages to the wire. This is done via:
CODEC_PATH
constant to a method which returns a&str
for better programability