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.

@FunctionalInterface public interface BytecodeSerializer
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 to beginSource)
Since:
24.2
See Also: