Struct wasmtime_environ::wasmparser::BinaryReader
source · pub struct BinaryReader<'a> { /* private fields */ }
Expand description
A binary reader of the WebAssembly structures and types.
Implementations§
source§impl<'a> BinaryReader<'a>
impl<'a> BinaryReader<'a>
sourcepub fn new(data: &[u8]) -> BinaryReader<'_>
pub fn new(data: &[u8]) -> BinaryReader<'_>
Constructs BinaryReader
type.
Examples
let fn_body = &vec![0x41, 0x00, 0x10, 0x00, 0x0B];
let mut reader = wasmparser::BinaryReader::new(fn_body);
while !reader.eof() {
let op = reader.read_operator();
println!("{:?}", op)
}
sourcepub fn new_with_offset(data: &[u8], original_offset: usize) -> BinaryReader<'_>
pub fn new_with_offset(data: &[u8], original_offset: usize) -> BinaryReader<'_>
Constructs a BinaryReader
with an explicit starting offset.
sourcepub fn original_position(&self) -> usize
pub fn original_position(&self) -> usize
Gets the original position of the binary reader.
sourcepub fn allow_memarg64(&mut self, allow: bool)
pub fn allow_memarg64(&mut self, allow: bool)
Whether or not to allow 64-bit memory arguments in functions.
This is intended to be true
when support for the memory64
WebAssembly proposal is also enabled.
sourcepub fn range(&self) -> Range<usize> ⓘ
pub fn range(&self) -> Range<usize> ⓘ
Returns a range from the starting offset to the end of the buffer.
sourcepub fn read_val_type(&mut self) -> Result<ValType, BinaryReaderError>
pub fn read_val_type(&mut self) -> Result<ValType, BinaryReaderError>
Reads a core WebAssembly value type from the binary reader.
sourcepub fn current_position(&self) -> usize
pub fn current_position(&self) -> usize
Returns the BinaryReader
’s current position.
sourcepub fn bytes_remaining(&self) -> usize
pub fn bytes_remaining(&self) -> usize
Returns the number of bytes remaining in the BinaryReader
.
sourcepub fn read_bytes(&mut self, size: usize) -> Result<&'a [u8], BinaryReaderError>
pub fn read_bytes(&mut self, size: usize) -> Result<&'a [u8], BinaryReaderError>
Advances the BinaryReader
size
bytes, and returns a slice from the
current position of size
length.
Errors
If size
exceeds the remaining length in BinaryReader
.
sourcepub fn read_u32(&mut self) -> Result<u32, BinaryReaderError>
pub fn read_u32(&mut self) -> Result<u32, BinaryReaderError>
Advances the BinaryReader
four bytes and returns a u32
.
Errors
If BinaryReader
has less than four bytes remaining.
sourcepub fn read_u64(&mut self) -> Result<u64, BinaryReaderError>
pub fn read_u64(&mut self) -> Result<u64, BinaryReaderError>
Advances the BinaryReader
eight bytes and returns a u64
.
Errors
If BinaryReader
has less than eight bytes remaining.
sourcepub fn read_u8(&mut self) -> Result<u8, BinaryReaderError>
pub fn read_u8(&mut self) -> Result<u8, BinaryReaderError>
sourcepub fn read_var_u32(&mut self) -> Result<u32, BinaryReaderError>
pub fn read_var_u32(&mut self) -> Result<u32, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a u32
.
Errors
If BinaryReader
has less than one or up to four bytes remaining, or
the integer is larger than 32 bits.
sourcepub fn read_var_u64(&mut self) -> Result<u64, BinaryReaderError>
pub fn read_var_u64(&mut self) -> Result<u64, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a u64
.
Errors
If BinaryReader
has less than one or up to eight bytes remaining, or
the integer is larger than 64 bits.
sourcepub fn skip_bytes(&mut self, len: usize) -> Result<(), BinaryReaderError>
pub fn skip_bytes(&mut self, len: usize) -> Result<(), BinaryReaderError>
Advances the BinaryReader
len
bytes, skipping the result.
Errors
If BinaryReader
has less than len
bytes remaining.
sourcepub fn skip_string(&mut self) -> Result<(), BinaryReaderError>
pub fn skip_string(&mut self) -> Result<(), BinaryReaderError>
Advances the BinaryReader
past a WebAssembly string. This method does
not perform any utf-8 validation.
Errors
If BinaryReader
has less than four bytes, the string’s length exceeds
the remaining bytes, or the string length
exceeds limits::MAX_WASM_STRING_SIZE
.
sourcepub fn read_var_i32(&mut self) -> Result<i32, BinaryReaderError>
pub fn read_var_i32(&mut self) -> Result<i32, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a i32
.
Errors
If BinaryReader
has less than one or up to four bytes remaining, or
the integer is larger than 32 bits.
sourcepub fn read_var_s33(&mut self) -> Result<i64, BinaryReaderError>
pub fn read_var_s33(&mut self) -> Result<i64, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a signed 33 bit integer, returned as a i64
.
Errors
If BinaryReader
has less than one or up to five bytes remaining, or
the integer is larger than 33 bits.
sourcepub fn read_var_i64(&mut self) -> Result<i64, BinaryReaderError>
pub fn read_var_i64(&mut self) -> Result<i64, BinaryReaderError>
Advances the BinaryReader
up to eight bytes to parse a variable
length integer as a 64 bit integer, returned as a i64
.
Errors
If BinaryReader
has less than one or up to eight bytes remaining, or
the integer is larger than 64 bits.
sourcepub fn read_f32(&mut self) -> Result<Ieee32, BinaryReaderError>
pub fn read_f32(&mut self) -> Result<Ieee32, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a 32 bit floating point integer, returned as Ieee32
.
Errors
If BinaryReader
has less than one or up to four bytes remaining, or
the integer is larger than 32 bits.
sourcepub fn read_f64(&mut self) -> Result<Ieee64, BinaryReaderError>
pub fn read_f64(&mut self) -> Result<Ieee64, BinaryReaderError>
Advances the BinaryReader
up to four bytes to parse a variable
length integer as a 32 bit floating point integer, returned as Ieee32
.
Errors
If BinaryReader
has less than one or up to four bytes remaining, or
the integer is larger than 32 bits.
sourcepub fn read_string(&mut self) -> Result<&'a str, BinaryReaderError>
pub fn read_string(&mut self) -> Result<&'a str, BinaryReaderError>
Reads a WebAssembly string from the module.
Errors
If BinaryReader
has less than up to four bytes remaining, the string’s
length exceeds the remaining bytes, the string’s length exceeds
limits::MAX_WASM_STRING_SIZE
, or the string contains invalid utf-8.
sourcepub fn visit_operator<T>(
&mut self,
visitor: &mut T
) -> Result<<T as VisitOperator<'a>>::Output, BinaryReaderError>where
T: VisitOperator<'a>,
pub fn visit_operator<T>( &mut self, visitor: &mut T ) -> Result<<T as VisitOperator<'a>>::Output, BinaryReaderError>where T: VisitOperator<'a>,
Reads the next available Operator
and calls the respective visit method.
Errors
If BinaryReader
has less bytes remaining than required to parse
the Operator
.
sourcepub fn read_operator(&mut self) -> Result<Operator<'a>, BinaryReaderError>
pub fn read_operator(&mut self) -> Result<Operator<'a>, BinaryReaderError>
Reads the next available Operator
.
Errors
If BinaryReader
has less bytes remaining than required to parse
the Operator
.
Trait Implementations§
source§impl<'a> Clone for BinaryReader<'a>
impl<'a> Clone for BinaryReader<'a>
source§fn clone(&self) -> BinaryReader<'a>
fn clone(&self) -> BinaryReader<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more