Trait ByteWrite

trait ByteWrite

A trait for anything that can write aligned values to an output stream

Required Methods

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

Writes whole numeric value to stream

Errors

Passes along any I/O error from the underlying stream.

Examples

use std::io::Write;
use bitstream_io::{BigEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), BigEndian);
writer.write(0b0000000011111111u16).unwrap();
assert_eq!(writer.into_writer(), [0b00000000, 0b11111111]);
use std::io::Write;
use bitstream_io::{LittleEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), LittleEndian);
writer.write(0b0000000011111111u16).unwrap();
assert_eq!(writer.into_writer(), [0b11111111, 0b00000000]);
fn write_as<F, V>(self: &mut Self, value: V) -> Result<()>
where
    F: Endianness,
    V: Primitive

Writes whole numeric value to stream in a potentially different endianness

Errors

Passes along any I/O error from the underlying stream.

Examples

use std::io::Write;
use bitstream_io::{BigEndian, ByteWriter, ByteWrite, LittleEndian};
let mut writer = ByteWriter::endian(Vec::new(), BigEndian);
writer.write_as::<LittleEndian, u16>(0b0000000011111111).unwrap();
assert_eq!(writer.into_writer(), [0b11111111, 0b00000000]);
use std::io::Write;
use bitstream_io::{BigEndian, ByteWriter, ByteWrite, LittleEndian};
let mut writer = ByteWriter::endian(Vec::new(), LittleEndian);
writer.write_as::<BigEndian, u16>(0b0000000011111111).unwrap();
assert_eq!(writer.into_writer(), [0b00000000, 0b11111111]);
fn write_bytes(self: &mut Self, buf: &[u8]) -> Result<()>

Writes the entirety of a byte buffer to the stream.

Errors

Passes along any I/O error from the underlying stream.

fn writer_ref(self: &mut Self) -> &mut dyn Write

Returns mutable reference to underlying writer

Provided Methods

fn build<T: ToByteStream>(self: &mut Self, build: &T) -> Result<(), <T as >::Error>

Builds and writes complex type

fn build_with<'a, T: ToByteStreamWith<'a>>(self: &mut Self, build: &T, context: &<T as >::Context) -> Result<(), <T as >::Error>

Builds and writes complex type with context

Implementors