code: private static ByteBuf allocateBuffer(
  			ByteBufAllocator allocator,
  			byte id,
  			int messageHeaderLength,
  			int contentLength,
  			boolean allocateForContent) {
  		checkArgument(contentLength <= Integer.MAX_VALUE - FRAME_HEADER_LENGTH);
  
  		final ByteBuf buffer;
  		if (!allocateForContent) {
  			buffer = allocator.directBuffer(FRAME_HEADER_LENGTH + messageHeaderLength);
  		} else if (contentLength != -1) {
  			buffer = allocator.directBuffer(FRAME_HEADER_LENGTH + messageHeaderLength + contentLength);
  		} else {
  			// content length unknown -> start with the default initial size (rather than FRAME_HEADER_LENGTH only):
  			buffer = allocator.directBuffer();
  		}
  		buffer.writeInt(FRAME_HEADER_LENGTH + messageHeaderLength + contentLength); // may be updated later, e.g. if contentLength == -1
  		buffer.writeInt(MAGIC_NUMBER);
  		buffer.writeByte(id);
  
  		return buffer;
  	}
docs: Allocates a new buffer and adds some header information for the frame decoder.
  
  <p>If the <tt>contentLength</tt> is unknown, you must write the actual length after adding
  the contents as an integer to position <tt>0</tt>!
  
  @param allocator
  byte buffer allocator to use
  @param id
  {@link NettyMessage} subclass ID
  @param messageHeaderLength
  additional header length that should be part of the allocated buffer and is written
  outside of this method
  @param contentLength
  content length (or <tt>-1</tt> if unknown)
  @param allocateForContent
  whether to make room for the actual content in the buffer (<tt>true</tt>) or whether to
  only return a buffer with the header information (<tt>false</tt>)
  
  @return a newly allocated direct buffer with header data written for {@link
  NettyMessageDecoder}