gRPC service code generation for `tonic`
Opened this issue · 1 comments
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?
- implement
Codec
here liketonic::codec::prost::ProstCodec
- implement builder for server and client options like
tonic-build
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?
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