Skip to main content

Reader

Struct Reader 

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

Bounds-checked read cursor over a Bytes buffer.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn new(buf: &'a Bytes) -> Self

Creates a reader at the start of buf.

Source

pub fn remaining(&self) -> usize

Number of unread bytes.

Source

pub fn position(&self) -> usize

Current offset from the start of the buffer.

Source

pub fn rest_slice(&self) -> &'a [u8] ⓘ

The unread bytes, without consuming them.

Source

pub fn finish(&self) -> DecodeResult<()>

Fails with DecodeError::TrailingBytes unless the input is fully consumed.

Source

pub fn take(&mut self, n: usize) -> DecodeResult<&'a [u8]>

Consumes n bytes and returns them as a borrowed slice.

Source

pub fn skip(&mut self, n: usize) -> DecodeResult<()>

Advances past n bytes.

Source

pub fn read_bytes(&mut self, n: usize) -> DecodeResult<Bytes>

Consumes n bytes and returns them as a zero-copy Bytes slice.

Source

pub fn bytes_since(&self, start: usize) -> Bytes

Zero-copy slice of everything read since offset start (from Reader::position).

Source

pub fn read_rest(&mut self) -> Bytes

Consumes and returns everything that is left (protodef restBuffer).

Source

pub fn peek_u8(&self) -> DecodeResult<u8>

Returns the next byte without consuming it.

Source

pub fn read_u8(&mut self) -> DecodeResult<u8>

Reads an unsigned byte.

Source

pub fn read_i8(&mut self) -> DecodeResult<i8>

Reads a signed byte.

Source

pub fn read_bool(&mut self) -> DecodeResult<bool>

Reads a boolean. Like vanilla, any non-zero byte is true.

Source

pub fn read_u16(&mut self) -> DecodeResult<u16>

Reads a big-endian u16.

Source

pub fn read_i16(&mut self) -> DecodeResult<i16>

Reads a big-endian i16.

Source

pub fn read_i32(&mut self) -> DecodeResult<i32>

Reads a big-endian i32.

Source

pub fn read_i64(&mut self) -> DecodeResult<i64>

Reads a big-endian i64.

Source

pub fn read_u64(&mut self) -> DecodeResult<u64>

Reads a big-endian u64.

Source

pub fn read_f32(&mut self) -> DecodeResult<f32>

Reads a big-endian IEEE-754 f32.

Source

pub fn read_f64(&mut self) -> DecodeResult<f64>

Reads a big-endian IEEE-754 f64.

Source

pub fn read_uuid(&mut self) -> DecodeResult<Uuid>

Reads a UUID (two big-endian 64-bit halves).

Source

pub fn read_varint(&mut self) -> DecodeResult<i32>

Reads a VarInt (at most 5 bytes).

Like vanilla, the unused high bits of a 5th byte are ignored; a 6th byte is an error (DecodeError::VarIntTooLong).

Source

pub fn read_varlong(&mut self) -> DecodeResult<i64>

Reads a VarLong (at most 10 bytes).

Source

pub fn read_len_varint(&mut self, limit: usize) -> DecodeResult<usize>

Reads a VarInt length prefix and checks it is non-negative and at most limit.

Source

pub fn check_count( &self, count: i64, min_elem_size: usize, ) -> DecodeResult<usize>

Reads an array count of the given prefix width and validates it.

min_elem_size is the smallest number of bytes one element can occupy; when it is non-zero the count is bounded by the remaining input, so a hostile count can never cause a large allocation or a long loop.

Source

pub fn read_byte_array(&mut self) -> DecodeResult<Bytes>

Reads a VarInt-prefixed byte array as a zero-copy slice.

Source

pub fn read_string(&mut self) -> DecodeResult<ByteString>

Reads a VarInt-prefixed UTF-8 string as a zero-copy ByteString.

Trait Implementations§

Source§

impl<'a> Clone for Reader<'a>

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<'a> Debug for Reader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Reader<'a>

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'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> 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> Same for T

Source§

type Output = T

Should always be Self
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.