Crate bincode [] [src]

bincode is a crate for encoding and decoding using a tiny binary serialization strategy.

There are simple functions for encoding to Vec<u8> and decoding from &[u8], but the meat of the library is the encode_into and decode_from functions which respectively allow encoding into a std::io::Writer and decoding from a std::io::Buffer.

Modules

There are two ways to encode and decode structs using bincode, either using rustc_serialize or the serde crate. rustc_serialize and serde are crates and and also the names of their corresponding modules inside of bincode. Both modules have exactly equivalant functions, and and the only difference is whether or not the library user wants to use rustc_serialize or serde.

Using Basic Functions

#![allow(unstable)]
extern crate bincode;
use bincode::rustc_serialize::{encode, decode};
fn main() {
    // The object that we will serialize.
    let target = Some("hello world".to_string());
    // The maximum size of the encoded message.
    let limit = bincode::SizeLimit::Bounded(20);

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

Modules

rustc_serialize

A collection of serialization and deserialization functions that use the rustc_serialize crate for the encodable and decodable implementation.

serde

A collection of serialization and deserialization functions that use the serde crate for the serialazble and deserializable implementation.

Structs

RefBox

A struct for encoding nested reference types.

SliceBox

Like a RefBox, but encodes from a [T] and encodes to a Vec<T>.

StrBox

Like a RefBox, but encoding from a str and decoedes to a String.

Enums

SizeLimit

A limit on the amount of bytes that can be read or written.