createId static method

BsonBinary createId(
  1. int seconds,
  2. bool clientMode
)

Implementation

static BsonBinary createId(int seconds, bool clientMode) {
  String getOctet(int value) {
    var res = value.toRadixString(16);
    while (res.length < 8) {
      res = '0$res';
    }
    return res;
  }

  if (clientMode) {
    var s = '${getOctet(seconds)}${getOctet(Statics.randomId)}'
        '${getOctet(Statics.nextIncrement)}';
    return BsonBinary.fromHexString(s);
  } else {
    return BsonBinary(12)
      ..writeInt(seconds, endianness: Endian.big)
      ..writeInt(Statics.randomId)
      ..writeInt(Statics.nextIncrement, endianness: Endian.big);
  }
}