Skip to main content

Leb128Codec

Struct Leb128Codec 

Source
pub struct Leb128Codec<T, P = NonStrict> { /* private fields */ }
Expand description

Type-level unchecked LEB128 codec.

T selects the decoded integer type and P selects the decoding policy. Encoding is always canonical; P only affects decoding.

Implementations§

Source§

impl<P> Leb128Codec<u8, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u8, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u8, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<u16, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u16, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u16, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<u32, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u32, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u32, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<u64, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u64, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u64, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<u128, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u128, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u128, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<usize, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(usize, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: usize, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<i8, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i8, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i8, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<i16, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i16, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i16, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<i32, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i32, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i32, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<i64, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i64, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i64, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<i128, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i128, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i128, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Source§

impl<P> Leb128Codec<isize, P>
where P: DecodePolicy,

Source

pub const REQUIRED_MIN_BUFFER_LEN: usize

Minimum number of bytes required to encode or decode this type.

Source

pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(isize, usize), Leb128DecodeError>

Decodes a value from input starting at index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • index: Start index in input.
§Returns

Returns the decoded value and the number of consumed bytes.

§Errors

Returns Leb128DecodeError if the bytes are malformed or strict decoding rejects a non-canonical representation.

§Safety

The caller must guarantee that input.as_ptr().add(index) is valid to read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte appears before that limit.

Source

pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: isize, ) -> usize

Encodes value into output starting at index without bounds checks.

§Parameters
  • output: Destination byte buffer.
  • index: Start index in output.
  • value: Value to encode.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that output.as_mut_ptr().add(index) is valid to write Self::REQUIRED_MIN_BUFFER_LEN bytes.

Trait Implementations§

Source§

impl<T: Clone, P: Clone> Clone for Leb128Codec<T, P>

Source§

fn clone(&self) -> Leb128Codec<T, P>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, P: Debug> Debug for Leb128Codec<T, P>

Source§

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

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

impl<T: Default, P: Default> Default for Leb128Codec<T, P>

Source§

fn default() -> Leb128Codec<T, P>

Returns the “default value” for a type. Read more
Source§

impl<T: PartialEq, P: PartialEq> PartialEq for Leb128Codec<T, P>

Source§

fn eq(&self, other: &Leb128Codec<T, P>) -> 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<T: Copy, P: Copy> Copy for Leb128Codec<T, P>

Source§

impl<T: Eq, P: Eq> Eq for Leb128Codec<T, P>

Source§

impl<T, P> StructuralPartialEq for Leb128Codec<T, P>

Auto Trait Implementations§

§

impl<T, P> Freeze for Leb128Codec<T, P>

§

impl<T, P> RefUnwindSafe for Leb128Codec<T, P>

§

impl<T, P> Send for Leb128Codec<T, P>

§

impl<T, P> Sync for Leb128Codec<T, P>

§

impl<T, P> Unpin for Leb128Codec<T, P>

§

impl<T, P> UnsafeUnpin for Leb128Codec<T, P>

§

impl<T, P> UnwindSafe for Leb128Codec<T, P>

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.