public static Buffer toBuffer(AbstractEvent event, boolean hasPriority) throws IOException {
        final ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);

        MemorySegment data = MemorySegmentFactory.wrap(serializedEvent.array());

        final Buffer buffer =
                new NetworkBuffer(
                        data, FreeingBufferRecycler.INSTANCE, getDataType(event, hasPriority));
        buffer.setSize(serializedEvent.remaining());

        return buffer;
    }
@Test
    void testToBuffer() throws IOException {
        for (AbstractEvent evt : events) {
            Buffer buffer = EventSerializer.toBuffer(evt, false);

            assertThat(buffer.isBuffer()).isFalse();
            assertThat(buffer.readableBytes()).isGreaterThan(0);
            assertThat(buffer.isRecycled()).isFalse();

            if (evt instanceof CheckpointBarrier) {
                assertThat(buffer.getDataType().isBlockingUpstream()).isTrue();
            } else if (evt instanceof EndOfData) {
                assertThat(buffer.getDataType()).isEqualTo(Buffer.DataType.END_OF_DATA);
            } else if (evt instanceof EndOfPartitionEvent) {
                assertThat(buffer.getDataType()).isEqualTo(Buffer.DataType.END_OF_PARTITION);
            } else {
                assertThat(buffer.getDataType()).isEqualTo(Buffer.DataType.EVENT_BUFFER);
            }
        }
    }