Cursor

Struct Cursor 

Source
pub struct Cursor {
    pub offset: usize,
    pub size: usize,
    pub data_source: Rc<RefCell<DataSource>>,
}
Expand description

The Cursor represents a slice or view of data without actually being loaded into memory. It is a slice of data source with range [offset, offset + size)

Fields§

§offset: usize§size: usize§data_source: Rc<RefCell<DataSource>>

Implementations§

Source§

impl Cursor

Source

pub fn new(size: usize, reader: Box<dyn Read>) -> Self

Create a cursor from reader and its corresponding size

Source

pub fn read_at(&self, buf: &mut [u8]) -> Result<usize, Error>

Read from a cursor into buf and returns actually read size.

Source

pub fn add_offset(&mut self, offset: usize) -> Result<(), Error>

Move offset forward and shrink a cursor from beginning.

Source

pub fn sub_size(&mut self, shrink_size: usize) -> Result<(), Error>

Shrink a cursor from end.

Source

pub fn unpack_number(&self) -> Result<usize, Error>

Read the first 4 bytes and unpack them into a u32 in little endian format.

Source

pub fn verify_fixed_size(&self, size: usize) -> Result<(), Error>

Verify that a cursor has size bytes.

Source

pub fn verify_table( &self, expected_field_count: usize, compatible: bool, ) -> Result<(), Error>

Verify that a cursor is a valid molecule table with expected_field_count fields. if compatible is true, actual fields count can be larger than expected_field_count.

Source

pub fn verify_dynvec(&self) -> Result<(), Error>

Verify that a cursor is a valid molecule dynvec

Source

pub fn verify_fixvec(&self, item_size: usize) -> Result<(), Error>

Verify that a cursor is a valid molecule fixvec

Source

pub fn option_is_none(&self) -> bool

Verify that a cursor is with zero size

Source

pub fn fixvec_length(&self) -> Result<usize, Error>

Assuming a cursor is a fixvec, return the length of the fixvec.

Source

pub fn dynvec_length(&self) -> Result<usize, Error>

Assuming a cursor is a dynvec, return the length of the dynvec.

Source

pub fn get_item_count(&self) -> Result<usize, Error>

Assuming a cursor is fixvec, dynvec, or table, return the item count.

See molecule memory layout

Source

pub fn table_actual_field_count(&self) -> Result<usize, Error>

Same to dynvec_length

Source

pub fn table_has_extra_fields(&self, field_count: usize) -> Result<bool, Error>

Verify a table has extra field larger than field_count

Source

pub fn slice_by_offset( &self, offset: usize, size: usize, ) -> Result<Cursor, Error>

Create a new cursor by adding an offset and setting the size to that of the original cursor.

Source

pub fn slice_by_start(&self, delta: usize) -> Result<Cursor, Error>

Create a new cursor by adding an offset and shrinking the size to that of the original cursor.

Source

pub fn fixvec_slice_by_index( &self, item_size: usize, item_index: usize, ) -> Result<Cursor, Error>

Assuming a cursor is fixvec with item size item_size, return an item with index item_index

Source

pub fn dynvec_slice_by_index(&self, item_index: usize) -> Result<Cursor, Error>

Assuming a cursor is dynvec, return an item with index item_index

Source

pub fn table_slice_by_index(&self, field_index: usize) -> Result<Cursor, Error>

Assuming a cursor is table, return a field with index field_index

Source

pub fn fixvec_slice_raw_bytes(&self) -> Result<Cursor, Error>

Assuming a cursor is fixvec, return raw data without header.

Source

pub fn convert_to_array(&self) -> Result<Cursor, Error>

helper function for generated code

Source

pub fn convert_to_rawbytes(&self) -> Result<Cursor, Error>

same to fixvec_slice_raw_bytes

Source

pub fn union_unpack(&self) -> Result<Union, Error>

Assuming a cursor is union. Return a union.

Trait Implementations§

Source§

impl Clone for Cursor

Source§

fn clone(&self) -> Cursor

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
Source§

impl<const N: usize> From<[u8; N]> for Cursor

Source§

fn from(mem: [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Cursor

Source§

fn from(mem: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> TryFrom<Cursor> for [u8; N]

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for Vec<u8>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for i16

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for i32

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for i64

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for i8

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for u16

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for u32

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for u64

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Cursor> for u8

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cur: Cursor) -> Result<Self, Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Cursor

§

impl !RefUnwindSafe for Cursor

§

impl !Send for Cursor

§

impl !Sync for Cursor

§

impl Unpin for Cursor

§

impl !UnwindSafe for Cursor

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 = 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.