128BITmoonuuididentifier notes
MoonBit · RFC 9562

reference · one package

API reference

Every public value, function, type and method in moonbitstack/moonuuid. Signatures are the package interface; the notes are the doc comments.

Nothing matches that filter.

Values

Constants the package exports: the nil and max identifiers, the four namespaces, and the offset between the Gregorian and Unix epochs.

gregorian_offsetvaluelet gregorian_offset : Int64

100-nanosecond intervals between 1582-10-15, where version 1 and 6 timestamps start, and 1970-01-01.

maxvaluelet max : Uuid

The max identifier, all ones.

namespace_dnsvaluelet namespace_dns : Uuid

The namespaces RFC 9562 assigns for names that are domain names, URLs, ISO OIDs and X.500 distinguished names.

namespace_oidvaluelet namespace_oid : Uuid
namespace_urlvaluelet namespace_url : Uuid
namespace_x500valuelet namespace_x500 : Uuid
nilvaluelet nil : Uuid

The nil identifier, all zeros.

Functions

Free functions that read text or make one version each.

parsefunctionfn parse(text : StringView) -> Uuid raise Refused

Text in any of the spellings in use: canonical, with or without hyphens, in braces, with the urn:uuid: prefix; any case.

ticks_offunctionfn ticks_of(unix_nanos : Int64) -> Int64

A version 1 or 6 timestamp from nanoseconds since 1970.

v1functionfn v1(ticks~ : Int64, clock_seq~ : Int32, node~ : Int64) -> Uuid

Time-based: a 60-bit timestamp from ticks_of, a 14-bit clock sequence and a 48-bit node, laid out with the low time bits first.

v3functionfn v3(space : Uuid, name : StringView) -> Uuid

Name-based with MD5: the same namespace and name always give the same identifier. The name is hashed as UTF-8.

v4functionfn v4(random : BytesView) -> Uuid raise Refused

Random: 122 of the 16 bytes given are kept.

v5functionfn v5(space : Uuid, name : StringView) -> Uuid

Name-based with SHA-1, preferred over version 3.

v6functionfn v6(ticks~ : Int64, clock_seq~ : Int32, node~ : Int64) -> Uuid

Version 1's fields with the timestamp's high bits first, so the identifiers sort in time order.

v7functionfn v7(millis~ : Int64, random : BytesView) -> Uuid raise Refused

Milliseconds since 1970 in the top 48 bits, then 74 bits from the 10 random bytes given: a 42-bit counter whose top bit starts clear, so a generator can count up within a millisecond, and 32 random bits.

v8functionfn v8(custom : BytesView) -> Uuid raise Refused

Custom: 122 bits of the 16 bytes given, laid out as the caller likes; only version and variant are written over.

Types

The identifier and the generator, with the methods that read or write them.

Generatorstructstruct Generator

Identifiers from a clock and a source of random bytes the caller supplies, keeping what the time-based versions need between calls: version 1 and 6 timestamps never repeat or go back, and version 7 ids made within one millisecond count up, so they sort in the order made.

fn Generator::new(clock~ : () -> Int64, random~ : &@moonrand.Source) -> Generator

clock gives nanoseconds since 1970; random is where the random bits come from: @system.source from moonrand/system in a program, or a Replay of fixed bytes in a test that wants the same ids every run.

fn Generator::v1(self : Generator, node~ : Int64, clock_seq? : Int32) -> Uuid raise Refused

Version 1 with node; the clock sequence is random unless given.

fn Generator::v4(self : Generator) -> Uuid raise Refused

Version 4 from 16 random bytes.

fn Generator::v6(self : Generator, node~ : Int64, clock_seq? : Int32) -> Uuid raise Refused

Version 6 with node; the clock sequence is random unless given.

fn Generator::v7(self : Generator) -> Uuid raise Refused

Version 7. Within one millisecond the counter goes up by one with a fresh random tail; when the clock steps back, the millisecond after the last one is used; when the counter runs out, the millisecond moves on.

Uuidstructstruct Uuid

A 128-bit identifier as RFC 9562 lays it out. Compared, hashed and ordered by its bytes, so a sorted list of time-ordered ids is in time order.

fn Uuid::bytes(self : Uuid) -> Bytes

The 16 bytes, most significant first.

fn Uuid::clock_seq(self : Uuid) -> Int32

The 14-bit clock sequence of versions 1 and 6.

fn Uuid::compare(Self, Self) -> Int32

From Compare.

fn Uuid::equal(Self, Self) -> Bool

From Eq.

fn Uuid::from_json(Json, @json.JsonPath) -> Self raise @json.JsonDecodeError

Any spelling parse reads.

fn Uuid::hash(Self) -> Int32

From Hash.

fn Uuid::hash_combine(Self, Hasher) -> Unit

From Hash.

fn Uuid::hex(self : Uuid) -> String

The 32 hexadecimal digits, lowercase, without hyphens.

fn Uuid::node(self : Uuid) -> Int64

The 48-bit node of versions 1 and 6.

fn Uuid::not_equal(Self, Self) -> Bool

From Eq.

fn Uuid::of_bytes(bytes : BytesView) -> Uuid raise Refused

The identifier from its 16 bytes, most significant first.

fn Uuid::of_parts(hi : UInt64, lo : UInt64) -> Uuid

The identifier from its high and low 64 bits.

fn Uuid::op_ge(Self, Self) -> Bool

From Compare.

fn Uuid::op_gt(Self, Self) -> Bool

From Compare.

fn Uuid::op_le(Self, Self) -> Bool

From Compare.

fn Uuid::op_lt(Self, Self) -> Bool

From Compare.

fn Uuid::output(Self, &Logger) -> Unit

The canonical text: 8-4-4-4-12 lowercase hexadecimal digits.

fn Uuid::parts(self : Uuid) -> (UInt64, UInt64)

The high and low 64 bits.

fn Uuid::time(self : Uuid) -> Int64

The timestamp the fields hold: 100-nanosecond intervals since 1582-10-15 for versions 1 and 6, milliseconds since 1970 for version 7, the version 1 reading of the fields otherwise.

fn Uuid::to_json(Self) -> Json

The canonical text.

fn Uuid::to_repr(Self) -> @debug.Repr

From Debug.

fn Uuid::to_string(Self) -> String

The canonical text: 8-4-4-4-12 lowercase hexadecimal digits.

fn Uuid::urn(self : Uuid) -> String

urn:uuid: and the canonical text, as RFC 9562 names an identifier.

fn Uuid::variant(self : Uuid) -> Variant

The variant its bits name.

fn Uuid::version(self : Uuid) -> Int32?

The version, 1 to 8 for the ones RFC 9562 defines; None when the variant is not RFC 9562's, where the version bits mean nothing.

implementsFromJsonShowToJson

Variantenumenum Variant

Who an identifier's variant bits say it belongs to.

  • Ncs Reserved for NCS backward compatibility.
  • Rfc RFC 9562, the variant every version here writes.
  • Microsoft Reserved for Microsoft backward compatibility.
  • Future Reserved for future definition.
fn Variant::equal(Self, Self) -> Bool

From Eq.

fn Variant::not_equal(Self, Self) -> Bool

From Eq.

fn Variant::output(Self, &Logger) -> Unit

From Show.

fn Variant::to_repr(Self) -> @debug.Repr

From Debug.

fn Variant::to_string(Self) -> String

From Show.

implementsShow

Errors

The refusal that a parse or a byte-count check raises.

Refusedsuberrorsuberror Refused

Why text or bytes are not a UUID.

  • Malformed(at~ : Int32, reason~ : String) Text that is not 32 hexadecimal digits once braces, hyphens and the urn:uuid: prefix are set aside; at is the offending character.
  • Size(want~ : Int32, got~ : Int32) Bytes of the wrong length.
  • Random(@moonrand.Unavailable) The generator's random source could not give what an identifier needs.
fn Refused::equal(Self, Self) -> Bool

From Eq.

fn Refused::not_equal(Self, Self) -> Bool

From Eq.

fn Refused::output(Self, &Logger) -> Unit

From Show.

fn Refused::to_repr(Self) -> @debug.Repr

From Debug.

fn Refused::to_string(Self) -> String

From Show.

implementsShow