ObjectId.fromBytes constructor

ObjectId.fromBytes(
  1. List<int> bytes
)

Creates ObjectId from bytes.

Example usage:

final id = ObjectId();
final id2 = ObjectId.fromBytes(id.bytes);
print(id == id2) // => true

ObjectId structure:

  4 byte timestamp    5 byte process unique   3 byte counter
|<----------------->|<---------------------->|<------------>|
|----|----|----|----|----|----|----|----|----|----|----|----|
0                   4                   8                   12

Implementation

ObjectId.fromBytes(List<int> bytes) {
  ArgumentError.checkNotNull(bytes, 'bytes');
  if (bytes.length != byteLength) {
    throw ArgumentError.value(
      bytes,
      'bytes',
      'Bytes array should has length equal to $byteLength',
    );
  }

  for (var i = 0; i < byteLength; i++) {
    _bytes[i] = bytes[i];
  }
}