A UUID is a Universally Unique Identifier. It is a 128-bit number generated either randomly or according to some inscrutable algorithm, depending on the UUID version used.
Here, we implement a data structure for holding and formatting UUIDs. To generate a UUID, use one of the other modules in the UUID package. You can also create a UUID by parsing a string containing a textual representation of a UUID, or by providing the constituent bytes.
struct Uuid #
This struct represents a UUID. It offers static members for creating and parsing UUIDs. This struct treats a UUID as an opaque type. The specification has fields for time, version, client MAC address, and several other data points, but these are meaningless for most applications and means of generating a UUID.
There are versions of UUID generation involving the system time and MAC address. These are not used for several reasons: - One version contains identifying information, which is undesirable. - Ensuring uniqueness between processes requires inter-process communication. This would be unreasonably slow and complex. - Obtaining the MAC address is a system-dependent operation and beyond the scope of this module. - Using Java and .NET as a guide, they only implement randomized creation of UUIDs, not the MAC address/time based generation.

When generating a random UUID, use a carefully seeded random number generator. A poorly chosen seed may produce undesirably consistent results.

Uuid opCall(ubyte[] data) [public, static] #
Copy the givent bytes into a UUID. If you supply more or fewer than 16 bytes, throws an IllegalArgumentException.
Uuid parse(char[] value) [public, static] #
Attempt to parse the representation of a UUID given in value. If the value is not in the correct format, throw IllegalArgumentException. If the value is in the correct format, return a UUID representing the given value.
The following is an example of a UUID in the expected format: 67e55044-10b1-426f-9247-bb680e5fe0c8
bool tryParse(char[] value, out Uuid uuid) [public, static] #
Attempt to parse the representation of a UUID given in value. If the value is not in the correct format, return false rather than throwing an exception. If the value is in the correct format, set uuid to represent the given value.
The following is an example of a UUID in the expected format: 67e55044-10b1-426f-9247-bb680e5fe0c8
Uuid random(Random)(Random generator) [public, static] #
Generate a UUID based on the given random number generator. The generator must have a method 'uint natural()' that returns a random number. The generated UUID conforms to version 4 of the specification.
Uuid empty() [public, static] #
Return an empty UUID (with all bits set to 0). This doesn't conform to any particular version of the specification. It's equivalent to using an uninitialized UUID. This method is provided for clarity.
ubyte[] toBytes() [public] #
Get a copy of this UUID's value as an array of unsigned bytes.
ubyte format() [public] #
Gets the version of this UUID. RFC 4122 defines five types of UUIDs: - Version 1 is based on the system's MAC address and the current time. - Version 2 uses the current user's userid and user domain in addition to the time and MAC address. - Version 3 is namespace-based, as generated by the NamespaceGenV3 module. It uses MD5 as a hash algorithm. RFC 4122 states that version 5 is preferred over version 3. - Version 4 is generated randomly. - Version 5 is like version 3, but uses SHA-1 rather than MD5. Use the NamespaceGenV5 module to create UUIDs like this.
The following additional versions exist: - Version 0 is reserved for backwards compatibility. - Version 6 is a non-standard Microsoft extension. - Version 7 is reserved for future use.
char[] toString() [public] #
Get the canonical string representation of a UUID. The canonical representation is in hexidecimal, with hyphens inserted after the eighth, twelfth, sixteenth, and twentieth digits. For example: 67e55044-10b1-426f-9247-bb680e5fe0c8 This is the format used by the parsing functions.
bool opEquals(Uuid other) [public] #
Determines if this UUID has the same value as another.
hash_t toHash() [public] #
Get a hash code representing this UUID.
interface UuidGen #
A base interface for any UUID generator for UUIDs. That is, this interface is specified so that you write your code dependent on a UUID generator that takes an arbitrary random source, and easily switch to a different random source. Since the default uses KISS, if you find yourself needing more secure random numbers, you could trivially switch your code to use the Mersenne twister, or some other PRNG.
You could also, if you wish, use this to switch to deterministic UUID generation, if your needs require it.
class RandomGen(TRandom) : UuidGen #
Given a random number generator conforming to Tango's standard random interface, this will generate random UUIDs according to version 4 of RFC 4122.