Interface BytecodeSerializer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a class that can serialize constants in a bytecode interpreter.
A BytecodeSerializer
establishes a byte encoding for objects. The
BytecodeDeserializer
used to deserialize an interpreter should follow the same encoding.
For example:
public class MyBytecodeSerializer implements BytecodeSerializer { @Override public void serialize(SerializerContext context, DataOutput buffer, Object object) throws IOException { if (object instanceof Integer i) { buffer.writeByte(0); buffer.writeInt(i); } else if (object instanceof String s) { buffer.writeByte(1); buffer.writeUTF(s); } else ... } }A serializer is responsible for encoding:
- objects used as constants in the bytecode (e.g., objects passed to
emitLoadConstant
or constant operands) - objects stored in non-
transient
fields of the root node Source
objects passed in builder calls (i.e., sources passed tobeginSource
)
- Since:
- 24.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Interface for a generated class that can serialize aBytecodeRootNode
to a byte buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
serialize
(BytecodeSerializer.SerializerContext context, DataOutput buffer, Object object) The serialization process.
-
Method Details
-
serialize
void serialize(BytecodeSerializer.SerializerContext context, DataOutput buffer, Object object) throws IOException The serialization process. The byte encoding ofobject
should be written tobuffer
.The
context
is supplied so that aBytecodeSerializer
can transitively serialize otherroot nodes
(e.g., inner functions) if necessary.Must not be dependent on any side-effects of the language.
- Throws:
IOException
- Since:
- 24.2
-