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