Class Module
Represents a WebAssembly module.
Inheritance
Namespace: Wasmtime
Assembly: Wasmtime.Dotnet.dll
Syntax
public class Module : IDisposable
Properties
| Improve this Doc View SourceExports
The exports of the module.
Declaration
public IReadOnlyList<Export> Exports { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Export> |
Imports
The imports of the module.
Declaration
public IReadOnlyList<Import> Imports { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Import> |
Name
The name of the module.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceConvertText(String)
Convert WAT (Web Assembly Text) into WASM bytes
Declaration
public static byte[] ConvertText(string wat)
Parameters
Type | Name | Description |
---|---|---|
System.String | wat | A string containing WAT (Web Assembly Text) |
Returns
Type | Description |
---|---|
System.Byte[] | Returns a byte array containing the WebAssembly module represented by the given text. |
Exceptions
Type | Condition |
---|---|
WasmtimeException | Thrown if text is not valid WAT |
Deserialize(Engine, String, ReadOnlySpan<Byte>)
Deserializes a previously serialized module from a span of bytes.
Declaration
public static Module Deserialize(Engine engine, string name, ReadOnlySpan<byte> bytes)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use to deserialize the module. |
System.String | name | The name of the module being deserialized. |
ReadOnlySpan<System.Byte> | bytes | The previously serialized module bytes. |
Returns
Type | Description |
---|---|
Module | Returns the Module that was previously serialized. |
Remarks
The passed bytes must come from a previous call to Serialize().
DeserializeFile(Engine, String, String)
Deserializes a previously serialized module from a file.
Declaration
public static Module DeserializeFile(Engine engine, string name, string path)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to deserialize the module with. |
System.String | name | The name of the deserialized module. |
System.String | path | The path to the previously serialized module. |
Returns
Type | Description |
---|---|
Module | Returns the Module that was previously serialized. |
Remarks
The file's contents must come from a previous call to Serialize().
Dispose()
Declaration
public void Dispose()
FromBytes(Engine, String, ReadOnlySpan<Byte>)
Creates a Module given the module name and bytes.
Declaration
public static Module FromBytes(Engine engine, string name, ReadOnlySpan<byte> bytes)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | name | The name of the module. |
ReadOnlySpan<System.Byte> | bytes | The bytes of the module. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
FromFile(Engine, String)
Creates a Module given the path to the WebAssembly file.
Declaration
public static Module FromFile(Engine engine, string path)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | path | The path to the WebAssembly file. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
FromStream(Engine, String, Stream)
Creates a Module from a stream.
Declaration
public static Module FromStream(Engine engine, string name, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | name | The name of the module. |
Stream | stream | The stream of the module data. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
FromText(Engine, String, String)
Creates a Module based on a WebAssembly text format representation.
Declaration
public static Module FromText(Engine engine, string name, string text)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | name | The name of the module. |
System.String | text | The WebAssembly text format representation of the module. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
FromTextFile(Engine, String)
Creates a Module based on the path to a WebAssembly text format file.
Declaration
public static Module FromTextFile(Engine engine, string path)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | path | The path to the WebAssembly text format file. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
FromTextStream(Engine, String, Stream)
Creates a Module from a WebAssembly text format stream.
Declaration
public static Module FromTextStream(Engine engine, string name, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for the module. |
System.String | name | The name of the module. |
Stream | stream | The stream of the module data. |
Returns
Type | Description |
---|---|
Module | Returns a new Module. |
Serialize()
Serializes the module to an array of bytes.
Declaration
public byte[] Serialize()
Returns
Type | Description |
---|---|
System.Byte[] | Returns the serialized module as an array of bytes. |
Validate(Engine, ReadOnlySpan<Byte>)
Validates the given WebAssembly module.
Declaration
public static string? Validate(Engine engine, ReadOnlySpan<byte> bytes)
Parameters
Type | Name | Description |
---|---|---|
Engine | engine | The engine to use for validation. |
ReadOnlySpan<System.Byte> | bytes | The bytes of the WebAssembly module to validate. |
Returns
Type | Description |
---|---|
System.Nullable<System.String> | Returns null if the module is valid or an error message if the module is invalid. |