Struct pi_bon::ReadBuffer

source ·
pub struct ReadBuffer<'a> {
    pub bytes: &'a [u8],
    pub head: usize,
}
Expand description

ReadBuffer,用于将二进制反序列化为对应数据

Fields§

§bytes: &'a [u8]§head: usize

Implementations§

source§

impl<'a> ReadBuffer<'a>

source

pub fn new(buf: &[u8], head: usize) -> ReadBuffer<'_>

创建ReadBuffer, buf必须符合bon协议, 否则当调用其partial_cmp会直接panic head指定反序列化开始的位置

source

pub fn head(&self) -> usize

获取ReadBuffer当前的读指针(读是从头部开始,即下一次调用read方法,将从self.head位置向后反序列化)

source

pub fn len(&self) -> usize

二进制的长度

source

pub fn get_type(&mut self) -> Result<u8, ReadBonErr>

获取接下来要反序列化的数据的类型

source

pub fn get_type_chunk(&mut self) -> Result<u8, ReadBonErr>

获取接下来要反序列化的数据的类型(不改变bytes偏移)

source

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

读一个布尔类型,如果二进制当前的值不是布尔类型,返回Err

source

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

读一个u8类型,如果二进制当前的值不是u8类型,返回Err

source

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

读一个u16类型,如果二进制当前的值不是u16类型,返回Err

source

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

读一个u32类型,如果二进制当前的值不是u32类型,返回Err

source

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

读一个u64类型,如果二进制当前的值不是u64类型,返回Err

source

pub fn read_usize(&mut self) -> Result<usize, ReadBonErr>

读一个usize类型,如果二进制当前的值不是usize类型,返回Err

source

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

读一个u128类型,如果二进制当前的值不是u128类型,返回Err

source

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

读一个i8类型,如果二进制当前的值不是i8类型,返回Err

source

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

读一个i16类型,如果二进制当前的值不是i16类型,返回Err

source

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

读一个ui32类型,如果二进制当前的值不是i32类型,返回Err

source

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

读一个i61类型,如果二进制当前的值不是i64类型,返回Err

source

pub fn read_isize(&mut self) -> Result<isize, ReadBonErr>

读一个isize类型,如果二进制当前的值不是isize类型,返回Err

source

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

读一个i128类型,如果二进制当前的值不是i128类型,返回Err

source

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

读一个f32类型,如果二进制当前的值不是f32类型,返回Err

source

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

读一个f64类型,如果二进制当前的值不是f64类型,返回Err

source

pub fn read_lengthen(&mut self) -> Result<u32, ReadBonErr>

读出一个动态长度,正整数,不允许大于0x20000000

source

pub fn read_bin(&mut self) -> Result<Vec<u8>, ReadBonErr>

source

pub fn read_utf8(&mut self) -> Result<String, ReadBonErr>

读一个utf8编码的字符串类型,如果二进制当前的值不是utf8编码的字符串类型类型,返回Err

source

pub fn read_container<T, F>(&mut self, read_next: F) -> Result<T, ReadBonErr>
where F: FnOnce(&mut ReadBuffer<'_>, u32, u64) -> Result<T, ReadBonErr>,

读一个容器类型,如果二进制当前的值不是容器类型,返回Err

source

pub fn is_nil(&mut self) -> Result<bool, ReadBonErr>

下一个值是否为None

source

pub fn read(&mut self) -> Result<EnumValue, ReadBonErr>

读下一个数据,已经读到最后,返回Err。否则,返回下一个数据

Trait Implementations§

source§

impl<'a> Clone for ReadBuffer<'a>

source§

fn clone(&self) -> ReadBuffer<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ReadBuffer<'a>

source§

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

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

impl<'a> Default for ReadBuffer<'a>

source§

fn default() -> ReadBuffer<'a>

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

impl<'a> Ord for ReadBuffer<'a>

source§

fn cmp(&self, other: &ReadBuffer<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a> PartialEq for ReadBuffer<'a>

source§

fn eq(&self, other: &ReadBuffer<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialOrd for ReadBuffer<'a>

source§

fn partial_cmp(&self, other: &ReadBuffer<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> Eq for ReadBuffer<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ReadBuffer<'a>

§

impl<'a> Send for ReadBuffer<'a>

§

impl<'a> Sync for ReadBuffer<'a>

§

impl<'a> Unpin for ReadBuffer<'a>

§

impl<'a> UnwindSafe for ReadBuffer<'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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.