pub struct BitpackWriter<W: Write> { /* private fields */ }
Expand description

Wraps a byte sink to write variable-length primitive types to it, packed according to the Vorbis I bitpack convention.

Implementations

Constructs a Vorbis I bitpack writer that write read variable-length primitive types to the specified byte sink.

The bitpack writer may end up writing small amounts of bytes fairly frequently. Therefore, for top performance it is recommended to use buffered byte sinks.

Writes the width least significant bits of the specified unsigned integer to the sink associated to this bitpack writer.

It may happen that the bitpacker does not immediately write every bit to the sink, in order to complete the last byte with further data. The finalize method forces any pending bits to be written immediately, but beware that the reader will have to skip any padding bits in the potentially incomplete last byte to keep bitstream sync.

Writes the the specified signed integer to the sink associated to this bitpack writer, doing a narrowing wrapping conversion to the specified width.

It may happen that the bitpacker does not immediately write every bit to the sink, in order to complete the last byte with further data. The finalize method forces any pending bits to be written immediately, but beware that the reader will have to skip any padding bits in that incomplete byte to keep bitstream sync.

Writes the specified double to the sink associated to this bitpack writer, converting it to the Vorbis float32 format.

This conversion is lossy for numbers that cannot be exactly represented in the float32 format, and is only well-defined for normal floating point numbers. If infinity, NaN or subnormal numbers are a concern, client code should guard against them by checking the result of float.classify() beforehand.

Writes a single bitpacked flag (i.e., boolean) value to the sink associated to this bitpack writer.

Flags are represented by single bits: true is converted to 1, and false to 0.

Immediately writes any bits that did not yet complete a byte, padding that byte with zeroes in the most significant positions.

The bitpack writer is automatically finalized when it is dropped, so this method usually does not need to be called, unless you need to know whether the finalization is successful.

Note that finalizing the bitpack writer does not flush the wrapped byte sink. Any bytes written by this method are only guaranteed to have reached their destination after a call to flush.

Flushes the wrapped byte sink.

This method will not force writing out any bits that did not yet made it to a completed byte. To do that, use finalize.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this 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.