Struct BinaryWriter

Source
pub struct BinaryWriter {
    pub out: Vec<u8>,
}
Expand description

Encodes binary values, using the same rules as .NET’s System.IO.BinaryWriter.

Fields§

§out: Vec<u8>

The output data.

Implementations§

Source§

impl BinaryWriter

Source

pub fn wrap(out: Vec<u8>) -> Self

Constructor

Source

pub fn into_inner(self) -> Vec<u8>

Extracts the inner buffer

Source

pub fn inner_mut(&mut self) -> &mut Vec<u8>

Accesses the inner buffer

Source

pub fn new() -> Self

Creates a new BinaryWriter over a Vec<u8>

Source

pub fn with_capacity(len: usize) -> Self

Creates a new BinaryWriter over a Vec<u8> with the given capacity.

Source

pub fn write_bytes(&mut self, bytes: &[u8])

Writes bytes to the output.

Source

pub fn write_cbytes<const N: usize>(&mut self, value: [u8; N])

Writes a small, fixed-size array of bytes.

Source

pub fn write_u8(&mut self, value: u8)

Writes a single u8 value

Source

pub fn write_i8(&mut self, value: i8)

Writes a single i8 value

Source

pub fn write_u16(&mut self, value: u16)

Writes a single u16 value

Source

pub fn write_u32(&mut self, value: u32)

Writes a single u32 value

Source

pub fn write_u64(&mut self, value: u64)

Writes a single u64 value

Source

pub fn write_i16(&mut self, value: i16)

Writes a single i16 value

Source

pub fn write_i32(&mut self, value: i32)

Writes a single i32 value

Source

pub fn write_i64(&mut self, value: i64)

Writes a single i64 value

Source

pub fn write_7bit_encoded_i32(&mut self, value: i32)

Encodes an i32 value using a variable-length encoding.

Although this function takes i32 values, applications should avoid using this for negative values. This function can correctly encode negative values, but most “small” negative value (e.g. -10) will be encoded with the maximum number of bytes, which wastes space.

Source

pub fn write_7bit_encoded_i64(&mut self, value: i64)

Encodes an i64 value using a variable-length encoding.

Although this function takes i64 values, applications should avoid using this for negative values. This function can correctly encode negative values, but most “small” negative value (e.g. -10) will be encoded with the maximum number of bytes, which wastes space.

Source

pub fn write_bool(&mut self, value: bool)

Writes a bool value. True is encoded as 1. False is encoded as 0.

Source

pub fn write_f32(&mut self, value: f32)

Writes an f32 value. The value is encoded using its 4-byte little-endian in-memory representation.

Source

pub fn write_f64(&mut self, value: f64)

Writes an f64 value. The value is encoded using its 4-byte little-endian in-memory representation.

Source

pub fn write_utf8_str(&mut self, s: &str) -> Result<(), BinaryWriterError>

Writes a UTF-8 string in length-prefixed form.

Source

pub fn write_utf8_bytes(&mut self, s: &[u8]) -> Result<(), BinaryWriterError>

Writes a UTF-8 string in length-prefixed form.

This function does not validate that the input string is well-formed UTF-8.

Source

pub fn write_utf16_wchars(&mut self, s: &[u16]) -> Result<(), BinaryWriterError>

Writes a UTF-16 string in length-prefixed form.

This function does not validate that the input string is well-formed UTF-16.

Source

pub fn write_utf16_encode(&mut self, s: &str)

Converts a UTF-8 string into UTF-16 and writes it in length-prefixed form.

Auto Trait Implementations§

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.