Introduce ClientCodec, ServerCodec type aliases
This commit is contained in:
parent
ef658be8e4
commit
13c30843a3
|
@ -6,7 +6,7 @@ use futures::SinkExt;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut frames = Framed::new(TcpStream::connect("127.0.0.1:8001").await?,
|
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?;
|
frames.send(packets::C2S::Connect(Value::from("producer-consumer-example").wrap())).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,9 @@ pub struct Codec<InT, OutT> {
|
||||||
ph_out: PhantomData<OutT>,
|
ph_out: PhantomData<OutT>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type ServerCodec = Codec<C2S, S2C>;
|
||||||
|
pub type ClientCodec = Codec<S2C, C2S>;
|
||||||
|
|
||||||
impl<InT, OutT> Codec<InT, OutT> {
|
impl<InT, OutT> Codec<InT, OutT> {
|
||||||
pub fn new(codec: value::Codec<V, Syndicate>) -> Self {
|
pub fn new(codec: value::Codec<V, Syndicate>) -> Self {
|
||||||
Codec { codec, ph_in: PhantomData, ph_out: PhantomData }
|
Codec { codec, ph_in: PhantomData, ph_out: PhantomData }
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct Peer {
|
||||||
id: ConnId,
|
id: ConnId,
|
||||||
tx: UnboundedSender<packets::S2C>,
|
tx: UnboundedSender<packets::S2C>,
|
||||||
rx: UnboundedReceiver<packets::S2C>,
|
rx: UnboundedReceiver<packets::S2C>,
|
||||||
frames: Framed<TcpStream, packets::Codec<packets::C2S, packets::S2C>>,
|
frames: Framed<TcpStream, packets::ServerCodec>,
|
||||||
space: Option<dataspace::DataspaceRef>,
|
space: Option<dataspace::DataspaceRef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue