Skip to main content

BufferReader

Struct BufferReader 

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

Decodes values from the WeaveFFI buffer format.

Every read_* method returns BufferDecodeError when the buffer is exhausted or holds invalid data, so a malformed buffer can never cause an out-of-bounds read.

Implementations§

Source§

impl<'a> BufferReader<'a>

Source

pub fn new(data: &'a [u8]) -> Self

Wrap an encoded buffer for reading.

Source

pub fn remaining(&self) -> usize

The number of bytes not yet consumed.

Source

pub fn read_bool(&mut self) -> Result<bool, BufferDecodeError>

Read a bool.

§Errors

Returns an error when the buffer is exhausted or the byte is not 0 or 1.

Source

pub fn read_i8(&mut self) -> Result<i8, BufferDecodeError>

Read an i8.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_u8(&mut self) -> Result<u8, BufferDecodeError>

Read a u8.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_i16(&mut self) -> Result<i16, BufferDecodeError>

Read an i16 little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_u16(&mut self) -> Result<u16, BufferDecodeError>

Read a u16 little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_i32(&mut self) -> Result<i32, BufferDecodeError>

Read an i32 little-endian. Also decodes C-style enum values and rich-enum tags.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_u32(&mut self) -> Result<u32, BufferDecodeError>

Read a u32 little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_i64(&mut self) -> Result<i64, BufferDecodeError>

Read an i64 little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_u64(&mut self) -> Result<u64, BufferDecodeError>

Read a u64 little-endian. Also decodes handles.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_f32(&mut self) -> Result<f32, BufferDecodeError>

Read an f32 from its IEEE 754 bits, little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_f64(&mut self) -> Result<f64, BufferDecodeError>

Read an f64 from its IEEE 754 bits, little-endian.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_len(&mut self) -> Result<usize, BufferDecodeError>

Read a length or element count (a u32).

§Errors

Returns an error when the buffer is exhausted or the decoded length exceeds the bytes remaining (which would make follow-up reads fail anyway; rejecting here gives a clearer error).

Source

pub fn read_string(&mut self) -> Result<String, BufferDecodeError>

Read a string: u32 byte length + UTF-8 bytes.

§Errors

Returns an error when the buffer is exhausted or the bytes are not valid UTF-8.

Source

pub fn read_bytes(&mut self) -> Result<Vec<u8>, BufferDecodeError>

Read a byte buffer: u32 length + raw bytes.

§Errors

Returns an error when the buffer is exhausted.

Source

pub fn read_option_flag(&mut self) -> Result<bool, BufferDecodeError>

Read an optional’s presence flag.

§Errors

Returns an error when the buffer is exhausted or the flag byte is not 0 or 1.

Source

pub fn expect_end(&self) -> Result<(), BufferDecodeError>

Assert the whole buffer was consumed. Called after decoding a complete value to catch trailing garbage.

§Errors

Returns an error when unconsumed bytes remain.

Trait Implementations§

Source§

impl<'a> Debug for BufferReader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BufferReader<'a>

§

impl<'a> RefUnwindSafe for BufferReader<'a>

§

impl<'a> Send for BufferReader<'a>

§

impl<'a> Sync for BufferReader<'a>

§

impl<'a> Unpin for BufferReader<'a>

§

impl<'a> UnsafeUnpin for BufferReader<'a>

§

impl<'a> UnwindSafe for BufferReader<'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 = !

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.