code: private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {
          int payload_len = 0;
          if (message.message() != null)
              payload_len = message.message().length;
  
          short type = message.get_type();
          bout.writeShort(type);
  
          int task_id = message.task();
          if (task_id > Short.MAX_VALUE)
              throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
  
          bout.writeShort((short) task_id);
          bout.writeInt(payload_len);
          if (payload_len > 0)
              bout.write(message.message());
  
          // LOG.info("Write one message taskid:{}, len:{}, data:{}", taskId
          // , payload_len, JStormUtils.toPrintableString(message.message()) );
      }
docs: write a TaskMessage into a stream
  
  Each TaskMessage is encoded as: task ... short(2) len ... int(4) payload ... byte[] *