예제 #1
0
  /**
   * Streams all members (dest and src addresses, buffer and headers) to the output stream.
   *
   * @param out
   * @throws Exception
   */
  public void writeTo(DataOutput out) throws Exception {
    byte leading = 0;

    if (dest_addr != null) leading = Util.setFlag(leading, DEST_SET);

    if (src_addr != null) leading = Util.setFlag(leading, SRC_SET);

    if (buf != null) leading = Util.setFlag(leading, BUF_SET);

    // 1. write the leading byte first
    out.write(leading);

    // 2. the flags (e.g. OOB, LOW_PRIO), skip the transient flags
    out.writeShort(flags);

    // 3. dest_addr
    if (dest_addr != null) Util.writeAddress(dest_addr, out);

    // 4. src_addr
    if (src_addr != null) Util.writeAddress(src_addr, out);

    // 5. buf
    if (buf != null) {
      out.writeInt(length);
      out.write(buf, offset, length);
    }

    // 6. headers
    int size = headers.size();
    out.writeShort(size);
    final short[] ids = headers.getRawIDs();
    final Header[] hdrs = headers.getRawHeaders();
    for (int i = 0; i < ids.length; i++) {
      if (ids[i] > 0) {
        out.writeShort(ids[i]);
        writeHeader(hdrs[i], out);
      }
    }
  }
예제 #2
0
  /**
   * Writes the message to the output stream, but excludes the dest and src addresses unless the src
   * address given as argument is different from the message's src address
   *
   * @param src
   * @param out
   * @throws Exception
   */
  public void writeToNoAddrs(Address src, DataOutputStream out) throws Exception {
    byte leading = 0;

    boolean write_src_addr = src == null || src_addr != null && !src_addr.equals(src);

    if (write_src_addr) leading = Util.setFlag(leading, SRC_SET);

    if (buf != null) leading = Util.setFlag(leading, BUF_SET);

    // 1. write the leading byte first
    out.write(leading);

    // 2. the flags (e.g. OOB, LOW_PRIO)
    out.writeShort(flags);

    // 4. src_addr
    if (write_src_addr) Util.writeAddress(src_addr, out);

    // 5. buf
    if (buf != null) {
      out.writeInt(length);
      out.write(buf, offset, length);
    }

    // 6. headers
    int size = headers.size();
    out.writeShort(size);
    final short[] ids = headers.getRawIDs();
    final Header[] hdrs = headers.getRawHeaders();
    for (int i = 0; i < ids.length; i++) {
      if (ids[i] > 0) {
        out.writeShort(ids[i]);
        writeHeader(hdrs[i], out);
      }
    }
  }