1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! Utilities for working with the traits from the
//! [async-codec](https://crates.io/crates/async-codec) crate.
#![deny(missing_docs)]

extern crate async_codec;
extern crate futures_core;
extern crate futures_io;

#[cfg(test)]
extern crate async_ringbuffer;
#[cfg(test)]
extern crate atm_io_utils;
#[macro_use]
#[cfg(test)]
extern crate quickcheck;

mod decoder;
pub use decoder::Decoder;
mod encoder;
pub use encoder::Encoder;

/// Decode a value from an `AsyncRead`, using an `AsyncDecode`.
pub fn decode<R, D>(reader: R, dec: D) -> decoder::Decoder<R, D> {
    decoder::Decoder::new(reader, dec)
}

/// Encode a value into an `AsyncWrite`, using an `AsyncEncode`.
pub fn encode<W, C>(writer: W, co: C) -> encoder::Encoder<W, C> {
    encoder::Encoder::new(writer, co)
}

// TODO add Chain for chaining two encoders sequentially
// TODO add remaining_bytes to encoder future when wrapping an AsyncEncodeLen