Struct blockbuffers::position::TablePosition
source · pub struct TablePosition(pub usize);
Expand description
TablePosition wrappers a position which points to a table in the buffer.
They start with an soffset_t to a vtable. This is a signed version of uoffset_t, since vtables may be stored anywhere relative to the object. This offset is substracted (not added) from the object start to arrive at the vtable start. This offset is followed by all the fields as aligned scalars (or offsets). Unlike structs, not all fields need to be present. There is no set order and layout.
To be able to access fields regardless of these uncertainties, we go through a vtable of offsets. Vtables are shared between any objects that happen to have the same vtable values.
Tuple Fields
0: usize
Implementations
sourceimpl TablePosition
impl TablePosition
sourcepub fn vtable(self, buf: &[u8]) -> VTablePosition
pub fn vtable(self, buf: &[u8]) -> VTablePosition
Seeks the vtable position.
Examples
use blockbuffers::position::TablePosition;
// | -4 | vtable | 4 |
let buf = &[252, 255, 255, 255, 4u8, 0, 4, 0, 4, 0, 0, 0][..];
let pos1 = TablePosition(0);
assert_eq!(4, pos1.vtable(&buf).0);
let pos2 = TablePosition(8);
assert_eq!(4, pos2.vtable(&buf).0);
sourcepub fn field_position(self, buf: &[u8], pos_in_vtable: usize) -> Option<usize>
pub fn field_position(self, buf: &[u8], pos_in_vtable: usize) -> Option<usize>
Seeks the position for a field.
The field index is specified using pos_in_vtable
, which is the offset inside vtable
bytes. For example, 4 means the first field, 6 is the second.
Examples
use blockbuffers::position::TablePosition;
// [vtable 10| 40| 20| 0| 4] [table 10]
let buf = &[10u8, 0, 40, 0, 20, 0, 0, 0, 4, 0, 10, 0, 0, 0][..];
let pos = TablePosition(10);
assert_eq!(Some(20 + 10), pos.field_position(&buf, 4));
assert_eq!(None, pos.field_position(&buf, 6));
assert_eq!(Some(4 + 10), pos.field_position(&buf, 8));
assert_eq!(None, pos.field_position(&buf, 10));
Trait Implementations
sourceimpl Clone for TablePosition
impl Clone for TablePosition
sourcefn clone(&self) -> TablePosition
fn clone(&self) -> TablePosition
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for TablePosition
impl Debug for TablePosition
sourceimpl PartialEq<TablePosition> for TablePosition
impl PartialEq<TablePosition> for TablePosition
sourcefn eq(&self, other: &TablePosition) -> bool
fn eq(&self, other: &TablePosition) -> bool
sourceimpl PartialOrd<TablePosition> for TablePosition
impl PartialOrd<TablePosition> for TablePosition
sourcefn partial_cmp(&self, other: &TablePosition) -> Option<Ordering>
fn partial_cmp(&self, other: &TablePosition) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more