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>
impl<'a> Cursor<'a>
Sourcepub const fn with_base(buf: &'a [u8], base: u32) -> Self
pub const fn with_base(buf: &'a [u8], base: u32) -> Self
A cursor over a slice that begins base bytes into the file.
Sourcepub const fn buf(&self) -> &'a [u8] ⓘ
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.
Sourcepub const fn remaining_len(&self) -> usize
pub const fn remaining_len(&self) -> usize
How many bytes are left.
Sourcepub fn take(&mut self, n: usize) -> Option<&'a [u8]>
pub fn take(&mut self, n: usize) -> Option<&'a [u8]>
Consume and return the next n bytes, or None if fewer remain.
Sourcepub fn varint(&mut self) -> Option<Varint>
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.
Sourcepub fn varint_lenient(
&mut self,
ctx: &mut Ctx<'_>,
struct_name: &'static str,
chunk_id: u32,
) -> i32
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.
Sourcepub fn lstring(&mut self) -> Option<&'a [u8]>
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.