pub struct CompactSizeDecoder { /* private fields */ }Expand description
Decodes a compact size encoded integer as a length prefix.
The decoded value is returned as a usize and is bounded by a configurable limit (default:
4,000,000). This limit is a denial-of-service protection: a malicious peer can send a compact
size value up to 2^64-1, and without a limit check the caller might attempt to allocate an
enormous buffer based on that value. CompactSizeDecoder prevents this by rejecting values
that exceed the limit before returning them to the caller.
If you are decoding an arbitrary u64 integer that is genuinely not a length prefix, use
CompactSizeU64Decoder instead.
For more information about decoders see the documentation of the Decoder trait.
Implementations§
Source§impl CompactSizeDecoder
impl CompactSizeDecoder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs a new compact size decoder with the default length limit.
The decoded value must not exceed 4,000,000 and must fit in a usize, otherwise
end will return an error. This default limit reflects the maximum sensible
vector length under the 4 MB block weight limit.
Sourcepub const fn new_with_limit(limit: usize) -> Self
pub const fn new_with_limit(limit: usize) -> Self
Constructs a new compact size decoder with a custom length limit.
The decoded value must not exceed limit, otherwise end will return an
error. Use this when you know the field you are decoding has a tighter bound than the
default limit of 4,000,000.
Trait Implementations§
Source§impl Clone for CompactSizeDecoder
impl Clone for CompactSizeDecoder
Source§fn clone(&self) -> CompactSizeDecoder
fn clone(&self) -> CompactSizeDecoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more