Skip to main content

CompactSizeU64Decoder

Struct CompactSizeU64Decoder 

Source
pub struct CompactSizeU64Decoder { /* private fields */ }
Expand description

Decodes a compact size encoded integer as a raw u64.

If you are decoding a length prefix, you probably want CompactSizeDecoder instead.

This decoder performs no limit check and no conversion to usize. It exists for the small number of Bitcoin protocol fields that are compact-size-encoded integers but are not length prefixes (e.g. service flags in the version message). For those fields the full u64 range is meaningful and there is no associated allocation whose size would be controlled by the decoded value.

§Denial-of-service warning

Do not use this decoder for length prefixes. If the decoded value is used to size an allocation, for example as the length of a Vec, a malicious peer can send a compact size value of up to 2^64-1 and cause an out-of-memory condition. CompactSizeDecoder prevents this by enforcing a configurable upper bound before returning the value.

For more information about decoders see the documentation of the Decoder trait.

Implementations§

Source§

impl CompactSizeU64Decoder

Source

pub const fn new() -> Self

Constructs a new CompactSizeU64Decoder.

See the struct-level documentation for guidance on when to use this decoder versus CompactSizeDecoder.

Trait Implementations§

Source§

impl Clone for CompactSizeU64Decoder

Source§

fn clone(&self) -> CompactSizeU64Decoder

Returns a duplicate 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 CompactSizeU64Decoder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Decoder for CompactSizeU64Decoder

Source§

type Output = u64

The type that this decoder produces when decoding is complete.
Source§

type Error = CompactSizeDecoderError

The error type that this decoder can produce.
Source§

fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error>

Pushes bytes into the decoder, consuming as much as possible. Read more
Source§

fn end(self) -> Result<Self::Output, Self::Error>

Completes the decoding process and return the final result. Read more
Source§

fn read_limit(&self) -> usize

Returns the maximum number of bytes this decoder can consume without over-reading. Read more
Source§

impl Default for CompactSizeU64Decoder

Source§

fn default() -> Self

Returns the “default value” for a type. 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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.