Expand description
bincode
uses a Builder-pattern to configure the Serializers and Deserializers in this
crate. This means that if you need to customize the behavior of bincode
, you should create an
instance of the DefaultOptions
struct:
use bincode::Options;
let my_options = bincode::DefaultOptions::new();
Options Struct vs bincode functions
Due to historical reasons, the default options used by the serialize()
and deserialize()
family of functions are different than the default options created by the DefaultOptions
struct:
Byte limit | Endianness | Int Encoding | Trailing Behavior | |
---|---|---|---|---|
struct | Unlimited | Little | Varint | Reject |
function | Unlimited | Little | Fixint | Allow |
This means that if you want to use the Serialize
/ Deserialize
structs with the same
settings as the functions, you should adjust the DefaultOptions
struct like so:
use bincode::Options;
let my_options = bincode::DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes();
Structs
A TrailingBytes config that will allow trailing bytes in slices after deserialization.
Big-endian byte ordering.
A SizeLimit that restricts serialized or deserialized messages from
exceeding a certain byte length.
ConfigDeprecated
A configuration builder whose options Bincode will use
while serializing and deserializing.
The default options for bincode serialization/deserialization.
Fixed-size integer encoding.
A SizeLimit without a limit!
Use this if you don’t care about the size of encoded or decoded messages.
Little-endian byte ordering.
The native byte ordering of the current system.
A TrailingBytes config that will cause bincode to produce an error if bytes are left over in the slice when deserialization is complete.
Variable-size integer encoding (excepting [ui]8).
A configuration struct with a user-specified endian order
A configuration struct with a user-specified length encoding
A configuration struct with a user-specified byte limit
A configuration struct with a user-specified trailing bytes behavior.
Traits
A configuration builder trait whose options Bincode will use
while serializing and deserializing.