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

Fields

buffer: &'b [u8]used_bits: i64pos: usize

Implementations

Decode any type that implements Decode.

Decode an integer 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. Finally we use zigzag to convert the unsigned integer back to a signed integer.

Decode a single bit of the buffer to get a bool. We mask out a single bit of the buffer based on used bits. and check if it is 0 for false or 1 for true.

Decode a byte from the buffer. This byte alignment agnostic. We use the next 8 bits in the buffer and return the resulting byte.

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.

Decode a 32 bit char. 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.

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.

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.

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.

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.

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.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.