static boolean writeBuffer(Buffer buffer, ByteBuffer memory) {
        final int bufferSize = buffer.getSize();

        if (memory.remaining() < bufferSize + HEADER_LENGTH) {
            return false;
        }

        memory.putShort(buffer.isBuffer() ? HEADER_VALUE_IS_BUFFER : HEADER_VALUE_IS_EVENT);
        memory.putShort(buffer.isCompressed() ? BUFFER_IS_COMPRESSED : BUFFER_IS_NOT_COMPRESSED);
        memory.putInt(bufferSize);
        memory.put(buffer.getNioBufferReadable());
        return true;
    }
@Test
    void writeByteBufferNotEnoughSpace() {
        final ByteBuffer memory = ByteBuffer.allocateDirect(10);
        final Buffer buffer = createTestBuffer();

        final boolean written = BufferReaderWriterUtil.writeBuffer(buffer, memory);

        assertThat(written).isFalse();
        assertThat(memory.position()).isZero();
        assertThat(memory.limit()).isEqualTo(memory.capacity());
    }