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

Fields

buffer: Vec<u8>

Implementations

Encode any type that implements Encode.

Encode 1 unsigned byte. Uses the next 8 bits in the buffer, can be byte aligned or byte unaligned

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

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.

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.

Encode an integer of any size. 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.

Encode a char of 32 bits. 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.

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.

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.

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.

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.

Trait Implementations

Returns the “default value” for a type. 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.