Introduce ClientCodec, ServerCodec type aliases

This commit is contained in:
Tony Garnock-Jones 2020-05-11 22:10:34 +02:00
parent ef658be8e4
commit 13c30843a3
3 changed files with 5 additions and 2 deletions

View File

@ -6,7 +6,7 @@ use futures::SinkExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut frames = Framed::new(TcpStream::connect("127.0.0.1:8001").await?,
packets::Codec::<packets::S2C, packets::C2S>::standard());
packets::ClientCodec::standard());
frames.send(packets::C2S::Connect(Value::from("producer-consumer-example").wrap())).await?;
Ok(())
}

View File

@ -103,6 +103,9 @@ pub struct Codec<InT, OutT> {
ph_out: PhantomData<OutT>,
}
pub type ServerCodec = Codec<C2S, S2C>;
pub type ClientCodec = Codec<S2C, C2S>;
impl<InT, OutT> Codec<InT, OutT> {
pub fn new(codec: value::Codec<V, Syndicate>) -> Self {
Codec { codec, ph_in: PhantomData, ph_out: PhantomData }

View File

@ -20,7 +20,7 @@ pub struct Peer {
id: ConnId,
tx: UnboundedSender<packets::S2C>,
rx: UnboundedReceiver<packets::S2C>,
frames: Framed<TcpStream, packets::Codec<packets::C2S, packets::S2C>>,
frames: Framed<TcpStream, packets::ServerCodec>,
space: Option<dataspace::DataspaceRef>,
}