Struct blockbuffers::position::VTablePosition
source · pub struct VTablePosition(pub usize);
Expand description
VTablePosition wrappers a position which points to a vtable in the buffer.
The elements of a vtable are all of type voffset_t, which is a uint16_t. The first element is the size of the vtable in bytes, including the size element. The second one is the size of the object, in bytes (including the vtable offset). This size could be used for streaming, to know how many bytes to read to be able to access all inline fields of the object. The remaining elements are the N offsets, where N is the amount of fields declared in the schema when the code that constructed this buffer was compiled (thus, the size of the table is N + 2).
Tuple Fields
0: usize
Implementations
sourceimpl VTablePosition
impl VTablePosition
sourcepub fn vtable_bytes_len(self, buf: &[u8]) -> usize
pub fn vtable_bytes_len(self, buf: &[u8]) -> usize
Reads the size of the vtable in bytes.
Example
use blockbuffers::position::VTablePosition;
let buf = &[4u8, 0, 6, 0][..];
let pos = VTablePosition(0);
assert_eq!(4, pos.vtable_bytes_len(&buf));
sourcepub fn table_bytes_len(self, buf: &[u8]) -> usize
pub fn table_bytes_len(self, buf: &[u8]) -> usize
Reads the size of the table in bytes.
Examples
use blockbuffers::position::VTablePosition;
let buf = &[4u8, 0, 6, 0][..];
let pos = VTablePosition(0);
assert_eq!(6, pos.table_bytes_len(&buf));
sourcepub fn field_offset(self, buf: &[u8], voffset_offset: usize) -> VOffset
pub fn field_offset(self, buf: &[u8], voffset_offset: usize) -> VOffset
Reads the field offset.
Parameter voffset_offset
is the position of the field voffset inside vtable bytes. For
example 4 means the offset for the first field in the schema.
Offset 0 indicates the field is absent in the table bytes.
Examples
use blockbuffers::position::VTablePosition;
// Field offsets are 20, 0, 4
let buf = &[10u8, 0, 40, 0, 20, 0, 0, 0, 4, 0][..];
let pos = VTablePosition(0);
assert_eq!(20, pos.field_offset(&buf, 4));
assert_eq!(0, pos.field_offset(&buf, 6));
assert_eq!(4, pos.field_offset(&buf, 8));
// Returns 0 when voffset_offset is out of range.
assert_eq!(0, pos.field_offset(&buf, 10));
Trait Implementations
sourceimpl Clone for VTablePosition
impl Clone for VTablePosition
sourcefn clone(&self) -> VTablePosition
fn clone(&self) -> VTablePosition
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for VTablePosition
impl Debug for VTablePosition
sourceimpl PartialEq<VTablePosition> for VTablePosition
impl PartialEq<VTablePosition> for VTablePosition
sourcefn eq(&self, other: &VTablePosition) -> bool
fn eq(&self, other: &VTablePosition) -> bool
sourceimpl PartialOrd<VTablePosition> for VTablePosition
impl PartialOrd<VTablePosition> for VTablePosition
sourcefn partial_cmp(&self, other: &VTablePosition) -> Option<Ordering>
fn partial_cmp(&self, other: &VTablePosition) -> 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