Struct vorbis_bitpack::BitpackWriter
source · [−]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
sourceimpl<W: Write> BitpackWriter<W>
impl<W: Write> BitpackWriter<W>
sourcepub fn new(sink: W) -> Self
pub fn new(sink: W) -> Self
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.
sourcepub fn write_unsigned_integer(
&mut self,
integer: u32,
width: BitpackedIntegerWidth
) -> Result<()>
pub fn write_unsigned_integer(
&mut self,
integer: u32,
width: BitpackedIntegerWidth
) -> Result<()>
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.
sourcepub fn write_signed_integer(
&mut self,
integer: i32,
width: BitpackedIntegerWidth
) -> Result<()>
pub fn write_signed_integer(
&mut self,
integer: i32,
width: BitpackedIntegerWidth
) -> Result<()>
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.
sourcepub fn write_float32(&mut self, float: f64) -> Result<()>
pub fn write_float32(&mut self, float: f64) -> Result<()>
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.
sourcepub fn write_flag(&mut self, flag: bool) -> Result<()>
pub fn write_flag(&mut self, flag: bool) -> Result<()>
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.
sourcepub fn finalize(&mut self) -> Result<()>
pub fn finalize(&mut self) -> Result<()>
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
.
Trait Implementations
sourceimpl<W: Debug + Write> Debug for BitpackWriter<W>
impl<W: Debug + Write> Debug for BitpackWriter<W>
Auto Trait Implementations
impl<W> RefUnwindSafe for BitpackWriter<W> where
W: RefUnwindSafe,
impl<W> Send for BitpackWriter<W> where
W: Send,
impl<W> Sync for BitpackWriter<W> where
W: Sync,
impl<W> Unpin for BitpackWriter<W> where
W: Unpin,
impl<W> UnwindSafe for BitpackWriter<W> where
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more