Encoder

Struct Encoder 

Source
pub struct Encoder {
    pub buffer: Vec<u8>,
    /* private fields */
}

Fields§

§buffer: Vec<u8>

Implementations§

Source§

impl Encoder

Source

pub fn word(&mut self, c: usize) -> &mut Self

Encode a unsigned integer of any size. This is byte alignment agnostic. We encode the 7 least significant bits of the unsigned byte. If the char value is greater than 127 we encode a leading 1 followed by repeating the above for the next 7 bits and so on.

Source

pub fn bool(&mut self, x: bool) -> &mut Self

Encode a bool value. This is byte alignment agnostic. Uses the next unused bit in the current byte to encode this information. One for true and Zero for false

Source

pub fn integer(&mut self, i: &Integer) -> &mut Self

Encode an arbitrarily sized integer.

This is byte alignment agnostic. First we use zigzag once to double the number and encode the negative sign as the least significant bit. Next we encode the 7 least significant bits of the unsigned integer. If the number is greater than 127 we encode a leading 1 followed by repeating the encoding above for the next 7 bits and so on.

Source

pub fn bits(&mut self, num_bits: i64, val: u8) -> &mut Self

Encodes up to 8 bits of information and is byte alignment agnostic. Uses unused bits in the current byte to write out the passed in byte value. Overflows to the most significant digits of the next byte if number of bits to use is greater than unused bits. Expects that number of bits to use is greater than or equal to required bits by the value. The param num_bits is i64 to match unused_bits type.

Source

pub fn bytes(&mut self, x: &[u8]) -> Result<&mut Self, FlatEncodeError>

Encode a byte array. Uses filler to byte align the buffer, then writes byte array length up to 255. Following that it writes the next 255 bytes from the array. We repeat writing length up to 255 and the next 255 bytes until we reach the end of the byte array. After reaching the end of the byte array we write a 0 byte. Only write 0 byte if the byte array is empty.

Source

pub fn byte_array(&mut self, arr: &[u8]) -> Result<&mut Self, FlatEncodeError>

Encode a byte array in a byte aligned buffer. Throws exception if any bits for the current byte were used. Writes byte array length up to 255 Following that it writes the next 255 bytes from the array. We repeat writing length up to 255 and the next 255 bytes until we reach the end of the byte array. After reaching the end of the buffer we write a 0 byte. Only write 0 if the byte array is empty.

Source

pub fn big_word(&mut self, c: Integer) -> &mut Self

Encode a unsigned integer of 128 bits size. This is byte alignment agnostic. We encode the 7 least significant bits of the unsigned byte. If the char value is greater than 127 we encode a leading 1 followed by repeating the above for the next 7 bits and so on.

Source

pub fn utf8(&mut self, s: &str) -> Result<&mut Self, FlatEncodeError>

Encode a string. Convert to byte array and then use byte array encoding. Uses filler to byte align the buffer, then writes byte array length up to 255. Following that it writes the next 255 bytes from the array. After reaching the end of the buffer we write a 0 byte. Only write 0 byte if the byte array is empty.

Source

pub fn list_with<T>( &mut self, list: &[T], encoder_func: for<'r> fn(&'r mut Encoder, &T) -> Result<(), FlatEncodeError>, ) -> Result<&mut Self, FlatEncodeError>

Encode a list of bytes with a function This is byte alignment agnostic. If there are bytes in a list then write 1 bit followed by the functions encoding. After the last item write a 0 bit. If the list is empty only encode a 0 bit.

Source

pub fn filler(&mut self) -> &mut Self

A filler amount of end 0’s followed by a 1 at the end of a byte. Used to byte align the buffer by padding out the rest of the byte.

Trait Implementations§

Source§

impl Default for Encoder

Source§

fn default() -> Encoder

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