Skip to main content

Cursor

Struct Cursor 

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

A cursor over a byte slice for sequential reading with endian-aware helpers.

All HDF5 file parsing goes through this type. It wraps a &[u8] and tracks the current position. Methods advance the position on success.

Implementations§

Source§

impl<'a> Cursor<'a>

Source

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

Create a new cursor at position 0.

Source

pub fn position(&self) -> u64

Current byte position.

Source

pub fn set_position(&mut self, pos: u64)

Set the position.

Source

pub fn len(&self) -> u64

Total length of the underlying data.

Source

pub fn is_empty(&self) -> bool

Returns true if the underlying data is empty.

Source

pub fn remaining(&self) -> u64

Remaining bytes from current position.

Source

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

Get the underlying data slice.

Source

pub fn slice_from(&self, offset: u64) -> Result<&'a [u8]>

Get a slice starting from an absolute offset.

Source

pub fn at_offset(&self, offset: u64) -> Result<Cursor<'a>>

Create a new cursor at a given absolute offset.

Source

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

Read exactly n bytes and advance.

Source

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

Peek at the next n bytes without advancing.

Source

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

Skip n bytes.

Source

pub fn align(&mut self, alignment: usize) -> Result<()>

Align position to alignment boundary.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn read_i16_le(&mut self) -> Result<i16>

Source

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

Source

pub fn read_i64_le(&mut self) -> Result<i64>

Source

pub fn read_f32_le(&mut self) -> Result<f32>

Source

pub fn read_f64_le(&mut self) -> Result<f64>

Source

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

Source

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

Source

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

Source

pub fn read_u16(&mut self, order: ByteOrder) -> Result<u16>

Source

pub fn read_u32(&mut self, order: ByteOrder) -> Result<u32>

Source

pub fn read_u64(&mut self, order: ByteOrder) -> Result<u64>

Source

pub fn read_offset(&mut self, size: u8) -> Result<u64>

Read an offset (address) of size bytes (little-endian). HDF5 uses 2/4/8-byte offsets depending on superblock configuration.

Source

pub fn read_length(&mut self, size: u8) -> Result<u64>

Read a length of size bytes (little-endian).

Source

pub fn read_uvar(&mut self, size: usize) -> Result<u64>

Read a variable-size unsigned integer of 1..=8 bytes (little-endian).

Source

pub fn is_undefined_offset(val: u64, offset_size: u8) -> bool

Check if an offset value represents the “undefined” address.

Source

pub fn read_null_terminated_string(&mut self) -> Result<String>

Read a null-terminated UTF-8 string.

Source

pub fn read_fixed_string(&mut self, len: usize) -> Result<String>

Read a fixed-length string, trimming null padding.

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'a>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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.