use elbus::ipc::{Client, Config};
use elbus::rpc::{DummyHandlers, Rpc, RpcClient};
use elbus::{empty_payload, QoS};
use serde::Deserialize;
use std::collections::HashMap;
#[derive(Deserialize)]
struct Amount {
value: u64,
}
#[tokio::main]
async fn main() {
let name = "test.client.123";
let target = "test.client.rpc";
let config = Config::new("/tmp/elbus.sock", name);
let client = Client::connect(&config).await.unwrap();
let rpc = RpcClient::new(client, DummyHandlers {});
rpc.call0(target, "test", empty_payload!(), QoS::Processed)
.await
.unwrap();
let mut payload: HashMap<&str, u32> = HashMap::new();
payload.insert("value", 10);
rpc.call(
target,
"add",
rmp_serde::to_vec_named(&payload).unwrap().into(),
QoS::Processed,
)
.await
.unwrap();
let result = rpc
.call(target, "get", empty_payload!(), QoS::Processed)
.await
.unwrap();
let amount: Amount = rmp_serde::from_slice(result.payload()).unwrap();
println!("{}", amount.value);
}