Flake64 constructor
Flake64({})
Create a Flake64 instance. The default configuration uses a 42-bit timestamp, 10-bit machine id, and 11-bit sequence.
Implementation
Flake64({
required this.machineId,
this.machineBits = 10,
this.sequenceBits = 11,
TimestampSource time = _currentMillis,
int? epochYear,
bool continuousSequence = false,
}) : _tracker = new _Tracker(time, sequenceBits, continuousSequence) {
if (machineBits < 1)
throw new StateError('Machine bits must be at least 1.');
if (sequenceBits < 1)
throw new StateError('Sequence bits must be at least 1.');
_timeShiftBits = machineBits + sequenceBits;
if (_timeShiftBits > 21)
throw new StateError('Too many machine+sequence bits.');
if (this.machineId < 0 || this.machineId > (1 << machineBits) - 1)
throw new StateError('Machine ID out of bounds.');
if (epochYear != null) {
_epochOffset = new DateTime(epochYear).millisecondsSinceEpoch;
}
}