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>
impl<N: Default + Copy, E: Endianness> BitRecorder<N, E>
Sourcepub fn with_capacity(writes: usize) -> Self
pub fn with_capacity(writes: usize) -> Self
Creates new recorder sized for the given number of writes
Trait Implementations§
Source§impl<N, E> BitWrite for BitRecorder<N, E>
impl<N, E> BitWrite for BitRecorder<N, E>
Source§fn write<U>(&mut self, bits: u32, value: U) -> Result<()>where
U: Numeric,
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_out<const BITS: u32, U>(&mut self, value: U) -> Result<()>where
U: Numeric,
fn write_out<const BITS: u32, U>(&mut self, value: U) -> Result<()>where
U: Numeric,
Writes an unsigned value to the stream using the given
const number of bits. Read more
Source§fn write_signed<S>(&mut self, bits: u32, value: S) -> Result<()>where
S: SignedNumeric,
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_signed_out<const BITS: u32, S>(&mut self, value: S) -> Result<()>where
S: SignedNumeric,
fn write_signed_out<const BITS: u32, S>(&mut self, value: S) -> Result<()>where
S: SignedNumeric,
Writes a twos-complement signed value to the stream
with the given const number of bits. Read more
Source§fn write_from<V>(&mut self, value: V) -> Result<()>where
V: Primitive,
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_as_from<F, V>(&mut self, value: V) -> Result<()>where
F: Endianness,
V: Primitive,
fn write_as_from<F, V>(&mut self, value: V) -> Result<()>where
F: Endianness,
V: Primitive,
Writes whole value to the stream whose size in bits
is equal to its type’s size in an endianness that may
be different from the stream’s endianness. Read more
Source§fn write_unary0(&mut self, value: u32) -> Result<()>
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 moreSource§fn write_unary1(&mut self, value: u32) -> Result<()>
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 moreSource§fn write_bytes(&mut self, buf: &[u8]) -> Result<()>
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
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>
fn build<T: ToBitStream>(&mut self, build: &T) -> Result<(), T::Error>
Builds and writes complex type
Source§fn build_with<'a, T: ToBitStreamWith<'a>>(
&mut self,
build: &T,
context: &T::Context,
) -> Result<(), T::Error>
fn build_with<'a, T: ToBitStreamWith<'a>>( &mut self, build: &T, context: &T::Context, ) -> Result<(), T::Error>
Builds and writes complex type with context
Source§impl<N: Default, E: Default + Endianness> Default for BitRecorder<N, E>
impl<N: Default, E: Default + Endianness> Default for BitRecorder<N, E>
Source§fn default() -> BitRecorder<N, E>
fn default() -> BitRecorder<N, E>
Returns the “default value” for a type. Read more
Source§impl<N, E> HuffmanWrite<E> for BitRecorder<N, E>
impl<N, E> HuffmanWrite<E> for BitRecorder<N, E>
Source§fn write_huffman<T>(
&mut self,
tree: &WriteHuffmanTree<E, T>,
symbol: T,
) -> Result<()>
fn write_huffman<T>( &mut self, tree: &WriteHuffmanTree<E, T>, symbol: T, ) -> Result<()>
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>where
N: RefUnwindSafe,
E: RefUnwindSafe,
impl<N, E> Send for BitRecorder<N, E>
impl<N, E> Sync for BitRecorder<N, E>
impl<N, E> Unpin for BitRecorder<N, E>
impl<N, E> UnwindSafe for BitRecorder<N, E>where
N: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more