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
impl BinaryWriter
Sourcepub fn into_inner(self) -> Vec<u8> ⓘ
pub fn into_inner(self) -> Vec<u8> ⓘ
Extracts the inner buffer
Sourcepub fn with_capacity(len: usize) -> Self
pub fn with_capacity(len: usize) -> Self
Creates a new BinaryWriter
over a Vec<u8>
with the given capacity.
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Writes bytes
to the output.
Sourcepub fn write_cbytes<const N: usize>(&mut self, value: [u8; N])
pub fn write_cbytes<const N: usize>(&mut self, value: [u8; N])
Writes a small, fixed-size array of bytes.
Sourcepub fn write_7bit_encoded_i32(&mut self, value: i32)
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.
Sourcepub fn write_7bit_encoded_i64(&mut self, value: i64)
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.
Sourcepub fn write_bool(&mut self, value: bool)
pub fn write_bool(&mut self, value: bool)
Writes a bool
value. True is encoded as 1. False is encoded as 0.
Sourcepub fn write_f32(&mut self, value: f32)
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.
Sourcepub fn write_f64(&mut self, value: f64)
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.
Sourcepub fn write_utf8_str(&mut self, s: &str) -> Result<(), BinaryWriterError>
pub fn write_utf8_str(&mut self, s: &str) -> Result<(), BinaryWriterError>
Writes a UTF-8 string in length-prefixed form.
Sourcepub fn write_utf8_bytes(&mut self, s: &[u8]) -> Result<(), BinaryWriterError>
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.
Sourcepub fn write_utf16_wchars(&mut self, s: &[u16]) -> Result<(), BinaryWriterError>
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.
Sourcepub fn write_utf16_encode(&mut self, s: &str)
pub fn write_utf16_encode(&mut self, s: &str)
Converts a UTF-8 string into UTF-16 and writes it in length-prefixed form.