#binary #encode #decode #serialize #deserialize

bincode

A binary serialization / deserialization strategy that uses Serde for transforming structs into bytes and vice versa!

50 releases (2 stable)

1.0.1 Jun 18, 2018
1.0.0 Feb 15, 2018
1.0.0-alpha7 Apr 8, 2017
1.0.0-alpha6 Mar 18, 2017
0.0.2 Nov 24, 2014

#3 in Network programming

Download history 6602/week @ 2018-07-04 7513/week @ 2018-07-11 8377/week @ 2018-07-18 7129/week @ 2018-07-25 7528/week @ 2018-08-01 7013/week @ 2018-08-08 8121/week @ 2018-08-15 6968/week @ 2018-08-22 8729/week @ 2018-08-29 9706/week @ 2018-09-05 8964/week @ 2018-09-12 9958/week @ 2018-09-19 9193/week @ 2018-09-26

25,756 downloads per month
Used in 290 crates (201 directly)

MIT license

64KB
2K SLoC


lib.rs:

Bincode is a crate for encoding and decoding using a tiny binary serialization strategy. Using it, you can easily go from having an object in memory, quickly serialize it to bytes, and then deserialize it back just as fast!

Using Basic Functions

extern crate bincode;
use bincode::{serialize, deserialize};
fn main() {
    // The object that we will serialize.
    let target: Option<String>  = Some("hello world".to_string());

    let encoded: Vec<u8>        = serialize(&target).unwrap();
    let decoded: Option<String> = deserialize(&encoded[..]).unwrap();
    assert_eq!(target, decoded);
}

128bit numbers

Support for i128 and u128 on Rust toolchains after 1.26.0 is enabled through the i128 feature. Add the following to your Cargo.toml:

[dependencies.bincode]
features = ["i128"]

Dependencies

~443KB