pub struct RawView<'a> {
pub buf: &'a [u8],
pub t_pos: usize,
pub v_pos: usize,
}Expand description
Low-level, type-erased view of a single table object.
Holds the three positions needed to navigate any table:
buf— the entire buffer the table lives in.t_pos— absolute position of the table object (where the vtable jump is).v_pos— absolute position of the vtable (computed from the jump).
All generated XxxView structs wrap a RawView as their inner field and
delegate field lookups to its methods.
§Vtable navigation
t_pos → [vtable_jump: i32][field_0_data]...[field_n_data]
v_pos = t_pos - vtable_jump (jump is negative when vtable is before table)
v_pos → [vtable_size: u16][object_size: u16]
[voff_0: u16][voff_1: u16]...[voff_n: u16]voff(i) == 0 means field i is absent (default value); non-zero means
the field data starts at t_pos + voff(i).
Fields§
§buf: &'a [u8]§t_pos: usizeAbsolute position of the table object’s first byte (the vtable jump).
v_pos: usizeAbsolute position of the vtable’s first byte.
Implementations§
Source§impl<'a> RawView<'a>
impl<'a> RawView<'a>
pub const EMPTY: RawView<'static>
Sourcepub fn new(buf: &'a [u8], table_pos: usize) -> RawView<'a>
pub fn new(buf: &'a [u8], table_pos: usize) -> RawView<'a>
Construct a RawView given the absolute position of the table object.
The vtable position is computed by reading the signed 32-bit jump stored
at table_pos: v_pos = table_pos - jump.
Sourcepub fn from_slot(buf: &'a [u8], slot: usize) -> RawView<'a>
pub fn from_slot(buf: &'a [u8], slot: usize) -> RawView<'a>
Construct from a slot (distance from the end of buf).
Converts slot → absolute position via buf.len() - slot, then
delegates to new.
Sourcepub fn voff(&self, field_idx: usize) -> usize
pub fn voff(&self, field_idx: usize) -> usize
Read the vtable offset for field field_idx.
The vtable stores one u16 per field starting at v_pos + 4 (after
the 2-byte vtable size and 2-byte object size). A value of 0 means
the field is absent.
Sourcepub fn is_present(&self, field_idx: usize) -> bool
pub fn is_present(&self, field_idx: usize) -> bool
Return true if field field_idx is present (vtable offset != 0).
Sourcepub fn indirect_idx(&self, field_idx: usize) -> usize
pub fn indirect_idx(&self, field_idx: usize) -> usize
Follow an Offset-mode field: read the forward offset at
t_pos + voff(field_idx) and return the absolute position of the
pointed-to data.