Decoder

Struct Decoder 

Source
pub struct Decoder<'b> {
    pub buffer: &'b [u8],
    pub used_bits: usize,
    pub pos: usize,
}

Fields§

§buffer: &'b [u8]§used_bits: usize§pos: usize

Implementations§

Source§

impl<'b> Decoder<'b>

Source

pub fn new(bytes: &'b [u8]) -> Decoder<'b>

Source

pub fn word(&mut self) -> Result<usize, FlatDecodeError>

Decode a word of any size. This is byte alignment agnostic. First we decode the next 8 bits of the buffer. We take the 7 least significant bits as the 7 least significant bits of the current unsigned integer. If the most significant bit of the 8 bits is 1 then we take the next 8 and repeat the process above, filling in the next 7 least significant bits of the unsigned integer and so on. If the most significant bit was instead 0 we stop decoding any more bits.

Source

pub fn list_with<'a, T, F>( &mut self, ctx: &mut Ctx<'a>, decoder_func: F, ) -> Result<BumpVec<'a, T>, FlatDecodeError>
where F: Copy + FnOnce(&mut Ctx<'a>, &mut Decoder<'_>) -> Result<T, FlatDecodeError>,

Decode a list of items with a decoder function. This is byte alignment agnostic. Decode a bit from the buffer. If 0 then stop. Otherwise we decode an item in the list with the decoder function passed in. Then decode the next bit in the buffer and repeat above. Returns a list of items decoded with the decoder function.

Source

pub fn bits8(&mut self, num_bits: usize) -> Result<u8, FlatDecodeError>

Decode up to 8 bits. This is byte alignment agnostic. If num_bits is greater than the 8 we throw an IncorrectNumBits error. First we decode the next num_bits of bits in the buffer. If there are less unused bits in the current byte in the buffer than num_bits, then we decode the remaining bits from the most significant bits in the next byte in the buffer. Otherwise we decode the unused bits from the current byte. Returns the decoded value up to a byte in size.

Source

pub fn filler(&mut self) -> Result<(), FlatDecodeError>

Decodes a filler of max one byte size. Decodes bits until we hit a bit that is 1. Expects that the 1 is at the end of the current byte in the buffer.

Source

pub fn bit(&mut self) -> Result<bool, FlatDecodeError>

Decode the next bit in the buffer. If the bit was 1 then return true. Otherwise return false. Throws EndOfBuffer error if used at the end of the array.

Source

pub fn integer(&mut self) -> Result<Integer, FlatDecodeError>

Decode an integer of an arbitrary size..

This is byte alignment agnostic. First we decode the next 8 bits of the buffer. We take the 7 least significant bits as the 7 least significant bits of the current unsigned integer. If the most significant bit of the 8 bits is 1 then we take the next 8 and repeat the process above, filling in the next 7 least significant bits of the unsigned integer and so on. If the most significant bit was instead 0 we stop decoding any more bits. Finally we use zigzag to convert the unsigned integer back to a signed integer.

Source

pub fn big_word(&mut self) -> Result<Integer, FlatDecodeError>

Decode a word of 128 bits size. This is byte alignment agnostic. First we decode the next 8 bits of the buffer. We take the 7 least significant bits as the 7 least significant bits of the current unsigned integer. If the most significant bit of the 8 bits is 1 then we take the next 8 and repeat the process above, filling in the next 7 least significant bits of the unsigned integer and so on. If the most significant bit was instead 0 we stop decoding any more bits.

Source

pub fn bytes<'a>( &mut self, arena: &'a Bump, ) -> Result<BumpVec<'a, u8>, FlatDecodeError>

Decode a byte array. Decodes a filler to byte align the buffer, then decodes the next byte to get the array length up to a max of 255. We decode bytes equal to the array length to form the byte array. If the following byte for array length is not 0 we decode it and repeat above to continue decoding the byte array. We stop once we hit a byte array length of 0. If array length is 0 for first byte array length the we return a empty array.

Source

pub fn utf8<'a>(&mut self, arena: &'a Bump) -> Result<&'a str, FlatDecodeError>

Decode a string. Convert to byte array and then use byte array decoding. Decodes a filler to byte align the buffer, then decodes the next byte to get the array length up to a max of 255. We decode bytes equal to the array length to form the byte array. If the following byte for array length is not 0 we decode it and repeat above to continue decoding the byte array. We stop once we hit a byte array length of 0. If array length is 0 for first byte array length the we return a empty array.

Auto Trait Implementations§

§

impl<'b> Freeze for Decoder<'b>

§

impl<'b> RefUnwindSafe for Decoder<'b>

§

impl<'b> Send for Decoder<'b>

§

impl<'b> Sync for Decoder<'b>

§

impl<'b> Unpin for Decoder<'b>

§

impl<'b> UnwindSafe for Decoder<'b>

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> MaybeSync for T