pub struct Config {
limit: LimitOption,
endian: EndianOption,
}
DefaultOptions
/Options
system insteadExpand description
A configuration builder whose options Bincode will use while serializing and deserializing.
ยงOptions
Endianness: The endianness with which multi-byte integers will be read/written. default: little endian Limit: The maximum number of bytes that will be read/written in a bincode serialize/deserialize. default: unlimited
ยงByte Limit Details
The purpose of byte-limiting is to prevent Denial-Of-Service attacks whereby malicious attackers get bincode deserialization to crash your process by allocating too much memory or keeping a connection open for too long.
When a byte limit is set, bincode will return Err
on any deserialization that goes over the limit, or any
serialization that goes over the limit.
Fieldsยง
ยงlimit: LimitOption
DefaultOptions
/Options
system insteadendian: EndianOption
DefaultOptions
/Options
system insteadImplementationsยง
sourceยงimpl Config
impl Config
pub(crate) fn new() -> Config
sourcepub fn no_limit(&mut self) -> &mut Self
pub fn no_limit(&mut self) -> &mut Self
Sets the byte limit to be unlimited. This is the default.
sourcepub fn little_endian(&mut self) -> &mut Self
pub fn little_endian(&mut self) -> &mut Self
Sets the endianness to little-endian This is the default.
sourcepub fn big_endian(&mut self) -> &mut Self
pub fn big_endian(&mut self) -> &mut Self
Sets the endianness to big-endian
sourcepub fn native_endian(&mut self) -> &mut Self
pub fn native_endian(&mut self) -> &mut Self
Sets the endianness to the the machine-native endianness
sourcepub fn serialize<T: ?Sized + Serialize>(&self, t: &T) -> Result<Vec<u8>>
pub fn serialize<T: ?Sized + Serialize>(&self, t: &T) -> Result<Vec<u8>>
Serializes a serializable object into a Vec
of bytes using this configuration
sourcepub fn serialized_size<T: ?Sized + Serialize>(&self, t: &T) -> Result<u64>
pub fn serialized_size<T: ?Sized + Serialize>(&self, t: &T) -> Result<u64>
Returns the size that an object would be if serialized using Bincode with this configuration
sourcepub fn serialize_into<W: Write, T: ?Sized + Serialize>(
&self,
w: W,
t: &T,
) -> Result<()>
pub fn serialize_into<W: Write, T: ?Sized + Serialize>( &self, w: W, t: &T, ) -> Result<()>
Serializes an object directly into a Writer
using this configuration
If the serialization would take more bytes than allowed by the size limit, an error
is returned and no bytes will be written into the Writer
sourcepub fn deserialize<'a, T: Deserialize<'a>>(&self, bytes: &'a [u8]) -> Result<T>
pub fn deserialize<'a, T: Deserialize<'a>>(&self, bytes: &'a [u8]) -> Result<T>
Deserializes a slice of bytes into an instance of T
using this configuration
sourcepub fn deserialize_seed<'a, T: DeserializeSeed<'a>>(
&self,
seed: T,
bytes: &'a [u8],
) -> Result<T::Value>
pub fn deserialize_seed<'a, T: DeserializeSeed<'a>>( &self, seed: T, bytes: &'a [u8], ) -> Result<T::Value>
Deserializes a slice of bytes with state seed
using this configuration.
sourcepub fn deserialize_from<R: Read, T: DeserializeOwned>(
&self,
reader: R,
) -> Result<T>
pub fn deserialize_from<R: Read, T: DeserializeOwned>( &self, reader: R, ) -> Result<T>
Deserializes an object directly from a Read
er using this configuration
If this returns an Error
, reader
may be in an invalid state.
sourcepub fn deserialize_from_seed<'a, R: Read, T: DeserializeSeed<'a>>(
&self,
seed: T,
reader: R,
) -> Result<T::Value>
pub fn deserialize_from_seed<'a, R: Read, T: DeserializeSeed<'a>>( &self, seed: T, reader: R, ) -> Result<T::Value>
Deserializes an object directly from a Read
er with state seed
using this configuration
If this returns an Error
, reader
may be in an invalid state.
sourcepub fn deserialize_from_custom<'a, R: BincodeRead<'a>, T: DeserializeOwned>(
&self,
reader: R,
) -> Result<T>
pub fn deserialize_from_custom<'a, R: BincodeRead<'a>, T: DeserializeOwned>( &self, reader: R, ) -> Result<T>
Deserializes an object from a custom BincodeRead
er using the default configuration.
It is highly recommended to use deserialize_from
unless you need to implement
BincodeRead
for performance reasons.
If this returns an Error
, reader
may be in an invalid state.
sourcepub fn deserialize_from_custom_seed<'a, R: BincodeRead<'a>, T: DeserializeSeed<'a>>(
&self,
seed: T,
reader: R,
) -> Result<T::Value>
pub fn deserialize_from_custom_seed<'a, R: BincodeRead<'a>, T: DeserializeSeed<'a>>( &self, seed: T, reader: R, ) -> Result<T::Value>
Deserializes an object from a custom BincodeRead
er with state seed
using the default
configuration. It is highly recommended to use deserialize_from
unless you need to
implement BincodeRead
for performance reasons.
If this returns an Error
, reader
may be in an invalid state.