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
impl Cursor
Sourcepub fn new(size: usize, reader: Box<dyn Read>) -> Self
pub fn new(size: usize, reader: Box<dyn Read>) -> Self
Create a cursor from reader and its corresponding size
Sourcepub fn read_at(&self, buf: &mut [u8]) -> Result<usize, Error>
pub fn read_at(&self, buf: &mut [u8]) -> Result<usize, Error>
Read from a cursor into buf and returns actually read size.
Sourcepub fn add_offset(&mut self, offset: usize) -> Result<(), Error>
pub fn add_offset(&mut self, offset: usize) -> Result<(), Error>
Move offset forward and shrink a cursor from beginning.
Sourcepub fn unpack_number(&self) -> Result<usize, Error>
pub fn unpack_number(&self) -> Result<usize, Error>
Read the first 4 bytes and unpack them into a u32 in little endian format.
Sourcepub fn verify_fixed_size(&self, size: usize) -> Result<(), Error>
pub fn verify_fixed_size(&self, size: usize) -> Result<(), Error>
Verify that a cursor has size bytes.
Sourcepub fn verify_table(
&self,
expected_field_count: usize,
compatible: bool,
) -> Result<(), Error>
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.
Sourcepub fn verify_dynvec(&self) -> Result<(), Error>
pub fn verify_dynvec(&self) -> Result<(), Error>
Verify that a cursor is a valid molecule dynvec
Sourcepub fn verify_fixvec(&self, item_size: usize) -> Result<(), Error>
pub fn verify_fixvec(&self, item_size: usize) -> Result<(), Error>
Verify that a cursor is a valid molecule fixvec
Sourcepub fn option_is_none(&self) -> bool
pub fn option_is_none(&self) -> bool
Verify that a cursor is with zero size
Sourcepub fn fixvec_length(&self) -> Result<usize, Error>
pub fn fixvec_length(&self) -> Result<usize, Error>
Assuming a cursor is a fixvec, return the length of the fixvec.
Sourcepub fn dynvec_length(&self) -> Result<usize, Error>
pub fn dynvec_length(&self) -> Result<usize, Error>
Assuming a cursor is a dynvec, return the length of the dynvec.
Sourcepub fn get_item_count(&self) -> Result<usize, Error>
pub fn get_item_count(&self) -> Result<usize, Error>
Assuming a cursor is fixvec, dynvec, or table, return the item count.
Sourcepub fn table_actual_field_count(&self) -> Result<usize, Error>
pub fn table_actual_field_count(&self) -> Result<usize, Error>
Same to dynvec_length
Sourcepub fn table_has_extra_fields(&self, field_count: usize) -> Result<bool, Error>
pub fn table_has_extra_fields(&self, field_count: usize) -> Result<bool, Error>
Verify a table has extra field larger than field_count
Sourcepub fn slice_by_offset(
&self,
offset: usize,
size: usize,
) -> Result<Cursor, Error>
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.
Sourcepub fn slice_by_start(&self, delta: usize) -> Result<Cursor, Error>
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.
Sourcepub fn fixvec_slice_by_index(
&self,
item_size: usize,
item_index: usize,
) -> Result<Cursor, Error>
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
Sourcepub fn dynvec_slice_by_index(&self, item_index: usize) -> Result<Cursor, Error>
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
Sourcepub fn table_slice_by_index(&self, field_index: usize) -> Result<Cursor, Error>
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
Sourcepub fn fixvec_slice_raw_bytes(&self) -> Result<Cursor, Error>
pub fn fixvec_slice_raw_bytes(&self) -> Result<Cursor, Error>
Assuming a cursor is fixvec, return raw data without header.
Sourcepub fn convert_to_array(&self) -> Result<Cursor, Error>
pub fn convert_to_array(&self) -> Result<Cursor, Error>
helper function for generated code
Sourcepub fn convert_to_rawbytes(&self) -> Result<Cursor, Error>
pub fn convert_to_rawbytes(&self) -> Result<Cursor, Error>
same to fixvec_slice_raw_bytes
Sourcepub fn union_unpack(&self) -> Result<Union, Error>
pub fn union_unpack(&self) -> Result<Union, Error>
Assuming a cursor is union. Return a union.