Exemplo n.º 1
0
  /**
   * Decode the data in the buffer and set the all the values in the DTNTime
   *
   * @param dt Empty DTNTime to store decoded DTNTime
   * @param buf Serializable Buffer to read and recode DTNTime
   */
  public static void decodeSDNV(DTNTime dt, IByteBuffer buf) {
    long[] decoded_seconds = new long[1];
    long[] decoded_nanoseconds = new long[1];
    SDNV.decode(buf, decoded_seconds);
    dt.set_seconds(decoded_seconds[0]);

    SDNV.decode(buf, decoded_nanoseconds);
    dt.set_nanoseconds(decoded_nanoseconds[0]);
  }
  /**
   * Encode the value and write to the buffer
   *
   * @param val Value to encode
   * @param buf Buffer to write encoded value
   * @return Number of bytes encoded
   */
  public int write_sdnv(long val, IByteBuffer buf) {

    int sdnv_len = SDNV.encode(val, buf);
    assert (sdnv_len > 0) : TAG + "write sdnv: incorrect length";
    ;
    return sdnv_len;
  }
  /**
   * decode the value from the buffer and return
   *
   * @param buf Buffer to read encoded value form
   * @param val Get the empty array and set the decoded value on the first index of array
   * @return Number of bytes decoded
   */
  public int read_sdnv(IByteBuffer buf, int[] val) throws BlockProcessorTooShortException {

    int sdnv_len = SDNV.decode(buf, val);
    if (sdnv_len < 1) {
      throw new BlockProcessorTooShortException();
    }
    assert (sdnv_len < 0) : TAG + "read sdnv: incorrect length";

    return sdnv_len;
  }
Exemplo n.º 4
0
  /**
   * Method for parse DTNTime , return null if it can't pass
   *
   * @param bp Buffer pupulated with data
   */
  public static DTNTime decodeSDNV_and_Create_DTNTime(IByteBuffer bp) {
    DTNTime ret = new DTNTime();
    int sdnv_len = SDNV.len(bp);

    if (sdnv_len == -1) return null;
    else {
      decodeSDNV(ret, bp);
      return ret;
    }
  }
Exemplo n.º 5
0
  /**
   * Get the length of bytes can be decoded from the buffer
   *
   * @param n Length of buffer
   * @param bp Buffer to read bytes
   * @return Number of bytes can be decoded
   */
  public static int SDNVs_decoding_len(int n, IByteBuffer bp) {
    int old_position = bp.position();

    try {
      int sumSDNVs_len = 0;
      for (int i = 1; i <= n; i++) {
        int current_SDNV_len = SDNV.len(bp);
        if (current_SDNV_len == -1) return -1;

        bp.position(bp.position() + current_SDNV_len);
        sumSDNVs_len += current_SDNV_len;
      }
      return sumSDNVs_len;
    } finally {
      bp.position(old_position);
    }
  }
  /**
   * Internal function get the total length of primary block to write on the buffer
   *
   * @param bundle Bundle to generate
   * @param dict Dictionary to get the offsets of the endpoint eids
   * @param primary PrimaryBlock data strucre object
   * @return Total numbers of Bytes required to write primary block
   */
  protected static int get_primary_len(final Bundle bundle, Dictionary dict, PrimaryBlock primary) {
    int primary_len = 0;
    int block_len = 0;
    primary.set_dictionary_length(0);
    primary.set_block_length(0);

    /*
     * We need to figure out the total length of the primary block,
     * except for the SDNVs used to encode flags and the length itself and
     * the one byte version field.
     *
     * First, we determine the size of the dictionary by first
     * figuring out all the unique strings, and in the process,
     * remembering their offsets and summing up their lengths
     * (including the null terminator for each).
     */

    dict.get_offsets(bundle.dest(), primary.dest_scheme_offset(), primary.dest_ssp_offset());

    block_len += SDNV.encoding_len(primary.dest_scheme_offset());
    block_len += SDNV.encoding_len(primary.dest_ssp_offset());

    dict.get_offsets(bundle.source(), primary.source_scheme_offset(), primary.source_ssp_offset());

    block_len += SDNV.encoding_len(primary.source_scheme_offset());
    block_len += SDNV.encoding_len(primary.source_ssp_offset());

    dict.get_offsets(
        bundle.replyto(), primary.replyto_scheme_offset(), primary.replyto_ssp_offset());

    block_len += SDNV.encoding_len(primary.replyto_scheme_offset());
    block_len += SDNV.encoding_len(primary.replyto_ssp_offset());

    dict.get_offsets(
        bundle.custodian(), primary.custodian_scheme_offset(), primary.custodian_ssp_offset());

    block_len += SDNV.encoding_len(primary.custodian_scheme_offset());
    block_len += SDNV.encoding_len(primary.custodian_ssp_offset());

    primary.set_dictionary_length(dict.dict_length());

    block_len += SDNV.encoding_len(bundle.creation_ts().seconds());
    block_len += SDNV.encoding_len(bundle.creation_ts().seqno());
    block_len += SDNV.encoding_len(bundle.expiration());

    block_len += SDNV.encoding_len(primary.dictionary_length_value());
    block_len += primary.dictionary_length_value();

    /*
     * If the bundle is a fragment, we need to include space for the
     * fragment offset and the original payload length.
     *
     * Note: Any changes to this protocol must be reflected into the
     * FragmentManager since it depends on this length when
     * calculating fragment sizes.
     */
    if (bundle.is_fragment()) {
      block_len += SDNV.encoding_len(bundle.frag_offset());
      block_len += SDNV.encoding_len(bundle.orig_length());
    }

    // Format the processing flags.
    primary.set_processing_flags(format_bundle_flags(bundle));

    primary.set_processing_flags(format_bundle_flags(bundle));
    primary.set_processing_flags(primary.processing_flags_value() | format_cos_flags(bundle));
    primary.set_processing_flags(primary.processing_flags_value() | format_srr_flags(bundle));

    /*
     * Finally, add up the initial preamble and the variable
     * length part.
     */

    primary.set_block_length(block_len);

    primary_len =
        (int)
            (1
                + SDNV.encoding_len(primary.processing_flags)
                + SDNV.encoding_len(primary.block_length())
                + primary.block_length_value());

    Log.d(TAG, "get_primary_len: for bundleid = " + bundle.bundleid() + ": " + primary_len);
    // Fill in the remaining values of 'primary' just for the sake of returning
    // a complete data structure.
    primary.set_version(BundleProtocol.CURRENT_VERSION);
    primary.set_creation_time(bundle.creation_ts().seconds());
    primary.set_creation_sequence(bundle.creation_ts().seqno());
    primary.set_lifetime(bundle.expiration());
    return primary_len;
  }
Exemplo n.º 7
0
 /**
  * Decode the data in the buffer and set the all the values in the DTNTime
  *
  * @param buf Buffer to decode data
  */
 public static int SDNV_decoding_len(IByteBuffer buf) {
   return SDNV.SDNVs_decoding_len(2, buf);
 }
Exemplo n.º 8
0
 /**
  * Encode this into SDNV and move the buffer position
  *
  * @param dt DTNTime to encode
  * @param buf Serializable Buffer to store SDNV of DTNTime
  */
 public static void encodeSDNV(DTNTime dt, IByteBuffer buf) {
   SDNV.encode(dt.seconds_, buf);
   SDNV.encode(dt.nanoseconds_, buf);
 }
Exemplo n.º 9
0
 /**
  * Return the length of SDNV encoding of the input DTNTime
  *
  * @param dt DTNTime object to get the length of SDNV encoding of the input DTNTime
  * @return Total length of SDVN encoding of DTNTime
  */
 public static int SDNV_encoding_len(DTNTime dt) {
   return SDNV.encoding_len(dt.seconds_) + SDNV.encoding_len(dt.nanoseconds_);
 }