Nuid class

Nuid means NATS UID

NATS is a communication protocol and need an optimized way to generate UIDs for the protocol.

The Nuid is an implementation of the NUID algorithm based of the Node.js nuid package

final nuid = Nuid.instance;

print('String:');
print('  First nuid:');
for (var i = 0; i < 4; i++) {
  print('  - ${nuid.next()}');
}

print('  Reseting nuid:');
nuid.reset();

for (var i = 0; i < 4; i++) {
  print('  - ${nuid.next()}');
}

print('\nBytes:');
print('  First nuid:');
for (var i = 0; i < 4; i++) {
  print('  - ${nuid.nextBytes()}');
}

print('  Reseting nuid:');
nuid.reset();

for (var i = 0; i < 4; i++) {
  print('  - ${nuid.nextBytes()}');
}

Constructors

Nuid([SeqInc? seqInc])
Create and initialize a Nuid.

Properties

buffer List<int>
Makes a copy to keep the _buf inmutable
no setter
current String
Return the buffer as String
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

next() String
Returns the next Nuid
nextBytes() List<int>
Returns the next Nuid as a List<int>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset([bool seqInc = true]) → void
Initializes or reinitializes a nuid with a crypto random prefix, and pseudo-random sequence and increment.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

binaryDigits List<int>
digits in List<int> format (i.e. as char array)
no setter
instance Nuid
Global Nuid instance
final

Constants

base → const int
Number of possible digits for an Nuid
digits → const String
Valid digits for Nuid (base36)
preLen → const int
Number of static prefix of the Nuid
seqLen → const int
Number of variable suffix of the Nuid
totalLen → const int
Length of a Nuid