Enum bincode::SizeLimit
[−]
[src]
pub enum SizeLimit { Infinite, Bounded(u64), }
A limit on the amount of bytes that can be read or written.
Size limits are an incredibly important part of both encoding and decoding.
In order to prevent DOS attacks on a decoder, it is important to limit the amount of bytes that a single encoded message can be; otherwise, if you are decoding bytes right off of a TCP stream for example, it would be possible for an attacker to flood your server with a 3TB vec, causing the decoder to run out of memory and crash your application! Because of this, you can provide a maximum-number-of-bytes that can be read during decoding, and the decoder will explicitly fail if it has to read any more than that.
On the other side, you want to make sure that you aren't encoding a message that is larger than your decoder expects. By supplying a size limit to an encoding function, the encoder will verify that the structure can be encoded within that limit. This verification occurs before any bytes are written to the Writer, so recovering from an the error is easy.
Variants
Infinite
Bounded(u64)
Trait Implementations
impl Clone for SizeLimit
[src]
fn clone(&self) -> SizeLimit
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for SizeLimit
[src]
impl Debug for SizeLimit
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Hash for SizeLimit
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Eq for SizeLimit
[src]
impl PartialEq for SizeLimit
[src]
fn eq(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests for !=
.
impl Ord for SizeLimit
[src]
fn cmp(&self, __arg_0: &SizeLimit) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for SizeLimit
[src]
fn partial_cmp(&self, __arg_0: &SizeLimit) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &SizeLimit) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more