code: public static ByteBuffer toBuffer(NDArrayMessageChunk chunk) {
          ByteBuffer ret = ByteBuffer.allocateDirect(sizeForMessage(chunk)).order(ByteOrder.nativeOrder());
          //the messages opType enum as an int
          ret.putInt(chunk.getMessageType().ordinal());
          //the number of chunks this chunk is apart of
          ret.putInt(chunk.getNumChunks());
          //the chunk size
          ret.putInt(chunk.getChunkSize());
          //the length of the id (for self describing purposes)
          ret.putInt(chunk.getId().getBytes().length);
          // the actual id as a string
          ret.put(chunk.getId().getBytes());
          //the chunk index
          ret.putInt(chunk.getChunkIndex());
          //the actual data
          ret.put(chunk.getData());
          return ret;
      }
docs: Convert an ndarray message chunk to a buffer.
  @param chunk the chunk to convert
  @return an {@link ByteBuffer} based on the
  passed in message chunk.