I compared the code about ObjectId() in bson ^4.0.0 and bson ^5.0.0:
In bson ^4.0.0:
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);
}
}
In bson ^5.0.0:
/// creates a BsonBinary representation of this ObjectId with the given number
/// of seconds sinceEpoch
static BsonBinary createId(int seconds) => BsonBinary(12)
..writeInt(seconds, endianness: Endian.big)
..setIntExtended(_randomValue, 5)
..setIntExtended(_nextIncrement, 3, endianness: Endian.big);
then I change the code in bson ^5.0.0 to :
/// creates a BsonBinary representation of this ObjectId with the given number
/// of seconds sinceEpoch
static BsonBinary createId(int seconds) => BsonBinary(12)
..writeInt(seconds, endianness: Endian.big)
..writeInt(Statics.randomId)
..writeInt(Statics.nextIncrement, endianness: Endian.big);
I compared the code about ObjectId() in bson ^4.0.0 and bson ^5.0.0:
In bson ^4.0.0:
In bson ^5.0.0:
then I change the code in bson ^5.0.0 to :
every thing is ok.
best regards.