Browse Source

Add src::proto::codec for Tokio integration.

wip
Titouan Rigoudy 7 years ago
parent
commit
c8a4e8fe74
5 changed files with 29 additions and 0 deletions
  1. +1
    -0
      Cargo.lock
  2. +1
    -0
      Cargo.toml
  3. +1
    -0
      src/main.rs
  4. +24
    -0
      src/proto/codec.rs
  5. +2
    -0
      src/proto/mod.rs

+ 1
- 0
Cargo.lock View File

@ -534,6 +534,7 @@ dependencies = [
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"ws 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",


+ 1
- 0
Cargo.toml View File

@ -16,4 +16,5 @@ rustc-serialize = "^0.3.17"
slab = "^0.2"
tokio-core = "^0.1"
tokio-io = "^0.1"
tokio-codec = "^0.1"
ws = "^0.4"

+ 1
- 0
src/main.rs View File

@ -17,6 +17,7 @@ extern crate env_logger;
extern crate mio;
extern crate rustc_serialize;
extern crate slab;
extern crate tokio_codec;
extern crate tokio_core;
extern crate tokio_io;
extern crate ws;


+ 24
- 0
src/proto/codec.rs View File

@ -0,0 +1,24 @@
use std::io;
use tokio_codec;
use bytes::BytesMut;
use super::base_codec::{ProtoEncode, ProtoEncoder};
use super::server::ServerRequest;
/*===================================*
* TOKIO CODEC TRAIT IMPLEMENTATIONS *
*===================================*/
struct ServerRequestEncoder;
impl tokio_codec::Encoder for ServerRequestEncoder {
type Item = ServerRequest;
type Error = io::Error;
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
let mut encoder = ProtoEncoder::new(dst);
item.encode(&mut encoder)?;
Ok(())
}
}

+ 2
- 0
src/proto/mod.rs View File

@ -1,4 +1,5 @@
mod base_codec;
mod codec;
mod constants;
mod handler;
mod packet;
@ -9,6 +10,7 @@ mod transport;
mod user;
pub use self::base_codec::{Decode, ProtoEncode, ProtoEncoder};
pub use self::codec::*;
pub use self::handler::*;
pub use self::packet::*;
pub use self::server::{ServerRequest, ServerResponse};


Loading…
Cancel
Save