[][src]Enum wasmparser::Payload

pub enum Payload<'a> {
    Version {
        num: u32,
        range: Range,
    },
    TypeSection(TypeSectionReader<'a>),
    ImportSection(ImportSectionReader<'a>),
    AliasSection(AliasSectionReader<'a>),
    InstanceSection(InstanceSectionReader<'a>),
    ModuleSection(ModuleSectionReader<'a>),
    FunctionSection(FunctionSectionReader<'a>),
    TableSection(TableSectionReader<'a>),
    MemorySection(MemorySectionReader<'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],
    },
    CodeSectionStart {
        count: u32,
        range: Range,
        size: u32,
    },
    CodeSectionEntry(FunctionBody<'a>),
    ModuleCodeSectionStart {
        count: u32,
        range: Range,
        size: u32,
    },
    ModuleCodeSectionEntry {
        parser: Parser,
        range: Range,
    },
    UnknownSection {
        id: u8,
        contents: &'a [u8],
        range: Range,
    },
    End,
}

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

Indicates the header of a WebAssembly binary.

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

Fields of Version

num: u32

The version number found

range: Range

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

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

ImportSection(ImportSectionReader<'a>)

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

AliasSection(AliasSectionReader<'a>)

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

InstanceSection(InstanceSectionReader<'a>)

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

ModuleSection(ModuleSectionReader<'a>)

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

FunctionSection(FunctionSectionReader<'a>)

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

TableSection(TableSectionReader<'a>)

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

MemorySection(MemorySectionReader<'a>)

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

GlobalSection(GlobalSectionReader<'a>)

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

ExportSection(ExportSectionReader<'a>)

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

StartSection

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

Fields of StartSection

func: u32

The start function index

range: Range

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

ElementSection(ElementSectionReader<'a>)

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

DataCountSection

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

Fields of DataCountSection

count: u32

The number of data segments.

range: Range

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

DataSection(DataSectionReader<'a>)

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

CustomSection

A custom section was found.

Fields of CustomSection

name: &'a str

The name of the custom section.

data_offset: usize

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

data: &'a [u8]

The actual contents of the custom section.

CodeSectionStart

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.

Fields of CodeSectionStart

count: u32

The number of functions in this section.

range: Range

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

size: u32

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

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.

ModuleCodeSectionStart

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 ModuleCodeSectionEntry.

Fields of ModuleCodeSectionStart

count: u32

The number of inline modules in this section.

range: Range

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

size: u32

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

ModuleCodeSectionEntry

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 ModuleCodeSectionEntry 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.

Fields of ModuleCodeSectionEntry

parser: Parser

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

range: Range

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

UnknownSection

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.

Fields of UnknownSection

id: u8

The 8-bit identifier for this section.

contents: &'a [u8]

The contents of this section.

range: Range

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

End

The end of the WebAssembly module was reached.

Trait Implementations

impl<'_> Debug for Payload<'_>[src]

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]

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

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

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

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

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.

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.