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

gRPC service code generation for tonic #687

Open
kriswuollett opened this issue Oct 26, 2023 · 2 comments
Open

gRPC service code generation for tonic #687

kriswuollett opened this issue Oct 26, 2023 · 2 comments

Comments

@kriswuollett
Copy link

kriswuollett commented Oct 26, 2023

I'd like to make use of rust-protobuf instead of prost when building servers based on tonic. Primary use cases are reading options on messages and service descriptors, and being able to use the semi-official proto3 JSON standard for setting up test cases and config files.

I assume something like this would be widely used since rust-protobuf has more proto features that may be needed without relying on additional third party libraries like prost-reflect (and would that even work with tonic-build?). And maybe if Rust consolidated on a single maintained proto library, there may be more users willing to contribute. The big unknown factor however is if Google ever decides to release their own instead of anointing an existing proto library -- then why take time to contribute at all if everything else gets dropped in the near future? Thankfully rust-protobuf and grpc-rs are mentioned by Google on an Android page, but no grpc-rs for me currently since I'd like to work within tower.

So tonic seems implemented fairly flexibly since it based on tower (see the Service re-export) and that tonic::Codec exists as a translator:

pub trait Codec {
    type Encode: Send + 'static;
    type Decode: Send + 'static;
    type Encoder: Encoder<Item = Self::Encode, Error = Status> + Send + 'static;
    type Decoder: Decoder<Item = Self::Decode, Error = Status> + Send + 'static;
    fn encoder(&mut self) -> Self::Encoder;
    fn decoder(&mut self) -> Self::Decoder;
}

That is used by the tower-based gRPC service to decode a message in the stream.

Isn't using using rust-protobuf with tonic (just 😅) the following steps?

I'm assuming it is straightforward due to the Codec trait, so kind of surprised I couldn't find an implementation in an internet search for rust-protobuf tonic codec. No one has looked into trying this before?

@dfrankland
Copy link

I have a similar use-case. I was able to look at some of the code you started on and created a fully working example:
https://github.com/dfrankland/tonic-no-codegen-example

@0xcaff
Copy link

0xcaff commented Jul 11, 2024

I have a similar use case too. I got it working with tonic (codgen and all) here. hyperium/tonic#1789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants