Skip to main content

ByteWriter

Struct ByteWriter 

Source
pub struct ByteWriter { /* private fields */ }
Expand description

Reusable little-endian binary writer.

Implementations§

Source§

impl ByteWriter

Source

pub const fn new() -> Self

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn from_vec(buf: Vec<u8>) -> Self

Source

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.

Source

pub fn clear(&mut self)

Source

pub fn reserve(&mut self, additional: usize)

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_slice(&self) -> &[u8] ⓘ

Source

pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Writes a canonical little-endian f32 (-0.0 -> +0.0, NaN -> canonical quiet NaN).

Source

pub fn write_f32_raw(&mut self, v: f32)

Writes a raw little-endian f32 preserving exact IEEE-754 bit patterns.

Source

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

Writes a canonical little-endian f64 (-0.0 -> +0.0, NaN -> canonical quiet NaN).

Source

pub fn write_f64_raw(&mut self, v: f64)

Writes a raw little-endian f64 preserving exact IEEE-754 bit patterns.

Source

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

Source

pub fn write_zeroes(&mut self, count: usize) -> Result<(), CodecError>

Source

pub fn patch_u32(&mut self, offset: usize, v: u32) -> Result<(), CodecError>

Source

pub fn write_len(&mut self, len: usize) -> Result<(), CodecError>

Source

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.

Source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source

pub fn write_bytes_max( &mut self, bytes: &[u8], max: usize, ) -> Result<(), CodecError>

Source

pub fn write_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source

pub fn write_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source

pub fn write_str(&mut self, s: &str) -> Result<(), CodecError>

Source

pub fn write_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>

Source

pub fn write_str_u16(&mut self, s: &str) -> Result<(), CodecError>

Source

pub fn write_str_u8(&mut self, s: &str) -> Result<(), CodecError>

Source

pub fn write_opt<T>( &mut self, opt: Option<T>, write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>, ) -> Result<(), CodecError>

Source

pub fn write_value<T: NvEncode>(&mut self, value: &T) -> Result<(), CodecError>

Trait Implementations§

Source§

impl ByteSink for ByteWriter

Source§

fn put_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_zeroes(&mut self, count: usize) -> Result<(), CodecError>

Source§

fn put_u8(&mut self, v: u8) -> Result<(), CodecError>

Source§

fn put_i8(&mut self, v: i8) -> Result<(), CodecError>

Source§

fn put_bool(&mut self, v: bool) -> Result<(), CodecError>

Source§

fn put_u16(&mut self, v: u16) -> Result<(), CodecError>

Source§

fn put_i16(&mut self, v: i16) -> Result<(), CodecError>

Source§

fn put_u32(&mut self, v: u32) -> Result<(), CodecError>

Source§

fn put_i32(&mut self, v: i32) -> Result<(), CodecError>

Source§

fn put_u64(&mut self, v: u64) -> Result<(), CodecError>

Source§

fn put_i64(&mut self, v: i64) -> Result<(), CodecError>

Source§

fn put_f32(&mut self, v: f32) -> Result<(), CodecError>

Source§

fn put_f32_raw(&mut self, v: f32) -> Result<(), CodecError>

Source§

fn put_f64(&mut self, v: f64) -> Result<(), CodecError>

Source§

fn put_f64_raw(&mut self, v: f64) -> Result<(), CodecError>

Source§

fn put_len(&mut self, len: usize) -> Result<(), CodecError>

Source§

fn put_len_max(&mut self, len: usize, max: usize) -> Result<(), CodecError>

Source§

fn put_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_bytes_max(&mut self, bytes: &[u8], max: usize) -> Result<(), CodecError>

Source§

fn put_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_str(&mut self, s: &str) -> Result<(), CodecError>

Source§

fn put_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>

Source§

fn put_str_u16(&mut self, s: &str) -> Result<(), CodecError>

Source§

fn put_str_u8(&mut self, s: &str) -> Result<(), CodecError>

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ByteWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ByteWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for ByteWriter

§

impl Freeze for ByteWriter
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for ByteWriter

§

impl RefUnwindSafe for ByteWriter

§

impl Send for ByteWriter
where RawVecInner: Send,

§

impl Sync for ByteWriter
where RawVecInner: Sync,

§

impl Unpin for ByteWriter
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for ByteWriter

§

impl UnwindSafe for ByteWriter
where RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.