class BufferReaderWriterUtil {

	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;
	}

}