Class StringCodec
java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.StringCodec
Encodes and decodes strings to/from WebAssembly linear memory using UTF-8.
Follows the Component Model Canonical ABI convention where strings are represented as a (pointer, byte_length) pair in linear memory.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringdecode(ai.tegmentum.webassembly4j.api.Memory memory, int ptr, int byteLen) Decodes a string from WebAssembly linear memory.static int[]encode(String value, ai.tegmentum.webassembly4j.api.Memory memory, MemoryAllocator allocator) Encodes a string into WebAssembly linear memory.
-
Method Details
-
encode
public static int[] encode(String value, ai.tegmentum.webassembly4j.api.Memory memory, MemoryAllocator allocator) Encodes a string into WebAssembly linear memory.- Parameters:
value- the string to encodememory- the linear memory to write toallocator- the allocator to use for the string data- Returns:
- a two-element array containing [pointer, byte_length]
-
decode
Decodes a string from WebAssembly linear memory.- Parameters:
memory- the linear memory to read fromptr- the pointer to the start of the string databyteLen- the length of the string data in bytes- Returns:
- the decoded string
-