Class MarshalContext

java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.MarshalContext

public final class MarshalContext extends Object
Bundles memory, allocator, writer and reader for marshalling complex types to and from WebAssembly linear memory.
  • Constructor Details

    • MarshalContext

      public MarshalContext(ai.tegmentum.webassembly4j.api.Memory memory, MemoryAllocator allocator)
      Creates a new MarshalContext.
      Parameters:
      memory - the linear memory
      allocator - the memory allocator
  • Method Details

    • fromInstance

      public static MarshalContext fromInstance(ai.tegmentum.webassembly4j.api.Instance instance)
      Creates a MarshalContext from a WASM instance by resolving the default memory export and building an appropriate allocator.
      Parameters:
      instance - the WASM instance
      Returns:
      a new MarshalContext
      Throws:
      IllegalStateException - if the instance does not export memory
    • memory

      public ai.tegmentum.webassembly4j.api.Memory memory()
      Returns the linear memory.
      Returns:
      the memory
    • allocator

      public MemoryAllocator allocator()
      Returns the memory allocator.
      Returns:
      the allocator
    • writer

      public MemoryWriter writer()
      Returns the memory writer.
      Returns:
      the writer
    • reader

      public MemoryReader reader()
      Returns the memory reader.
      Returns:
      the reader