Crates.io | tokio-u8-codec |
lib.rs | tokio-u8-codec |
version | 0.1.0 |
source | src |
created_at | 2017-10-22 12:41:19.273015 |
updated_at | 2017-10-22 12:41:19.273015 |
description | A Tokio codec that just reads and writes u8s |
homepage | |
repository | https://github.com/paulkernfeld/tokio-u8-codec |
max_upload_size | |
id | 36563 |
size | 4,041 |
A Tokio codec that just reads and writes u8s.
This is probably not a very performant way to process streams of bytes because it only looks at one byte at a time.
extern crate bytes;
extern crate tokio_io;
extern crate tokio_u8_codec;
use tokio_io::codec::{Decoder, Encoder};
use tokio_u8_codec::U8Codec;
use bytes::BytesMut;
fn main() {
let mut buf: BytesMut = Default::default();
let mut codec: U8Codec = Default::default();
codec.encode(1, &mut buf).unwrap();
codec.encode(2, &mut buf).unwrap();
assert_eq!(codec.decode(&mut buf).unwrap(), Some(1));
assert_eq!(codec.decode(&mut buf).unwrap(), Some(2));
assert_eq!(codec.decode(&mut buf).unwrap(), None);
}
License: MIT/Apache-2.0