private void setMessageHeader() {
    Assert.assertTrue(overflowBuf == null);
    Assert.assertTrue(!isOverflowMode());
    // int processorType = this.msg.getProcessorType();
    int msgType;
    if (doneWritingMsg) {
      if (normalMsg) {
        msgType = Connection.NORMAL_MSG_TYPE;
      } else {
        msgType = Connection.END_CHUNKED_MSG_TYPE;
      }
      if (directReply) {
        msgType |= Connection.DIRECT_ACK_BIT;
      }
    } else {
      msgType = Connection.CHUNKED_MSG_TYPE;
    }
    if (!normalMsg) {
      if (msgId == MsgIdGenerator.NO_MSG_ID) {
        msgId = MsgIdGenerator.obtain();
      }
    }

    buffer.putInt(Connection.MSG_HEADER_SIZE_OFFSET,
        Connection.calcHdrSize(buffer.limit() - Connection.MSG_HEADER_BYTES));
    buffer.put(Connection.MSG_HEADER_TYPE_OFFSET, (byte) (msgType & 0xff));
    buffer.putShort(Connection.MSG_HEADER_ID_OFFSET, msgId);
    buffer.position(0);
  }
write the header after the message has been written to the stream
geode-core/src/main/java/org/apache/geode/internal/tcp/MsgStreamer.java