presto-main/src/main/java/io/prestosql/operator/aggregation/minmaxby/KeyAndBlockPositionValueStateSerializer.java/KeyAndBlockPositionValueStateSerializer/serialize
class KeyAndBlockPositionValueStateSerializer:    @Override
    public void serialize(T state, BlockBuilder out)
    {
        BlockBuilder blockBuilder = out.beginBlockEntry();
        BOOLEAN.writeBoolean(blockBuilder, state.isFirstNull());
        BOOLEAN.writeBoolean(blockBuilder, state.isSecondNull());

        if (state.isFirstNull()) {
            blockBuilder.appendNull();
        }
        else {
            writeFirstField(blockBuilder, state);
        }

        if (state.isSecondNull()) {
            blockBuilder.appendNull();
        }
        else {
            secondType.appendTo(state.getSecondBlock(), state.getSecondPosition(), blockBuilder);
        }
        out.closeEntry();
    }