Enum wasmparser::Payload

source ·
pub enum Payload<'a> {
Show 30 variants Version { num: u32, encoding: Encoding, range: Range<usize>, }, TypeSection(TypeSectionReader<'a>), ImportSection(ImportSectionReader<'a>), FunctionSection(FunctionSectionReader<'a>), TableSection(TableSectionReader<'a>), MemorySection(MemorySectionReader<'a>), TagSection(TagSectionReader<'a>), GlobalSection(GlobalSectionReader<'a>), ExportSection(ExportSectionReader<'a>), StartSection { func: u32, range: Range<usize>, }, ElementSection(ElementSectionReader<'a>), DataCountSection { count: u32, range: Range<usize>, }, DataSection(DataSectionReader<'a>), CodeSectionStart { count: u32, range: Range<usize>, size: u32, }, CodeSectionEntry(FunctionBody<'a>), ModuleSection { parser: Parser, range: Range<usize>, }, InstanceSection(InstanceSectionReader<'a>), AliasSection(AliasSectionReader<'a>), CoreTypeSection(CoreTypeSectionReader<'a>), ComponentSection { parser: Parser, range: Range<usize>, }, ComponentInstanceSection(ComponentInstanceSectionReader<'a>), ComponentAliasSection(ComponentAliasSectionReader<'a>), ComponentTypeSection(ComponentTypeSectionReader<'a>), ComponentCanonicalSection(ComponentCanonicalSectionReader<'a>), ComponentStartSection(ComponentStartSectionReader<'a>), ComponentImportSection(ComponentImportSectionReader<'a>), ComponentExportSection(ComponentExportSectionReader<'a>), CustomSection(CustomSectionReader<'a>), UnknownSection { id: u8, contents: &'a [u8], range: Range<usize>, }, End(usize),
}
Expand description

Values that can be parsed from a WebAssembly module or component.

This enumeration is all possible chunks of pieces that can be parsed by a Parser from a binary WebAssembly module or component. 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 module or component 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 in the header.

§encoding: Encoding

The encoding format being parsed.

§range: Range<usize>

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

Indicates the header of a WebAssembly module or component.

§

TypeSection(TypeSectionReader<'a>)

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

§

ImportSection(ImportSectionReader<'a>)

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

§

FunctionSection(FunctionSectionReader<'a>)

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

§

TableSection(TableSectionReader<'a>)

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

§

MemorySection(MemorySectionReader<'a>)

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

§

TagSection(TagSectionReader<'a>)

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

§

GlobalSection(GlobalSectionReader<'a>)

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

§

ExportSection(ExportSectionReader<'a>)

A module 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<usize>

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

A module start section was received.

§

ElementSection(ElementSectionReader<'a>)

A module 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<usize>

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

A module data count section was received.

§

DataSection(DataSectionReader<'a>)

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

§

CodeSectionStart

Fields

§count: u32

The number of functions in this section.

§range: Range<usize>

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 of a WebAssembly module.

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 from a WebAssembly module.

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.

§

ModuleSection

Fields

§parser: Parser

The parser for the nested module.

§range: Range<usize>

The range of bytes that represent the nested module in the original byte stream.

A core module section was received and the provided parser can be used to parse the nested module.

This variant is special in that it returns a sub-Parser. Upon receiving a ModuleSection 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 current component.

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

§

InstanceSection(InstanceSectionReader<'a>)

A core instance section was received and the provided parser can be used to parse the contents of the core instance section.

Currently this section is only parsed in a component.

§

AliasSection(AliasSectionReader<'a>)

A core alias section was received and the provided parser can be used to parse the contents of the core alias section.

Currently this section is only parsed in a component.

§

CoreTypeSection(CoreTypeSectionReader<'a>)

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

Currently this section is only parsed in a component.

§

ComponentSection

Fields

§parser: Parser

The parser for the nested component.

§range: Range<usize>

The range of bytes that represent the nested component in the original byte stream.

A component section from a WebAssembly component was received and the provided parser can be used to parse the nested component.

This variant is special in that it returns a sub-Parser. Upon receiving a ComponentSection 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 current component.

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

§

ComponentInstanceSection(ComponentInstanceSectionReader<'a>)

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

§

ComponentAliasSection(ComponentAliasSectionReader<'a>)

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

§

ComponentTypeSection(ComponentTypeSectionReader<'a>)

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

§

ComponentCanonicalSection(ComponentCanonicalSectionReader<'a>)

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

§

ComponentStartSection(ComponentStartSectionReader<'a>)

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

§

ComponentImportSection(ComponentImportSectionReader<'a>)

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

§

ComponentExportSection(ComponentExportSectionReader<'a>)

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

§

CustomSection(CustomSectionReader<'a>)

A module or component custom section was received.

§

UnknownSection

Fields

§id: u8

The 8-bit identifier for this section.

§contents: &'a [u8]

The contents of this section.

§range: Range<usize>

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 encountered. This likely wants to be interpreted as an error by consumers of the parser, but this can also be used to parse sections currently unsupported by the parser.

§

End(usize)

The end of the WebAssembly module or component was reached.

The value is the offset in the input byte stream where the end 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.