mirror of
https://github.com/OMGeeky/tarpc.git
synced 2025-12-26 17:02:32 +01:00
Unify serde transports.
This PR obsoletes the JSON and Bincode transports and instead introduces a unified transport that is generic over any tokio-serde serialization format as well as AsyncRead + AsyncWrite medium. This comes with a slight hit for usability (having to manually specify the underlying transport and codec), but it can be alleviated by making custom freestanding connect and listen fns.
This commit is contained in:
committed by
Tim Kuehn
parent
f945392b5a
commit
bbbd43e282
@@ -18,6 +18,7 @@ futures = "0.3"
|
||||
serde = { version = "1.0" }
|
||||
tarpc = { version = "0.18", path = "../tarpc", features = ["full"] }
|
||||
tokio = "0.2"
|
||||
tokio-serde = { version = "0.6", features = ["json"] }
|
||||
env_logger = "0.6"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
use clap::{App, Arg};
|
||||
use std::{io, net::SocketAddr};
|
||||
use tarpc::{client, context};
|
||||
use tokio_serde::formats::Json;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
@@ -40,7 +41,7 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
let name = flags.value_of("name").unwrap().into();
|
||||
|
||||
let transport = tarpc::json_transport::connect(server_addr).await?;
|
||||
let transport = tarpc::serde_transport::tcp::connect(server_addr, Json::default()).await?;
|
||||
|
||||
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
|
||||
// config and any Transport as input.
|
||||
|
||||
@@ -18,6 +18,7 @@ use tarpc::{
|
||||
context,
|
||||
server::{self, Channel, Handler},
|
||||
};
|
||||
use tokio_serde::formats::Json;
|
||||
|
||||
// This is the type that implements the generated World trait. It is the business logic
|
||||
// and is used to start the server.
|
||||
@@ -66,7 +67,7 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
||||
// to start up a serde-powered json serialization strategy over TCP.
|
||||
tarpc::json_transport::listen(&server_addr)
|
||||
tarpc::serde_transport::tcp::listen(&server_addr, Json::default)
|
||||
.await?
|
||||
// Ignore accept errors.
|
||||
.filter_map(|r| future::ready(r.ok()))
|
||||
|
||||
Reference in New Issue
Block a user