pub enum MemoryPointerLength {
X32b,
X64b,
}
Expand description
An enum deciding the amount of bytes required to point to a location in memory. If the extra memory is not needed, using a smaller MemoryPointerLength can be file size optimization.
§Pointing to the max memory index
X32b => [0xFF, 0xFF, 0xFF, 0xFF]
X64b => [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
Variants§
Implementations§
Source§impl MemoryPointerLength
impl MemoryPointerLength
Sourcepub fn extract(&self, index: usize, pool: &[u8]) -> usize
pub fn extract(&self, index: usize, pool: &[u8]) -> usize
Extract a usize from the memory pool at the given start index, until this MemoryPointerLength’s span is satisfied.
See Self::get_span(), [Self::to_usize(&[u8])].
Sourcepub fn to_usize(&self, input: &[u8]) -> usize
pub fn to_usize(&self, input: &[u8]) -> usize
Convert the given input to a usize.
Panics if this length cannot be fit into a usize.
Sourcepub fn fit(&self, mem_ptr_index: usize) -> Vec<u8> ⓘ
pub fn fit(&self, mem_ptr_index: usize) -> Vec<u8> ⓘ
Convert a memory pointer index to its little-endian byte representation.
Sourcepub fn get_span(&self) -> usize
pub fn get_span(&self) -> usize
Get the byte size of this memory size.
X32b => 4 bytes, X64b => 8 bytes.
Sourcepub fn get_byte_identifier(&self) -> u8
pub fn get_byte_identifier(&self) -> u8
Get the this memory pointer length’s byte identifier. This will be placed into the bytecode header.
See [options::header_format_doc] for a full guide regarding the ivm bytecode format.
Sourcepub fn from_byte_identifier(byte: u8) -> Option<Self>
pub fn from_byte_identifier(byte: u8) -> Option<Self>
Match the memory pointer length from the given byte.