1 //! A HelloWorld example that uses a custom codec instead of the default Prost codec. 2 //! 3 //! Generated code is the output of codegen as defined in the `examples/build.rs` file. 4 //! The generation is the one with .codec_path("crate::common::SmallBufferCodec") 5 //! The generated code assumes that a module `crate::common` exists which defines 6 //! `SmallBufferCodec`, and `SmallBufferCodec` must have a Default implementation. 7 8 pub mod common; 9 10 pub mod small_buf { 11 include!(concat!(env!("OUT_DIR"), "/smallbuf/helloworld.rs")); 12 } 13 use small_buf::greeter_client::GreeterClient; 14 15 use crate::small_buf::HelloRequest; 16 17 #[tokio::main] main() -> Result<(), Box<dyn std::error::Error>>18async fn main() -> Result<(), Box<dyn std::error::Error>> { 19 let mut client = GreeterClient::connect("http://[::1]:50051").await?; 20 21 let request = tonic::Request::new(HelloRequest { 22 name: "Tonic".into(), 23 }); 24 25 let response = client.say_hello(request).await?; 26 27 println!("RESPONSE={:?}", response); 28 29 Ok(()) 30 } 31