Exemple #1
0
  public static ONodeId generateUniqueId() {
    final long clusterPosition = random.nextLong(Long.MAX_VALUE);

    final int[] chunks = new int[CHUNKS_SIZE];
    final byte[] uuid = new byte[16];
    secureRandom.nextBytes(uuid);

    chunks[0] = (int) (clusterPosition >>> 32);
    chunks[1] = (int) clusterPosition;

    chunks[2] = OIntegerSerializer.INSTANCE.deserialize(uuid, 0);
    chunks[3] = OIntegerSerializer.INSTANCE.deserialize(uuid, 4);

    chunks[4] = OIntegerSerializer.INSTANCE.deserialize(uuid, 8);
    chunks[5] = OIntegerSerializer.INSTANCE.deserialize(uuid, 12);

    return new ONodeId(chunks, 1);
  }
  @Override
  public int deserialize(byte[] stream, int offset) {
    final int contentSize = getSerializedSize(stream, offset);

    this.size = OIntegerSerializer.INSTANCE.deserialize(stream, offset);

    this.serializedContent = new byte[contentSize];
    System.arraycopy(stream, offset, this.serializedContent, 0, contentSize);
    deserialized = false;

    return offset + contentSize;
  }
Exemple #3
0
  public static ONodeId fromStream(byte[] content, int start) {
    final int[] chunks = new int[CHUNKS_SIZE];

    int pos = start;
    for (int i = 0; i < CHUNKS_SIZE; i++) {
      chunks[i] = OIntegerSerializer.INSTANCE.deserialize(content, pos);
      pos += OIntegerSerializer.INT_SIZE;
    }

    final int signum = content[pos];

    return new ONodeId(chunks, signum);
  }
  private void doDeserialization() {
    if (deserialized) return;

    int offset = 0;
    int entriesSize = OIntegerSerializer.INSTANCE.deserialize(serializedContent, offset);
    offset += OIntegerSerializer.INT_SIZE;

    for (int i = 0; i < entriesSize; i++) {
      ORID rid = OLinkSerializer.INSTANCE.deserialize(serializedContent, offset);
      offset += OLinkSerializer.RID_SIZE;

      OIdentifiable identifiable;
      if (rid.isTemporary()) identifiable = rid.getRecord();
      else identifiable = rid;

      addEntry(identifiable);
    }

    deserialized = true;
  }
 @Override
 public int getSerializedSize(byte[] stream, int offset) {
   return OIntegerSerializer.INSTANCE.deserialize(stream, offset) * OLinkSerializer.RID_SIZE
       + OIntegerSerializer.INT_SIZE;
 }