Enum wasmparser::Payload

source ·
pub enum Payload<'a> {
Show 22 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

Fields

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

Indicates the header of a WebAssembly binary.

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

§

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.

§

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.

§

EventSection(EventSectionReader<'a>)

An event section was received, and the provided reader can be used to parse the contents of the event 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

Fields

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

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

§

ElementSection(ElementSectionReader<'a>)

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

§

DataCountSection

Fields

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

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

§

DataSection(DataSectionReader<'a>)

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

§

CustomSection

Fields

§name: &'a str

The name of the custom section.

§data_offset: usize

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

§data: &'a [u8]

The actual contents of the custom section.

§range: Range

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.

A custom section was found.

§

CodeSectionStart

Fields

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

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.

§

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.

§

ModuleSectionStart

Fields

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

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.

§

ModuleSectionEntry

Fields

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

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.

§

UnknownSection

Fields

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

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.

§

End

The end of the WebAssembly module was reached.

Trait Implementations§

source§

impl Debug for Payload<'_>

source§

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

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.