package uuidm

  1. Overview
  2. Docs

Universally unique identifiers (UUIDs).

Uuidm implements 128 bits universally unique identifiers version 3, 5 (name based with MD5, SHA-1 hashing) and 4 (random based) according to RFC 4122.

References

v0.9.6 - homepage

UUIDs

type t

The type for UUIDs.

type version = [
  1. | `V3 of t * string
    (*

    Name based with MD5 hashing

    *)
  2. | `V4
    (*

    Random based

    *)
  3. | `V5 of t * string
    (*

    Name based with SHA-1 hasing

    *)
]

The type for UUID versions and generation parameters. `V3 and `V5 specify a namespace and a name for the generation. `V4 is random based with a private state seeded with Random.State.make_self_init, use v4_gen to specify your own seed.

val v : version -> t

v version is an UUID of the given version.

val v3 : t -> string -> t

v3 ns n is create `V3 (ns, n).

val v5 : t -> string -> t

v5 ns n is create `V5 (ns, n).

val v4_gen : Random.State.t -> unit -> t

v4 seed is a function that generates random version 4 UUIDs with the given seed.

Constants

val nil : t

nil is the nil UUID.

val ns_dns : t

ns_dns is the DNS namespace UUID.

val ns_url : t

ns_url is the URL namespace UUID.

val ns_oid : t

ns_oid is the ISO OID namespace UUID.

val ns_X500 : t

ns_dn is the X.500 DN namespace UUID.

Comparing

val compare : t -> t -> int

compare u u' totally orders u and u'.

val equal : t -> t -> bool

equal u u' is true iff u and u' are equal.

Conversion with UUID binary representation

val of_bytes : ?pos:int -> string -> t option

of_bytes pos s is the UUID represented by the 16 bytes starting at pos (defaults to 0) in s. Returns None if the string is not long enough.

val to_bytes : t -> string

to_bytes u is u as a 16 bytes long string.

Conversion with UUID US-ASCII representation

val of_string : ?pos:int -> string -> t option

of_string pos s converts the substring of s starting at pos (defaults to 0) of the form "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" where X is a lower or upper case hexadecimal number to an UUID. Returns None if a parse error occured.

val to_string : ?upper:bool -> t -> string

to_string u is u as a string of the form "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" where X is a lower case hexadecimal number (or upper if upper is true).

Pretty-printing

val pp : Format.formatter -> t -> unit

pp ppf u formats u on ppf like to_string would do. It is unspecified whether upper or lower case hexadecimal numbers are used.

val pp_string : ?upper:bool -> Format.formatter -> t -> unit

pp_string ?upper ppf u formats u on ppf like to_string would do.