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
.
Using Basic Functions
#![allow(unstable)] extern crate bincode; 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> = bincode::encode(&target, limit).unwrap(); let (decoded, len): (Option<String>, u64) = bincode::decode(&encoded[..]).unwrap(); assert_eq!(target, decoded); }
Structs
DecoderReader |
A Decoder that reads bytes from a buffer. |
EncoderWriter |
An Encoder that encodes values directly into a Writer. |
RefBox |
A struct for encoding nested reference types. |
SliceBox |
Like a RefBox, but encodes from a |
StrBox |
Like a RefBox, but encoding from a |
Enums
DecodingError |
An error that can be produced during decoding. |
EncodingError |
An error that can be produced during encoding. |
SizeLimit |
A limit on the amount of bytes that can be read or written. |
Functions
decode |
Decodes a slice of bytes into an object. |
decode_from |
Decodes an object directly from a |
encode |
Encodes an encodable object into a |
encode_into |
Encodes an object directly into a |
encoded_size |
Returns the size that an object would be if encoded using bincode. |
encoded_size_bounded |
Given a maximum size limit, check how large an object would be if it were to be encoded. |
Type Definitions
DecodingResult | |
EncodingResult |