Struct BinaryWriter

Source
pub struct BinaryWriter<'a> { /* private fields */ }
Expand description

Write to a stream.

Implementations§

Source§

impl<'a> BinaryWriter<'a>

Source

pub fn new(stream: &'a mut impl WriteStream, endian: Endian) -> Self

Create a binary writer with the given endianness.

Source

pub fn write_string<S: AsRef<str>>(&mut self, value: S) -> Result<usize>

Write a length-prefixed String to the stream.

The length of the String is written as a usize unless the wasm32 or string_len_u32 feature is enabled in which case the length is a u32.

Source

pub fn write_7bit_encoded_len_string<S: AsRef<str>>( &mut self, value: S, ) -> Result<usize>

Write a 7bit encoded length-prefixed String to the stream.

The length of the String is written as a 7bit encoded usize unless the wasm32 or string_len_u32 feature is enabled in which case the length is a 7bit encoded u32.

Source

pub fn write_char<V: Borrow<char>>(&mut self, v: V) -> Result<usize>

Write a character to the stream.

Source

pub fn write_bool<V: Borrow<bool>>(&mut self, value: V) -> Result<usize>

Write a bool to the stream.

Source

pub fn write_f32<V: Borrow<f32>>(&mut self, value: V) -> Result<usize>

Write a f32 to the stream.

Source

pub fn write_f64<V: Borrow<f64>>(&mut self, value: V) -> Result<usize>

Write a f64 to the stream.

Source

pub fn write_isize<V: Borrow<isize>>(&mut self, value: V) -> Result<usize>

Write an isize to the stream.

Source

pub fn write_usize<V: Borrow<usize>>(&mut self, value: V) -> Result<usize>

Write a usize to the stream.

Source

pub fn write_u64<V: Borrow<u64>>(&mut self, value: V) -> Result<usize>

Write a u64 to the stream.

Source

pub fn write_i64<V: Borrow<i64>>(&mut self, value: V) -> Result<usize>

Write an i64 to the stream.

Source

pub fn write_u32<V: Borrow<u32>>(&mut self, value: V) -> Result<usize>

Write a u32 to the stream.

Source

pub fn write_i32<V: Borrow<i32>>(&mut self, value: V) -> Result<usize>

Write an i32 to the stream.

Source

pub fn write_u16<V: Borrow<u16>>(&mut self, value: V) -> Result<usize>

Write a u16 to the stream.

Source

pub fn write_i16<V: Borrow<i16>>(&mut self, value: V) -> Result<usize>

Write an i16 to the stream.

Source

pub fn write_u8<V: Borrow<u8>>(&mut self, value: V) -> Result<usize>

Write a u8 to the stream.

Source

pub fn write_i8<V: Borrow<i8>>(&mut self, value: V) -> Result<usize>

Write an i8 to the stream.

Source

pub fn write_bytes<B: AsRef<[u8]>>(&mut self, data: B) -> Result<usize>

Write a byte buffer to the stream.

Source

pub fn write_bytes_with_value( &mut self, count: usize, fill_value: u8, ) -> Result<usize>

Write a byte buffer to the stream.

Source

pub fn write_7bit_encoded_i32(&mut self, value: i32) -> Result<usize>

Write 7bit encoded i32 to the stream

Source

pub fn write_7bit_encoded_u32(&mut self, value: u32) -> Result<usize>

Write 7bit encoded u32 to the stream

Source

pub fn write_7bit_encoded_usize(&mut self, value: usize) -> Result<usize>

Write 7bit encoded usize to the stream

Source

pub fn swap_endianness(&mut self)

Swap endianness to allow for reversing the writing mid stream

Trait Implementations§

Source§

impl<'a> SeekStream for BinaryWriter<'a>

Source§

fn seek(&mut self, to: usize) -> Result<usize>

Seek to a position.
Source§

fn tell(&mut self) -> Result<usize>

Get the current position.
Source§

fn len(&self) -> Result<usize>

Get the length of the stream.

Auto Trait Implementations§

§

impl<'a> Freeze for BinaryWriter<'a>

§

impl<'a> !RefUnwindSafe for BinaryWriter<'a>

§

impl<'a> !Send for BinaryWriter<'a>

§

impl<'a> !Sync for BinaryWriter<'a>

§

impl<'a> Unpin for BinaryWriter<'a>

§

impl<'a> !UnwindSafe for BinaryWriter<'a>

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

Source§

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

Source§

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.