Browse Source

Implement tokio_codec::Encoder for all message types.

wip
Titouan Rigoudy 7 years ago
parent
commit
94a5ba0229
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      src/proto/codec.rs

+ 12
- 4
src/proto/codec.rs View File

@ -1,19 +1,23 @@
use std::io;
use std::marker;
use tokio_codec;
use bytes::BytesMut;
use super::base_codec::{ProtoEncode, ProtoEncoder};
use super::server::ServerRequest;
use super::server::{ServerRequest,ServerResponse};
use super::peer::Message;
/*===================================*
* TOKIO CODEC TRAIT IMPLEMENTATIONS *
*===================================*/
struct ServerRequestEncoder;
struct Encoder<T> {
data: marker::PhantomData<T>
}
impl tokio_codec::Encoder for ServerRequestEncoder {
type Item = ServerRequest;
impl<T: ProtoEncode> tokio_codec::Encoder for Encoder<T> {
type Item = T;
type Error = io::Error;
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
@ -22,3 +26,7 @@ impl tokio_codec::Encoder for ServerRequestEncoder {
Ok(())
}
}
pub type ServerRequestEncoder = Encoder<ServerRequest>;
pub type ServerResponseEncoder = Encoder<ServerResponse>;
pub type PeerMessageEncoder = Encoder<Message>;

Loading…
Cancel
Save