Struct ReadBuffer

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

A buffer for reading codec data with safety checks

Implementations§

Source§

impl ReadBuffer

Source

pub fn new(bytes: Bytes) -> Self

Creates a new reader from bytes

Source

pub fn read_varint(&mut self) -> Result<u64, Error>

Reads a varint-encoded unsigned integer

Source

pub fn get_u8(&mut self) -> Result<u8, Error>

Gets a byte from the buffer

Source

pub fn remaining(&self) -> usize

Gets remaining bytes

Source

pub fn has_remaining(&self) -> bool

Checks if the buffer has any remaining bytes

Source

pub fn at_least(&self, size: usize) -> Result<(), Error>

Ensures the buffer has at least size bytes remaining

Source

pub fn advance(&mut self, cnt: usize)

Advance the buffer by cnt bytes

Source

pub fn get_u16(&mut self) -> Result<u16, Error>

Source

pub fn get_u32(&mut self) -> Result<u32, Error>

Source

pub fn get_u64(&mut self) -> Result<u64, Error>

Source

pub fn get_u128(&mut self) -> Result<u128, Error>

Source

pub fn get_i8(&mut self) -> Result<i8, Error>

Source

pub fn get_i16(&mut self) -> Result<i16, Error>

Source

pub fn get_i32(&mut self) -> Result<i32, Error>

Source

pub fn get_i64(&mut self) -> Result<i64, Error>

Source

pub fn get_i128(&mut self) -> Result<i128, Error>

Source

pub fn get_f32(&mut self) -> Result<f32, Error>

Source

pub fn get_f64(&mut self) -> Result<f64, Error>

Source

pub fn copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), Error>

Source

pub fn split_to(&mut self, size: usize) -> Result<Bytes, Error>

Source

pub fn inner(&self) -> &Bytes

Returns a reference to the internal buffer

Trait Implementations§

Source§

impl Debug for ReadBuffer

Source§

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

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

impl Reader for ReadBuffer

Source§

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

Reads a u8 value
Source§

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

Reads a u16 value
Source§

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

Reads a u32 value
Source§

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

Reads a u64 value
Source§

fn read_u128(&mut self) -> Result<u128, Error>

Reads a u128 value
Source§

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

Reads a i8 value
Source§

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

Reads a i16 value
Source§

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

Reads a i32 value
Source§

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

Reads a i64 value
Source§

fn read_i128(&mut self) -> Result<i128, Error>

Reads a i128 value
Source§

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

Reads a f32 value
Source§

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

Reads a f64 value
Source§

fn read_varint(&mut self) -> Result<u64, Error>

Reads a varint-encoded integer
Source§

fn read_bytes(&mut self) -> Result<Bytes, Error>

Reads bytes with a length prefix
Source§

fn read_n_bytes(&mut self, n: usize) -> Result<Bytes, Error>

Reads a fixed number of bytes
Source§

fn read_bytes_lte(&mut self, max: usize) -> Result<Bytes, Error>

Reads bytes with a length prefix, with a limit on the number of bytes
Source§

fn read_fixed<const N: usize>(&mut self) -> Result<[u8; N], Error>

Reads a fixed number of bytes into a fixed-size byte array
Source§

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

Reads a boolean value
Source§

fn read_option<T: Codec>(&mut self) -> Result<Option<T>, Error>

Reads an option value
Source§

fn read_vec<T: Codec>(&mut self) -> Result<Vec<T>, Error>

Reads a vector with a length prefix
Source§

fn read_vec_lte<T: Codec>(&mut self, max: usize) -> Result<Vec<T>, Error>

Reads a vector with a length prefix, with a limit on the number of elements

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.