pub struct BigEndianWriter<W: Write>(/* private fields */);Expand description
Writes bits in the big-endian format
BigEndianWriter writes bits starting from the most significant bit (MSB).
Individual bits are packed into bytes with the first bit written going to the
MSB position, and multi-byte values are written with the most significant
byte first.
§Examples
use bitter::{BitWriter, BigEndianWriter};
let mut buffer = Vec::new();
{
let mut writer = BigEndianWriter::new(&mut buffer);
// Write some mixed data
writer.write_bit(true).unwrap(); // 1 bit
writer.write_u8(0xFF).unwrap(); // 8 bits
writer.write_u16(0x1234).unwrap(); // 16 bits
writer.write_bits(4, 0xA).unwrap(); // 4 more bits
writer.flush().unwrap();
}
// Data is written in big-endian bit order
println!("Written {} bytes", buffer.len());§Bit Ordering
In big-endian format:
- Individual bits are written from MSB to LSB within each byte
- Multi-byte values have their most significant byte written first
- This matches the bit ordering used by
BigEndianReader
Implementations§
Source§impl<W: Write> BigEndianWriter<W>
impl<W: Write> BigEndianWriter<W>
Sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Create a big endian writer from the given Write implementation.
§Examples
use bitter::{BitWriter, BigEndianWriter};
let mut buffer = Vec::new();
{
let mut writer = BigEndianWriter::new(&mut buffer);
writer.write_u32(0x12345678).unwrap();
writer.flush().unwrap();
}
// Big endian: most significant byte first
assert_eq!(buffer, &[0x12, 0x34, 0x56, 0x78]);Sourcepub fn into_inner(self) -> Result<W, IntoInnerError<BigEndianWriter<W>>>
pub fn into_inner(self) -> Result<W, IntoInnerError<BigEndianWriter<W>>>
Unwraps this BigEndianWriter, returning the underlying writer.
The buffer is flushed before returning the writer. If an error occurs while flushing, both the error and the writer are returned.
§Errors
An IntoInnerError will be returned if an error occurs while flushing the buffer.
This allows recovery of the original writer.
§Examples
use bitter::{BitWriter, BigEndianWriter};
let mut buffer = Vec::new();
let mut writer = BigEndianWriter::new(&mut buffer);
writer.write_u8(42).unwrap();
let buffer = writer.into_inner().unwrap();
assert_eq!(buffer, &[42]);Sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
Gets a reference to the underlying writer.
§Examples
use bitter::{BitWriter, BigEndianWriter};
let mut buffer = Vec::new();
let writer = BigEndianWriter::new(&mut buffer);
// Get a reference to the underlying buffer
let buffer_ref = writer.get_ref();Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Gets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
§Examples
use bitter::{BitWriter, BigEndianWriter};
let mut buffer = Vec::new();
let mut writer = BigEndianWriter::new(&mut buffer);
// Get a mutable reference to the underlying buffer
let buffer_ref = writer.get_mut();Trait Implementations§
Source§impl<W: Write> BitWriter for BigEndianWriter<W>
impl<W: Write> BitWriter for BigEndianWriter<W>
Source§fn write_u16(&mut self, value: u16) -> Result<()>
fn write_u16(&mut self, value: u16) -> Result<()>
Source§fn write_bits(&mut self, bits: u32, value: u64) -> Result<()>
fn write_bits(&mut self, bits: u32, value: u64) -> Result<()>
Source§fn write_signed_bits(&mut self, bits: u32, value: i64) -> Result<()>
fn write_signed_bits(&mut self, bits: u32, value: i64) -> Result<()>
Source§fn unaligned_bits(&self) -> u32
fn unaligned_bits(&self) -> u32
Source§impl<W: Write> Write for BigEndianWriter<W>
impl<W: Write> Write for BigEndianWriter<W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)