Enum cranelift_wasm::wasmparser::Payload
source · pub enum Payload<'a> {
Show 29 variants
Version {
num: u16,
encoding: Encoding,
range: Range<usize>,
},
TypeSection(SectionLimited<'a, Type>),
ImportSection(SectionLimited<'a, Import<'a>>),
FunctionSection(SectionLimited<'a, u32>),
TableSection(SectionLimited<'a, Table<'a>>),
MemorySection(SectionLimited<'a, MemoryType>),
TagSection(SectionLimited<'a, TagType>),
GlobalSection(SectionLimited<'a, Global<'a>>),
ExportSection(SectionLimited<'a, Export<'a>>),
StartSection {
func: u32,
range: Range<usize>,
},
ElementSection(SectionLimited<'a, Element<'a>>),
DataCountSection {
count: u32,
range: Range<usize>,
},
DataSection(SectionLimited<'a, Data<'a>>),
CodeSectionStart {
count: u32,
range: Range<usize>,
size: u32,
},
CodeSectionEntry(FunctionBody<'a>),
ModuleSection {
parser: Parser,
range: Range<usize>,
},
InstanceSection(SectionLimited<'a, Instance<'a>>),
CoreTypeSection(SectionLimited<'a, CoreType<'a>>),
ComponentSection {
parser: Parser,
range: Range<usize>,
},
ComponentInstanceSection(SectionLimited<'a, ComponentInstance<'a>>),
ComponentAliasSection(SectionLimited<'a, ComponentAlias<'a>>),
ComponentTypeSection(SectionLimited<'a, ComponentType<'a>>),
ComponentCanonicalSection(SectionLimited<'a, CanonicalFunction>),
ComponentStartSection {
start: ComponentStartFunction,
range: Range<usize>,
},
ComponentImportSection(SectionLimited<'a, ComponentImport<'a>>),
ComponentExportSection(SectionLimited<'a, ComponentExport<'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
Indicates the header of a WebAssembly module or component.
Fields
TypeSection(SectionLimited<'a, Type>)
A module type section was received and the provided reader can be used to parse the contents of the type section.
ImportSection(SectionLimited<'a, Import<'a>>)
A module import section was received and the provided reader can be used to parse the contents of the import section.
FunctionSection(SectionLimited<'a, u32>)
A module function section was received and the provided reader can be used to parse the contents of the function section.
TableSection(SectionLimited<'a, Table<'a>>)
A module table section was received and the provided reader can be used to parse the contents of the table section.
MemorySection(SectionLimited<'a, MemoryType>)
A module memory section was received and the provided reader can be used to parse the contents of the memory section.
TagSection(SectionLimited<'a, TagType>)
A module tag section was received, and the provided reader can be used to parse the contents of the tag section.
GlobalSection(SectionLimited<'a, Global<'a>>)
A module global section was received and the provided reader can be used to parse the contents of the global section.
ExportSection(SectionLimited<'a, Export<'a>>)
A module export section was received, and the provided reader can be used to parse the contents of the export section.
StartSection
A module start section was received.
Fields
ElementSection(SectionLimited<'a, Element<'a>>)
A module element section was received and the provided reader can be used to parse the contents of the element section.
DataCountSection
A module data count section was received.
Fields
DataSection(SectionLimited<'a, Data<'a>>)
A module data section was received and the provided reader can be used to parse the contents of the data section.
CodeSectionStart
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.
Fields
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.
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
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
.
Fields
InstanceSection(SectionLimited<'a, Instance<'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.
CoreTypeSection(SectionLimited<'a, CoreType<'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
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
.
Fields
ComponentInstanceSection(SectionLimited<'a, ComponentInstance<'a>>)
A component instance section was received and the provided reader can be used to parse the contents of the component instance section.
ComponentAliasSection(SectionLimited<'a, ComponentAlias<'a>>)
A component alias section was received and the provided reader can be used to parse the contents of the component alias section.
ComponentTypeSection(SectionLimited<'a, ComponentType<'a>>)
A component type section was received and the provided reader can be used to parse the contents of the component type section.
ComponentCanonicalSection(SectionLimited<'a, CanonicalFunction>)
A component canonical section was received and the provided reader can be used to parse the contents of the component canonical section.
ComponentStartSection
A component start section was received.
Fields
start: ComponentStartFunction
The start function description.
ComponentImportSection(SectionLimited<'a, ComponentImport<'a>>)
A component import section was received and the provided reader can be used to parse the contents of the component import section.
ComponentExportSection(SectionLimited<'a, ComponentExport<'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
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.
Fields
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.
Implementations§
source§impl Payload<'_>
impl Payload<'_>
sourcepub fn as_section(&self) -> Option<(u8, Range<usize>)>
pub fn as_section(&self) -> Option<(u8, Range<usize>)>
If this Payload
represents a section in the original wasm module then
the section’s id and range within the original wasm binary are returned.
Not all payloads refer to entire sections, such as the Version
and
CodeSectionEntry
variants. These variants will return None
from this
function.
Otherwise this function will return Some
where the first element is
the byte identifier for the section and the second element is the range
of the contents of the section within the original wasm binary.
The purpose of this method is to enable tools to easily iterate over entire sections if necessary and handle sections uniformly, for example dropping custom sections while preserving all other sections.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Payload<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more