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

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);

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.