Struct bincode::config::Config

source ยท
pub struct Config { /* private fields */ }
๐Ÿ‘ŽDeprecated since 1.3.0: please use the DefaultOptions/Options system instead
Expand 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.

Implementationsยง

sourceยง

impl Config

source

pub fn no_limit(&mut self) -> &mut Self

Sets the byte limit to be unlimited. This is the default.

source

pub fn limit(&mut self, limit: u64) -> &mut Self

Sets the byte limit to limit.

source

pub fn little_endian(&mut self) -> &mut Self

Sets the endianness to little-endian This is the default.

source

pub fn big_endian(&mut self) -> &mut Self

Sets the endianness to big-endian

source

pub fn native_endian(&mut self) -> &mut Self

Sets the endianness to the the machine-native endianness

source

pub fn serialize<T: ?Sized + Serialize>(&self, t: &T) -> Result<Vec<u8>>

Serializes a serializable object into a Vec of bytes using this configuration

source

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

source

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

source

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

source

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.

source

pub fn deserialize_from<R: Read, T: DeserializeOwned>( &self, reader: R, ) -> Result<T>

Deserializes an object directly from a Reader using this configuration

If this returns an Error, reader may be in an invalid state.

source

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 Reader with state seed using this configuration

If this returns an Error, reader may be in an invalid state.

source

pub fn deserialize_from_custom<'a, R: BincodeRead<'a>, T: DeserializeOwned>( &self, reader: R, ) -> Result<T>

Deserializes an object from a custom BincodeReader 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.

source

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 BincodeReader 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.

Trait Implementationsยง

sourceยง

impl Clone for Config

sourceยง

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 ยท sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
sourceยง

impl Debug for Config

sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
sourceยง

impl<T> CloneToUninit for T
where T: Clone,

sourceยง

default unsafe fn clone_to_uninit(&self, dst: *mut T)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
sourceยง

impl<T> From<T> for T

sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

sourceยง

impl<T> ToOwned for T
where T: Clone,

ยง

type Owned = T

The resulting type after obtaining ownership.
sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

ยง

type Error = Infallible

The type returned in the event of a conversion error.
sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

ยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.