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
emitLoadConstantor constant operands) - objects stored in non-
transientfields of the root node Sourceobjects passed in builder calls (i.e., sources passed tobeginSource)
- Since:
- 24.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface for a generated class that can serialize aBytecodeRootNodeto a byte buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidserialize(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 ofobjectshould be written tobuffer.The
contextis supplied so that aBytecodeSerializercan 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
-