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
Until "default type parameters" lands, we have an extra module called endian_choice
that duplicates all of the core bincode functionality but with the option to choose
which endianness the integers are encoded using.
The default endianness is little.
Using Basic Functions
extern crate bincode; use bincode::{serialize, deserialize, Bounded}; fn main() { // The object that we will serialize. let target = Some("hello world".to_string()); // The maximum size of the encoded message. let limit = Bounded(20); let encoded: Vec<u8> = serialize(&target, limit).unwrap(); let decoded: Option<String> = deserialize(&encoded[..]).unwrap(); assert_eq!(target, decoded); }
Modules
endian_choice |
All of the core bincode functions and types with the ability to choose endianness. |
Structs
Bounded |
A SizeLimit that restricts serialized or deserialized messages from exceeding a certain byte length. |
Infinite |
A SizeLimit without a limit! Use this if you don't care about the size of encoded or decoded messages. |
Enums
ErrorKind |
The kind of error that can be produced during a serialization or deserialization. |
Traits
SizeLimit |
A limit on the amount of bytes that can be read or written. |
Functions
deserialize |
Deserializes a slice of bytes into an object. |
deserialize_from |
Deserializes an object directly from a |
serialize |
Serializes a serializable object into a |
serialize_into |
Serializes an object directly into a |
serialized_size |
Returns the size that an object would be if serialized using bincode. |
serialized_size_bounded |
Given a maximum size limit, check how large an object would be if it were to be serialized. |
Type Definitions
Deserializer |
A Deserializer that uses LittleEndian byteorder |
Error |
An error that can be produced during (de)serializing. |
Result |
The result of a serialization or deserialization operation. |
Serializer |
A Serializer that uses LittleEndian byteorder |