feat(build): Better support for custom codecs (#999)
BREAKING CHANGE: `CODEC_PATH` moved from const to fn
This commit is contained in:
+27
-2
@@ -1,5 +1,4 @@
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
tonic_build::configure()
|
||||
@@ -30,4 +29,30 @@ fn main() {
|
||||
&["proto/googleapis"],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
build_json_codec_service();
|
||||
}
|
||||
|
||||
// Manually define the json.helloworld.Greeter service which used a custom JsonCodec to use json
|
||||
// serialization instead of protobuf for sending messages on the wire.
|
||||
// This will result in generated client and server code which relies on its request, response and
|
||||
// codec types being defined in a module `crate::common`.
|
||||
//
|
||||
// See the client/server examples defined in `src/json-codec` for more information.
|
||||
fn build_json_codec_service() {
|
||||
let greeter_service = tonic_build::manual::Service::builder()
|
||||
.name("Greeter")
|
||||
.package("json.helloworld")
|
||||
.method(
|
||||
tonic_build::manual::Method::builder()
|
||||
.name("say_hello")
|
||||
.route_name("SayHello")
|
||||
.input_type("crate::common::HelloRequest")
|
||||
.output_type("crate::common::HelloResponse")
|
||||
.codec_path("crate::common::JsonCodec")
|
||||
.build(),
|
||||
)
|
||||
.build();
|
||||
|
||||
tonic_build::manual::Builder::new().compile(&[greeter_service]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user