Class MemoryReader
java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.MemoryReader
Reads typed values from WebAssembly linear memory.
Handles endianness conversion (WASM uses little-endian) and complex type unmarshalling.
Uses a reusable scratch buffer to avoid per-call byte array and ByteBuffer allocations in the hot path.
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryReader(ai.tegmentum.webassembly4j.api.Memory memory) Creates a new MemoryReader. -
Method Summary
Modifier and TypeMethodDescriptionbooleanreadBool(int offset) Reads a boolean value from the given offset.byte[]readBytes(int offset) Reads a byte array from the given offset.floatreadF32(int offset) Reads a 32-bit float from the given offset (little-endian).doublereadF64(int offset) Reads a 64-bit float from the given offset (little-endian).intreadI32(int offset) Reads a 32-bit integer from the given offset (little-endian).longreadI64(int offset) Reads a 64-bit integer from the given offset (little-endian).readString(int offset) Reads a string from the given offset.
-
Constructor Details
-
MemoryReader
public MemoryReader(ai.tegmentum.webassembly4j.api.Memory memory) Creates a new MemoryReader.- Parameters:
memory- the linear memory to read from
-
-
Method Details
-
readBool
public boolean readBool(int offset) Reads a boolean value from the given offset.- Parameters:
offset- the byte offset in linear memory- Returns:
- the boolean value
-
readI32
public int readI32(int offset) Reads a 32-bit integer from the given offset (little-endian).- Parameters:
offset- the byte offset in linear memory- Returns:
- the integer value
-
readI64
public long readI64(int offset) Reads a 64-bit integer from the given offset (little-endian).- Parameters:
offset- the byte offset in linear memory- Returns:
- the long value
-
readF32
public float readF32(int offset) Reads a 32-bit float from the given offset (little-endian).- Parameters:
offset- the byte offset in linear memory- Returns:
- the float value
-
readF64
public double readF64(int offset) Reads a 64-bit float from the given offset (little-endian).- Parameters:
offset- the byte offset in linear memory- Returns:
- the double value
-
readString
Reads a string from the given offset.Expects a (pointer, byte_length) pair at the offset, then reads UTF-8 data from the pointed-to location.
- Parameters:
offset- the byte offset of the (ptr, len) pair- Returns:
- the decoded string
-
readBytes
public byte[] readBytes(int offset) Reads a byte array from the given offset.Expects a (pointer, byte_length) pair at the offset, then reads the byte data from the pointed-to location.
- Parameters:
offset- the byte offset of the (ptr, len) pair- Returns:
- the byte array
-