set up stub grpc client

This commit is contained in:
Ilion Beyst 2022-06-01 20:19:13 +02:00
parent af5cd69f7b
commit 0f80b19614
4 changed files with 45 additions and 1 deletions

View file

@ -3,6 +3,6 @@
members = [ members = [
"planetwars-rules", "planetwars-rules",
"planetwars-matchrunner", "planetwars-matchrunner",
"planetwars-cli",
"planetwars-server", "planetwars-server",
"planetwars-client",
] ]

View file

@ -0,0 +1,14 @@
[package]
name = "planetwars-client"
version = "0.0.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.15", features = ["full"] }
prost = "0.10"
tonic = "0.7.2"
[build-dependencies]
tonic-build = "0.7.2"

View file

@ -0,0 +1,9 @@
extern crate tonic_build;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.build_server(false)
.build_client(true)
.compile(&["../proto/bot_api.proto"], &["../proto"])?;
Ok(())
}

View file

@ -0,0 +1,21 @@
pub mod pb {
tonic::include_proto!("grpc.planetwars.bot_api");
}
use pb::test_service_client::TestServiceClient;
use pb::{Hello, HelloResponse};
use tonic::Response;
#[tokio::main]
async fn main() {
let mut client = TestServiceClient::connect("http://localhost:50051")
.await
.unwrap();
let response: Response<HelloResponse> = client
.greet(Hello {
hello_message: "robbe".to_string(),
})
.await
.unwrap();
println!("{}", response.get_ref().response);
}