@Override
    public byte[] serialize(final String topic, final LeftOrRightValue<V1, V2> data) {
        if (data == null) {
            return null;
        }

        final byte[] rawValue = (data.getLeftValue() != null)
            ? leftSerializer.serialize(topic, data.getLeftValue())
            : rightSerializer.serialize(topic, data.getRightValue());

        if (rawValue == null) {
            return null;
        }

        return ByteBuffer
            .allocate(1 + rawValue.length)
            .put((byte) (data.getLeftValue() != null ? 1 : 0))
            .put(rawValue)
            .array();
    }
Serializes a {@link LeftOrRightValue}. The serialized bytes starts with a byte that references
to whether the value is V1 or V2.
streams/src/main/java/org/apache/kafka/streams/state/internals/LeftOrRightValueSerializer.java