Skip to main content

Cursor

Struct Cursor 

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

A position within a borrowed buffer.

base is the offset of buf[0] within the whole file, so a cursor over a sliced-out chunk payload still reports file-absolute offsets in diagnostics.

Implementations§

Source§

impl<'a> Cursor<'a>

Source

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

A cursor over a whole file.

Source

pub const fn with_base(buf: &'a [u8], base: u32) -> Self

A cursor over a slice that begins base bytes into the file.

Source

pub const fn pos(&self) -> usize

Bytes consumed so far.

Source

pub const fn offset(&self) -> u32

File-absolute offset of the current position.

Source

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

The whole buffer, consumed part included.

Needed to slice out a span the cursor has already walked past - the event-command codec scans its parameters to find their extent, then hands back that exact subslice.

Source

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

The not-yet-consumed bytes.

Source

pub const fn remaining_len(&self) -> usize

How many bytes are left.

Source

pub const fn is_empty(&self) -> bool

Whether the cursor is exhausted.

Source

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

Consume and return the next n bytes, or None if fewer remain.

Source

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

Consume and return everything left.

Source

pub fn skip(&mut self, n: usize)

Advance by at most n bytes, saturating at the end.

Source

pub fn varint(&mut self) -> Option<Varint>

Consume a compressed integer.

Advances past the whole encoding even when it overflows the 5-byte cap, matching LcfReader::ReadInt. Returns None at end of input.

Source

pub fn varint_lenient( &mut self, ctx: &mut Ctx<'_>, struct_name: &'static str, chunk_id: u32, ) -> i32

Consume a compressed integer, substituting 0 on malformed or truncated input.

This is the lenient form the generated readers use: liblcf yields 0 in both cases, and real files rely on it, so the value is reported alongside a diagnostic rather than an error.

Source

pub fn varint64(&mut self) -> Option<Varint64>

Consume a 64-bit compressed integer.

Source

pub fn u8(&mut self) -> Option<u8>

Consume one raw byte.

Source

pub fn i16_le(&mut self) -> Option<i16>

Consume a little-endian i16.

Source

pub fn u32_le(&mut self) -> Option<u32>

Consume a little-endian u32.

Source

pub fn i32_le(&mut self) -> Option<i32>

Consume a little-endian i32.

Source

pub fn f64_le(&mut self) -> Option<f64>

Consume a little-endian f64.

Source

pub fn peek(&self) -> Option<u8>

Peek at the next byte without consuming it.

Source

pub fn lstring(&mut self) -> Option<&'a [u8]>

Read a length-prefixed byte string: a compressed integer length followed by that many raw bytes.

The bytes are returned verbatim. This crate never transcodes: LCF carries no encoding marker of any kind, so guessing would be exactly that. See the crate docs.

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'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 Cursor<'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 Cursor<'a>

§

impl<'a> RefUnwindSafe for Cursor<'a>

§

impl<'a> Send for Cursor<'a>

§

impl<'a> Sync for Cursor<'a>

§

impl<'a> Unpin for Cursor<'a>

§

impl<'a> UnsafeUnpin for Cursor<'a>

§

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