Skip to main content

ByteReader

Struct ByteReader 

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

Byte-aligned, forward-scanning cursor over a &[u8] buffer.

ByteReader is used to walk the outer demo command stream — the sequence of (cmd, tick, size, body) tuples that make up a .dem file after the 16-byte file header. All multi-byte integers are little-endian, and variable-length integers use protobuf-style LEB128 encoding.

For bit-level access inside decompressed packet payloads, see BitReader.

Implementations§

Source§

impl<'a> ByteReader<'a>

Source

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

Create a new reader starting at the beginning of data.

Source

pub fn position(&self) -> usize

Current byte offset from the start of the buffer.

Source

pub fn remaining(&self) -> usize

Number of bytes between the cursor and the end of the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true when the cursor is at or past the end of the buffer.

Source

pub fn seek(&mut self, position: usize) -> Result<()>

Move the cursor to an absolute byte position.

Returns Error::Overflow if position exceeds the buffer length.

Source

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

Read a single byte and advance the cursor.

Source

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

Read a little-endian u16 and advance the cursor by 2 bytes.

Source

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

Read a little-endian u32 and advance the cursor by 4 bytes.

Source

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

Read a little-endian i32 and advance the cursor by 4 bytes.

Source

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

Borrow n bytes starting at the cursor and advance past them.

Source

pub fn read_uvarint32(&mut self) -> Result<u32>

Read a protobuf-style unsigned varint (up to 32 bits / 5 bytes).

Source

pub fn read_uvarint64(&mut self) -> Result<u64>

Read a protobuf-style unsigned varint (up to 64 bits / 10 bytes).

Source

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

Advance the cursor by n bytes without reading.

Source

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

Returns the full underlying data slice (independent of cursor position).

Auto Trait Implementations§

§

impl<'a> Freeze for ByteReader<'a>

§

impl<'a> RefUnwindSafe for ByteReader<'a>

§

impl<'a> Send for ByteReader<'a>

§

impl<'a> Sync for ByteReader<'a>

§

impl<'a> Unpin for ByteReader<'a>

§

impl<'a> UnsafeUnpin for ByteReader<'a>

§

impl<'a> UnwindSafe for ByteReader<'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 = 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.