Enum wasmparser::Payload[][src]

pub enum Payload<'a> {
Show variants Version { num: u32, range: Range, }, TypeSection(TypeSectionReader<'a>), ImportSection(ImportSectionReader<'a>), AliasSection(AliasSectionReader<'a>), InstanceSection(InstanceSectionReader<'a>), FunctionSection(FunctionSectionReader<'a>), TableSection(TableSectionReader<'a>), MemorySection(MemorySectionReader<'a>), EventSection(EventSectionReader<'a>), GlobalSection(GlobalSectionReader<'a>), ExportSection(ExportSectionReader<'a>), StartSection { func: u32, range: Range, }, ElementSection(ElementSectionReader<'a>), DataCountSection { count: u32, range: Range, }, DataSection(DataSectionReader<'a>), CustomSection { name: &'a str, data_offset: usize, data: &'a [u8], range: Range, }, CodeSectionStart { count: u32, range: Range, size: u32, }, CodeSectionEntry(FunctionBody<'a>), ModuleSectionStart { count: u32, range: Range, size: u32, }, ModuleSectionEntry { parser: Parser, range: Range, }, UnknownSection { id: u8, contents: &'a [u8], range: Range, }, End,
}
Expand description

Values that can be parsed from a wasm module.

This enumeration is all possible chunks of pieces that can be parsed by a Parser from a binary WebAssembly module. Note that for many sections the entire section is parsed all at once, whereas other functions, like the code section, are parsed incrementally. This is a distinction where some sections, like the type section, are required to be fully resident in memory (fully downloaded) before proceeding. Other sections, like the code section, can be processed in a streaming fashion where each function is extracted individually so it can possibly be shipped to another thread while you wait for more functions to get downloaded.

Note that payloads, when returned, do not indicate that the wasm module is valid. For example when you receive a Payload::TypeSection the type section itself has not yet actually been parsed. The reader returned will be able to parse it, but you’ll have to actually iterate the reader to do the full parse. Each payload returned is intended to be a window into the original data passed to Parser::parse which can be further processed if necessary.

Variants

Version
Expand description

Indicates the header of a WebAssembly binary.

This header also indicates the version number that was parsed, which is currently always 1.

Show fields

Fields of Version

num: u32
Expand description

The version number found

range: Range
Expand description

The range of bytes that were parsed to consume the header of the module. Note that this range is relative to the start of the byte stream.

TypeSection(TypeSectionReader<'a>)
Expand description

A type section was received, and the provided reader can be used to parse the contents of the type section.

ImportSection(ImportSectionReader<'a>)
Expand description

A import section was received, and the provided reader can be used to parse the contents of the import section.

AliasSection(AliasSectionReader<'a>)
Expand description

An alias section was received, and the provided reader can be used to parse the contents of the alias section.

InstanceSection(InstanceSectionReader<'a>)
Expand description

An instance section was received, and the provided reader can be used to parse the contents of the instance section.

FunctionSection(FunctionSectionReader<'a>)
Expand description

A function section was received, and the provided reader can be used to parse the contents of the function section.

TableSection(TableSectionReader<'a>)
Expand description

A table section was received, and the provided reader can be used to parse the contents of the table section.

MemorySection(MemorySectionReader<'a>)
Expand description

A memory section was received, and the provided reader can be used to parse the contents of the memory section.

EventSection(EventSectionReader<'a>)
Expand description

An event section was received, and the provided reader can be used to parse the contents of the event section.

GlobalSection(GlobalSectionReader<'a>)
Expand description

A global section was received, and the provided reader can be used to parse the contents of the global section.

ExportSection(ExportSectionReader<'a>)
Expand description

An export section was received, and the provided reader can be used to parse the contents of the export section.

StartSection
Expand description

A start section was received, and the u32 here is the index of the start function.

Show fields

Fields of StartSection

func: u32
Expand description

The start function index

range: Range
Expand description

The range of bytes that specify the func field, specified in offsets relative to the start of the byte stream.

ElementSection(ElementSectionReader<'a>)
Expand description

An element section was received, and the provided reader can be used to parse the contents of the element section.

DataCountSection
Expand description

A data count section was received, and the u32 here is the contents of the data count section.

Show fields

Fields of DataCountSection

count: u32
Expand description

The number of data segments.

range: Range
Expand description

The range of bytes that specify the count field, specified in offsets relative to the start of the byte stream.

DataSection(DataSectionReader<'a>)
Expand description

A data section was received, and the provided reader can be used to parse the contents of the data section.

CustomSection
Expand description

A custom section was found.

Show fields

Fields of CustomSection

name: &'a str
Expand description

The name of the custom section.

data_offset: usize
Expand description

The offset, relative to the start of the original module, that the data payload for this custom section starts at.

data: &'a [u8]
Expand description

The actual contents of the custom section.

range: Range
Expand description

The range of bytes that specify this whole custom section (including both the name of this custom section and its data) specified in offsets relative to the start of the byte stream.

CodeSectionStart
Expand description

Indicator of the start of the code section.

This entry is returned whenever the code section starts. The count field indicates how many entries are in this code section. After receiving this start marker you’re guaranteed that the next count items will be either CodeSectionEntry or an error will be returned.

This, unlike other sections, is intended to be used for streaming the contents of the code section. The code section is not required to be fully resident in memory when we parse it. Instead a Parser is capable of parsing piece-by-piece of a code section.

Show fields

Fields of CodeSectionStart

count: u32
Expand description

The number of functions in this section.

range: Range
Expand description

The range of bytes that represent this section, specified in offsets relative to the start of the byte stream.

size: u32
Expand description

The size, in bytes, of the remaining contents of this section.

This can be used in combination with Parser::skip_section where the caller will know how many bytes to skip before feeding bytes into Parser again.

CodeSectionEntry(FunctionBody<'a>)
Expand description

An entry of the code section, a function, was parsed.

This entry indicates that a function was successfully received from the code section, and the payload here is the window into the original input where the function resides. Note that the function itself has not been parsed, it’s only been outlined. You’ll need to process the FunctionBody provided to test whether it parses and/or is valid.

ModuleSectionStart
Expand description

Indicator of the start of the module code section.

This behaves the same as the CodeSectionStart payload being returned. You’re guaranteed the next count items will be of type ModuleSectionEntry.

Show fields

Fields of ModuleSectionStart

count: u32
Expand description

The number of inline modules in this section.

range: Range
Expand description

The range of bytes that represent this section, specified in offsets relative to the start of the byte stream.

size: u32
Expand description

The size, in bytes, of the remaining contents of this section.

ModuleSectionEntry
Expand description

An entry of the module code section, a module, was parsed.

This variant is special in that it returns a sub-Parser. Upon receiving a ModuleSectionEntry it is expected that the returned Parser will be used instead of the parent Parser until the parse has finished. You’ll need to feed data into the Parser returned until it returns Payload::End. After that you’ll switch back to the parent parser to resume parsing the rest of the module code section.

Note that binaries will not be parsed correctly if you feed the data for a nested module into the parent Parser.

Show fields

Fields of ModuleSectionEntry

parser: Parser
Expand description

The parser to use to parse the contents of the nested submodule. This parser should be used until it reports End.

range: Range
Expand description

The range of bytes, relative to the start of the input stream, of the bytes containing this submodule.

UnknownSection
Expand description

An unknown section was found.

This variant is returned for all unknown sections in a wasm file. This likely wants to be interpreted as an error by consumers of the parser, but this can also be used to parse sections unknown to wasmparser at this time.

Show fields

Fields of UnknownSection

id: u8
Expand description

The 8-bit identifier for this section.

contents: &'a [u8]
Expand description

The contents of this section.

range: Range
Expand description

The range of bytes, relative to the start of the original data stream, that the contents of this section reside in.

End
Expand description

The end of the WebAssembly module was reached.

Trait Implementations

impl Debug for Payload<'_>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'a> RefUnwindSafe for Payload<'a>

impl<'a> Send for Payload<'a>

impl<'a> Sync for Payload<'a>

impl<'a> Unpin for Payload<'a>

impl<'a> UnwindSafe for Payload<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.