Skip to main content

VarInt

Struct VarInt 

Source
pub struct VarInt(pub u64);
Expand description

Variable-integer encoding.

Integer can be encoded depending on the represented value to save space. Variable length integers always precede an array/vector of a type of data that may vary in length. Longer numbers are encoded in little endian.

ValueStorage lengthFormat
<= 0xfc1u8
<= 0xffff30xfd followed by value as u16
<= 0xffffffff50xfe followed by value as u32
-90xff followed by value as u64

See also Bitcoin variable length integers.

Tuple Fields§

§0: u64

Implementations§

Source§

impl VarInt

Source

pub fn length(&self) -> usize

Gets the length of this VarInt when encoded. Returns:

  • 1 for 0..0xFC
  • 3 for 0xFD..(2^16-1)
  • 5 for 0x10000..(2^32-1)
  • 9 otherwise

Trait Implementations§

Source§

impl Debug for VarInt

Source§

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

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

impl Decodable for VarInt

Source§

fn decode<D: Read>(d: &mut D) -> Result<Self, Error>

Source§

impl Encodable for VarInt

Source§

fn encode<S: Write>(&self, s: &mut S) -> Result<usize, Error>

Encode an object with a well-defined format. Should only ever error if the underlying Write errors. Returns the number of bytes written on success.
Source§

impl Eq for VarInt

Source§

impl PartialEq for VarInt

Source§

fn eq(&self, other: &VarInt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for VarInt

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