UUIDs¶
Tinlok includes full built-in support for UUID objects, via the UUID
class. This includes
parsing both Variant 1 (RFC 4122) and Variant 2 (Legacy Microsoft) UUIDs of all five versions.
Creating UUIDs¶
Tinlok has support for generating version 1 (MAC address based) and version 4 (psuedorandom) UUIDs.
Note
UUID generation is implemented via libuuid for Linux, and CreateUuid
on Windows. This
helps ensure global uniqueness whenever possible.
val v4 = UUID.uuid4()
assert(v4.version == UUID.Version.VERSION_FOUR)
val v1 = UUID.uuid1() // leaks information!
assert(v1.version == UUID.Version.VERSION_ONE)
Parsing UUIDs¶
Existing UUID data in binary form can be used with the primary constructor of the UUID class:
val data = byteArrayOf(...).toByteString()
val uuid = UUID(data)
UUIDs can be parsed from a string using fromString()
:
val uuid = UUID.fromString("c55ec9ff-cae0-406e-b0e6-0378f101285f")
Properties¶
The UUID class contains all the properties defined in RFC 4122, and enumerations for certain multiplexed fields.
RFC Name |
Property |
Description |
---|---|---|
|
|
The lower part of the timestamp. |
|
|
The middle part of the timestamp. |
|
|
The upper part of the timestamp, multiplexed with the version. |
|
|
The upper part of the clock sequence, multiplexed with the variant. |
|
|
The lower part of the clock sequence. |
|
|
The unique node identifier. |
N/A |
|
The version enum, extracted from |
N/A |
|
The variant enum, extracted from |