pub struct ByteWriter { /* private fields */ }Expand description
Reusable little-endian binary writer.
Implementations§
Source§impl ByteWriter
impl ByteWriter
pub const fn new() -> Self
pub fn with_capacity(cap: usize) -> Self
pub fn from_vec(buf: Vec<u8>) -> Self
Sourcepub fn with_buf<R>(buf: &mut Vec<u8>, f: impl FnOnce(&mut Self) -> R) -> R
pub fn with_buf<R>(buf: &mut Vec<u8>, f: impl FnOnce(&mut Self) -> R) -> R
Borrows an existing Vec<u8> into a ByteWriter with zero allocation, restoring it on return.
pub fn clear(&mut self)
pub fn reserve(&mut self, additional: usize)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn write_u8(&mut self, v: u8)
pub fn write_i8(&mut self, v: i8)
pub fn write_bool(&mut self, v: bool)
pub fn write_u16(&mut self, v: u16)
pub fn write_i16(&mut self, v: i16)
pub fn write_u32(&mut self, v: u32)
pub fn write_i32(&mut self, v: i32)
pub fn write_u64(&mut self, v: u64)
pub fn write_i64(&mut self, v: i64)
Sourcepub fn write_f32(&mut self, v: f32)
pub fn write_f32(&mut self, v: f32)
Writes a canonical little-endian f32 (-0.0 -> +0.0, NaN -> canonical quiet NaN).
Sourcepub fn write_f32_raw(&mut self, v: f32)
pub fn write_f32_raw(&mut self, v: f32)
Writes a raw little-endian f32 preserving exact IEEE-754 bit patterns.
Sourcepub fn write_f64(&mut self, v: f64)
pub fn write_f64(&mut self, v: f64)
Writes a canonical little-endian f64 (-0.0 -> +0.0, NaN -> canonical quiet NaN).
Sourcepub fn write_f64_raw(&mut self, v: f64)
pub fn write_f64_raw(&mut self, v: f64)
Writes a raw little-endian f64 preserving exact IEEE-754 bit patterns.
pub fn write_raw(&mut self, bytes: &[u8])
pub fn write_zeroes(&mut self, count: usize) -> Result<(), CodecError>
pub fn patch_u32(&mut self, offset: usize, v: u32) -> Result<(), CodecError>
pub fn write_len(&mut self, len: usize) -> Result<(), CodecError>
Sourcepub fn write_len_max(
&mut self,
len: usize,
max: usize,
) -> Result<(), CodecError>
pub fn write_len_max( &mut self, len: usize, max: usize, ) -> Result<(), CodecError>
Writes a u32 length prefix bounded by max (and u32::MAX), rejecting oversized
payloads at encode time so an encoder never emits bytes its own decoder rejects.
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>
pub fn write_bytes_max( &mut self, bytes: &[u8], max: usize, ) -> Result<(), CodecError>
pub fn write_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>
pub fn write_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>
pub fn write_str(&mut self, s: &str) -> Result<(), CodecError>
pub fn write_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>
pub fn write_str_u16(&mut self, s: &str) -> Result<(), CodecError>
pub fn write_str_u8(&mut self, s: &str) -> Result<(), CodecError>
pub fn write_opt<T>( &mut self, opt: Option<T>, write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>, ) -> Result<(), CodecError>
pub fn write_value<T: NvEncode>(&mut self, value: &T) -> Result<(), CodecError>
Trait Implementations§
Source§impl ByteSink for ByteWriter
impl ByteSink for ByteWriter
fn put_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_zeroes(&mut self, count: usize) -> Result<(), CodecError>
fn put_u8(&mut self, v: u8) -> Result<(), CodecError>
fn put_i8(&mut self, v: i8) -> Result<(), CodecError>
fn put_bool(&mut self, v: bool) -> Result<(), CodecError>
fn put_u16(&mut self, v: u16) -> Result<(), CodecError>
fn put_i16(&mut self, v: i16) -> Result<(), CodecError>
fn put_u32(&mut self, v: u32) -> Result<(), CodecError>
fn put_i32(&mut self, v: i32) -> Result<(), CodecError>
fn put_u64(&mut self, v: u64) -> Result<(), CodecError>
fn put_i64(&mut self, v: i64) -> Result<(), CodecError>
fn put_f32(&mut self, v: f32) -> Result<(), CodecError>
fn put_f32_raw(&mut self, v: f32) -> Result<(), CodecError>
fn put_f64(&mut self, v: f64) -> Result<(), CodecError>
fn put_f64_raw(&mut self, v: f64) -> Result<(), CodecError>
fn put_len(&mut self, len: usize) -> Result<(), CodecError>
fn put_len_max(&mut self, len: usize, max: usize) -> Result<(), CodecError>
fn put_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_bytes_max(&mut self, bytes: &[u8], max: usize) -> Result<(), CodecError>
fn put_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_str(&mut self, s: &str) -> Result<(), CodecError>
fn put_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>
fn put_str_u16(&mut self, s: &str) -> Result<(), CodecError>
fn put_str_u8(&mut self, s: &str) -> Result<(), CodecError>
fn put_opt<T>(
&mut self,
opt: Option<T>,
write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>,
) -> Result<(), CodecError>where
Self: Sized,
Source§impl Clone for ByteWriter
impl Clone for ByteWriter
Source§impl Debug for ByteWriter
impl Debug for ByteWriter
Auto Trait Implementations§
impl Forget for ByteWriter
impl Freeze for ByteWriter
impl Move for ByteWriter
impl RefUnwindSafe for ByteWriter
impl Send for ByteWriterwhere
RawVecInner: Send,
impl Sync for ByteWriterwhere
RawVecInner: Sync,
impl Unpin for ByteWriter
impl UnsafeUnpin for ByteWriter
impl UnwindSafe for ByteWriterwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more