Struct bitstream_io::write::BitRecorder

source ·
pub struct BitRecorder<N, E: Endianness> { /* private fields */ }
Expand description

For recording writes in order to play them back on another writer

§Example

use std::io::Write;
use bitstream_io::{BigEndian, BitWriter, BitWrite, BitRecorder};
let mut recorder: BitRecorder<u32, BigEndian> = BitRecorder::new();
recorder.write(1, 0b1).unwrap();
recorder.write(2, 0b01).unwrap();
recorder.write(5, 0b10111).unwrap();
assert_eq!(recorder.written(), 8);
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
recorder.playback(&mut writer);
assert_eq!(writer.into_writer(), [0b10110111]);

Implementations§

source§

impl<N: Default + Copy, E: Endianness> BitRecorder<N, E>

source

pub fn new() -> Self

Creates new recorder

source

pub fn with_capacity(writes: usize) -> Self

Creates new recorder sized for the given number of writes

source

pub fn endian(_endian: E) -> Self

Creates new recorder with the given endianness

source

pub fn written(&self) -> N

Returns number of bits written

source

pub fn playback<W: BitWrite>(&self, writer: &mut W) -> Result<()>

Plays recorded writes to the given writer

Trait Implementations§

source§

impl<N, E> BitWrite for BitRecorder<N, E>
where E: Endianness, N: Copy + From<u32> + AddAssign + Rem<Output = N> + Eq,

source§

fn write_bit(&mut self, bit: bool) -> Result<()>

Writes a single bit to the stream. true indicates 1, false indicates 0 Read more
source§

fn write<U>(&mut self, bits: u32, value: U) -> Result<()>
where U: Numeric,

Writes an unsigned value to the stream using the given number of bits. Read more
source§

fn write_signed<S>(&mut self, bits: u32, value: S) -> Result<()>
where S: SignedNumeric,

Writes a twos-complement signed value to the stream with the given number of bits. Read more
source§

fn write_from<V>(&mut self, value: V) -> Result<()>
where V: Primitive,

Writes whole value to the stream whose size in bits is equal to its type’s size. Read more
source§

fn write_unary0(&mut self, value: u32) -> Result<()>

Writes value number of 1 bits to the stream and then writes a 0 bit. This field is variably-sized. Read more
source§

fn write_unary1(&mut self, value: u32) -> Result<()>

Writes value number of 0 bits to the stream and then writes a 1 bit. This field is variably-sized. Read more
source§

fn write_bytes(&mut self, buf: &[u8]) -> Result<()>

Writes the entirety of a byte buffer to the stream. Read more
source§

fn byte_aligned(&self) -> bool

Returns true if the stream is aligned at a whole byte.
source§

fn build<T: ToBitStream>(&mut self, build: &T) -> Result<(), T::Error>

Builds and writes complex type
source§

fn build_with<T: ToBitStreamWith>( &mut self, build: &T, context: &T::Context ) -> Result<(), T::Error>

Builds and writes complex type with context
source§

fn byte_align(&mut self) -> Result<()>

Pads the stream with 0 bits until it is aligned at a whole byte. Does nothing if the stream is already aligned. Read more
source§

impl<N: Default, E: Default + Endianness> Default for BitRecorder<N, E>

source§

fn default() -> BitRecorder<N, E>

Returns the “default value” for a type. Read more
source§

impl<N, E> HuffmanWrite<E> for BitRecorder<N, E>
where E: Endianness, N: Copy + From<u32> + AddAssign + Rem<Output = N> + Eq,

source§

fn write_huffman<T>( &mut self, tree: &WriteHuffmanTree<E, T>, symbol: T ) -> Result<()>
where T: Ord + Copy,

Writes Huffman code for the given symbol to the stream. Read more

Auto Trait Implementations§

§

impl<N, E> Freeze for BitRecorder<N, E>
where N: Freeze,

§

impl<N, E> RefUnwindSafe for BitRecorder<N, E>

§

impl<N, E> Send for BitRecorder<N, E>
where N: Send, E: Send,

§

impl<N, E> Sync for BitRecorder<N, E>
where N: Sync, E: Sync,

§

impl<N, E> Unpin for BitRecorder<N, E>
where N: Unpin, E: Unpin,

§

impl<N, E> UnwindSafe for BitRecorder<N, E>
where N: UnwindSafe, E: UnwindSafe,

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> 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<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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.