Class GcMarshaller
java.lang.Object
ai.tegmentum.webassembly4j.runtime.gc.GcMarshaller
Marshals Java objects to and from WebAssembly GC struct instances.
Works with classes annotated with GcMapped. The marshaller
reflects the class fields, maps them to GC struct fields, and handles
bidirectional conversion.
Example:
GcExtension gc = instance.extension(GcExtension.class).orElseThrow();
GcMarshaller marshaller = GcMarshaller.forExtension(gc);
// Java → GC struct
Point p = new Point(1.0, 2.0);
GcStructInstance struct = marshaller.marshal(p);
// GC struct → Java
Point result = marshaller.unmarshal(struct, Point.class);
-
Method Summary
Modifier and TypeMethodDescriptionstatic GcMarshallerforExtension(ai.tegmentum.webassembly4j.api.gc.GcExtension gc) Creates a marshaller using the given GC extension and a new type mapper.static GcMarshallerforExtension(ai.tegmentum.webassembly4j.api.gc.GcExtension gc, GcTypeMapper typeMapper) Creates a marshaller using the given GC extension and type mapper.ai.tegmentum.webassembly4j.api.gc.GcStructInstanceMarshals a Java object to a GC struct instance.Returns the type mapper used by this marshaller.<T> TUnmarshals a GC struct instance to a Java object.
-
Method Details
-
forExtension
Creates a marshaller using the given GC extension and a new type mapper. -
forExtension
public static GcMarshaller forExtension(ai.tegmentum.webassembly4j.api.gc.GcExtension gc, GcTypeMapper typeMapper) Creates a marshaller using the given GC extension and type mapper. -
typeMapper
Returns the type mapper used by this marshaller. -
marshal
Marshals a Java object to a GC struct instance.- Parameters:
object- an instance of aGcMapped-annotated class- Returns:
- a new GC struct instance with the object's field values
- Throws:
IllegalArgumentException- if the object's class is not GC-mappable
-
unmarshal
Unmarshals a GC struct instance to a Java object.- Type Parameters:
T- the target type- Parameters:
struct- the GC struct instancetype- the target Java class (must beGcMapped-annotated)- Returns:
- a new Java object with fields populated from the struct
- Throws:
IllegalArgumentException- if the class is not GC-mappable
-