Class WasmRuntime

java.lang.Object
org.mockserver.wasm.WasmRuntime

public class WasmRuntime extends Object
Thin wrapper around a compiled chicory WASM instance.

Thread-safety: chicory Instance is NOT thread-safe, so the stored WASM bytes are parsed into a WasmModule and a fresh Instance is created for each invocation.

The WASM module must export a function match(i32 ptr, i32 len) -> i32 that reads len bytes from linear memory starting at ptr and returns non-zero for a match.

This class fails closed: any error returns false.

  • Constructor Details

    • WasmRuntime

      public WasmRuntime(byte[] wasmBytes)
      Create a runtime with the default memory page limit from ConfigurationProperties.wasmMaxMemoryPages().
    • WasmRuntime

      public WasmRuntime(byte[] wasmBytes, int maxMemoryPages)
      Create a runtime with an explicit memory page limit.
      Parameters:
      wasmBytes - the compiled WASM binary
      maxMemoryPages - maximum number of WASM linear memory pages (each page is 64 KiB)
  • Method Details

    • callMatch

      public boolean callMatch(String requestBody)
      Call the WASM module's match() function with the request body written into linear memory at offset 0.
      Parameters:
      requestBody - the HTTP request body (may be null)
      Returns:
      true if the module's match function returns non-zero