diff --git a/Cargo.toml b/Cargo.toml index f0e42fa..ec93bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ [package] -name = "binary_encode" +name = "bincode" version = "0.0.1" authors = ["Ty Overby "] diff --git a/README.md b/README.md index 4dc59df..cd013d0 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # Binary Encoder / Decoder -[![Build Status](https://travis-ci.org/TyOverby/binary-encode.svg)](https://travis-ci.org/TyOverby/binary-encode) +[![Build Status](https://travis-ci.org/TyOverby/bincode.svg)](https://travis-ci.org/TyOverby/bincode) A compact encoder / decoder pair that uses an binary zero-fluff encoding scheme. The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program. -In addition to exposing two simple funcitons that encode to `Vec` and decode -from `Vec`, binary-encode exposes a Reader/Writer API that makes it work +In addition to exposing two simple funcitons that encode to Vec and decode +from Vec, binary-encode exposes a Reader/Writer API that makes it work perfectly with other stream-based apis such as rust files, network streams, and the [flate2-rs](https://github.com/alexcrichton/flate2-rs) compression library. -[Api Documentation](http://tyoverby.github.io/binary-encode/binary_encode/) +[Api Documentation](http://tyoverby.github.io/bincode/bincode/) ## Example ```rust -extern crate binary_encode; +extern crate bincode; extern crate serialize; #[deriving(Encodable, Decodable, PartialEq)] @@ -36,8 +36,8 @@ fn main() { entities: vec![Entity {x: 0.0, y: 4.0}, Entity {x: 10.0, y: 20.5}] }; - let encoded: Vec = binary_encode::encode(&world).unwrap(); - let decoded: World = binary_encode::decode(encoded).unwrap(); + let encoded: Vec = bincode::encode(&world).unwrap(); + let decoded: World = bincode::decode(encoded).unwrap(); assert!(world == decoded); } diff --git a/examples/basic.rs b/examples/basic.rs index c0d0875..f9d9f0b 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,4 +1,4 @@ -extern crate binary_encode; +extern crate bincode; extern crate serialize; #[deriving(Encodable, Decodable, PartialEq)] @@ -17,8 +17,8 @@ fn main() { entities: vec![Entity {x: 0.0, y: 4.0}, Entity {x: 10.0, y: 20.5}] }; - let encoded: Vec = binary_encode::encode(&world).unwrap(); - let decoded: World = binary_encode::decode(encoded).unwrap(); + let encoded: Vec = bincode::encode(&world).unwrap(); + let decoded: World = bincode::decode(encoded).unwrap(); assert!(world == decoded); } diff --git a/examples/file.rs b/examples/file.rs new file mode 100644 index 0000000..7028d21 --- /dev/null +++ b/examples/file.rs @@ -0,0 +1,21 @@ +extern crate bincode; +extern crate serialize; + +use std::collections::HashMap; +use std::io::{Truncate, ReadWrite, File, BufferedReader}; + +fn main() { + let mut word_counts = HashMap::new(); + word_counts.insert("foo".to_string(), 3u); + word_counts.insert("fizzbuzz".to_string(), 8u); + + let file = File::open_mode(&Path::new("store.bin"), Truncate, ReadWrite); + let mut file = file.unwrap(); + bincode::encode_into(&word_counts, &mut file); + file.fsync().unwrap(); + + let out: HashMap = + bincode::decode_from(&mut BufferedReader::new(file)).unwrap(); + + assert!(out == word_counts); +} diff --git a/readme.dev.md b/readme.dev.md index 8d04a2a..799042a 100644 --- a/readme.dev.md +++ b/readme.dev.md @@ -1,12 +1,18 @@ # Binary Encoder / Decoder -[![Build Status](https://travis-ci.org/TyOverby/binary-encode.svg)](https://travis-ci.org/TyOverby/binary-encode) +[![Build Status](https://travis-ci.org/TyOverby/bincode.svg)](https://travis-ci.org/TyOverby/bincode) A compact encoder / decoder pair that uses an binary zero-fluff encoding scheme. The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program. -[Api Documentation](http://tyoverby.github.io/binary-encode/binary_encode/) +In addition to exposing two simple funcitons that encode to Vec and decode +from Vec, binary-encode exposes a Reader/Writer API that makes it work +perfectly with other stream-based apis such as rust files, network streams, +and the [flate2-rs](https://github.com/alexcrichton/flate2-rs) compression +library. + +[Api Documentation](http://tyoverby.github.io/bincode/bincode/) ## Example diff --git a/src/lib.rs b/src/lib.rs index d48aaa1..04bcce9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![crate_name = "binary_encode"] +#![crate_name = "bincode"] #![crate_type = "rlib"] #![crate_type = "dylib"]