Uuid128

Namespace: System · struct

Implements: IComparable, IEquatable<Uuid128>, IComparable<Uuid128>, IEquatable<Guid>, ISliceSerializable, ISpanEncodable, ISpanFormattable, IFormattable, ISpanParsable<Uuid128>, IParsable<Uuid128>, IUtf8SpanFormattable, IUtf8SpanParsable<Uuid128>

Represents an RFC 4122 compliant 128-bit UUID

Remarks

You should use this type if you are primarily exchanging UUIDs with non-.NET platforms, that use the RFC 4122 byte ordering (big endian). The type System.Guid uses the Microsoft encoding (little endian) and is not compatible.

Constructors

Uuid128

Uuid128(Guid guid)

Constructs a Uuid128 from a Guid value

Uuid128(string value)

Constructs a Uuid128 from a string literal

Uuid128(Slice slice)

Constructs a Uuid128 from a Slice

Uuid128(byte[] bytes)

Constructs a Uuid128 from a byte array

Uuid128(ReadOnlySpan<byte> bytes)

Constructs a Uuid128 from a span of bytes

Uuid128(Int128 a)

Constructs a Uuid128 from an Int128 value

Uuid128(UInt128 a)

Constructs a Uuid128 from a UInt128 value

Uuid128(Uuid64 a, Uuid64 b)

Constructs a Uuid128 from its constituent parts

Uuid128(ulong a, ulong b)

Constructs a Uuid128 from its constituent parts

Uuid128(int a, short b, short c, byte[] d)

Constructs a Uuid128 from its constituent parts

Uuid128(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)

Constructs a Uuid128 from its constituent parts

Uuid128(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)

Constructs a Uuid128 from its constituent parts

Properties

ClockSequence

int ClockSequence { get; }

Returns the clock sequence field of this uuid.

Lower16

ushort Lower16 { get; }

Returns the 16 lower bits ........-....-....-....-........xxxx

Lower32

uint Lower32 { get; }

Returns the 32 lower bits ........-....-....-....-....xxxxxxxx

Lower48

Uuid48 Lower48 { get; }

Returns the 48 lower bits ........-....-....-....-xxxxxxxxxxxx

Lower64

ulong Lower64 { get; }

Returns the 64 lower bits ........-....-....-xxxx-xxxxxxxxxxxx

Lower80

Uuid80 Lower80 { get; }

Returns the 80 lower bits ........-....-xxxx-xxxx-xxxxxxxxxxxx

Lower96

Uuid96 Lower96 { get; }

Returns the 96 lower bits ........-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Node

long Node { get; }

Returns the node field of this uuid.

Timestamp

long Timestamp { get; }

Returns the timestamp field of this uuid.

Upper16

ushort Upper16 { get; }

Returns the 16 upper bits xxxx....-....-....-....-............

Upper32

uint Upper32 { get; }

Returns the 32 upper bits xxxxxxxx-....-....-....-............

Upper48

Uuid48 Upper48 { get; }

Returns the 48 upper bits xxxxxxxx-xxxx-....-....-............

Upper64

ulong Upper64 { get; }

Returns the 64 upper bits xxxxxxxx-xxxx-xxxx-....-............

Upper80

Uuid80 Upper80 { get; }

Returns the 80 upper bits xxxxxxxx-xxxx-xxxx-xxxx-............

Upper96

Uuid96 Upper96 { get; }

Returns the 80 upper bits xxxxxxxx-xxxx-xxxx-xxxx-xxxx........

Version

int Version { get; }

Returns the version field of this uuid.

Methods

CompareTo

int CompareTo(Uuid128 other)

int CompareTo(object obj)

Convert

static Guid Convert(ReadOnlySpan<byte> source)

Returns a Guid created from the contents of a span of bytes

Deconstruct

void Deconstruct(out Uuid64 high, out Uuid64 low)

Splits this 128-bit UUID into two 64-bit UUIDs

  • high — Receives the first 8 bytes (in network order) of this UUID
  • low — Receives the last 8 bytes (in network order) of this UUID

void Deconstruct(out ulong a, out uint b, out uint c)

Split this 128-bit UUID into two 64-bit numbers

  • axxxxxxxx-xxxx-xxxx-....-............
  • b........-....-....-xxxx-xxxx........
  • c........-....-....-....-....xxxxxxxx

void Deconstruct(out uint a, out uint b, out uint c, out uint d)

Split this 128-bit UUID into two 64-bit numbers

  • axxxxxxxx-....-....-....-............
  • b........-xxxx-xxxx-....-............
  • c........-....-....-xxxx-xxxx........
  • d........-....-....-....-....xxxxxxxx

Equals

bool Equals(object obj)

bool Equals(Uuid128 other)

bool Equals(Guid other)

FromBase62

static Uuid128 FromBase62(string buffer)

Parse a Base62 encoded string representation of an UUid64

static Uuid128 FromBase62(ReadOnlySpan<char> buffer)

Parse a Base62 encoded string representation of an UUid64

FromUInt128

static Uuid128 FromUInt128(UInt128 value)

Constructs a Uuid128 from a UInt128 value

FromUInt32

static Uuid128 FromUInt32(uint low)

Constructs a Uuid128 from a smaller 32-bit value

The 96 upper bits will be set to 0.

FromUInt64

static Uuid128 FromUInt64(ulong low)

Constructs a Uuid128 from a smaller 64-bit value

The 64 upper bits will be set to 0.

static Uuid128 FromUInt64(ulong high, ulong low)

Constructs a Uuid128 from two smaller 64-bit values

FromUpper32Lower96

static Uuid128 FromUpper32Lower96(uint hi, Uuid96 low)

Creates a Uuid128 from the upper 32-bit and lower 96-bit parts

  • hi — 32 upper bits (xxxxxxxx-....-....-....-............)
  • low — 96 lower bits (........-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

FromUpper32Middle32Lower64

static Uuid128 FromUpper32Middle32Lower64(uint hi, uint middle, ulong low)

Creates a Uuid128 from the upper 32-bit, middle 32-bit and lower 64-bit parts

  • hi — 32 upper bits (xxxxxxxx-....-....-....-............)
  • middle — 32 middle bits (........-xxxx-xxxx-....-............)
  • low — 64 lower bits (........-....-....-xxxx-xxxxxxxxxxxx)

FromUpper32Middle64Lower32

static Uuid128 FromUpper32Middle64Lower32(uint hi, ulong middle, uint low)

Creates a Uuid128 from the upper 32-bit, middle 64-bit and lower 32-bit parts

  • hi — 32 upper bits (xxxxxxxx-....-....-....-............)
  • middle — 64 middle bits (........-xxxx-xxxx-xxxx-xxxx........)
  • low — 32 lower bits (........-....-....-....-....xxxxxxxx)

FromUpper48Lower80

static Uuid128 FromUpper48Lower80(Uuid48 hi, Uuid80 low)

Creates a Uuid128 from the upper 48-bit and lower 80-bit parts

  • hi — 48 upper bits (xxxxxxxx-xxxx-....-....-............)
  • low — 80 lower bits (........-....-xxxx-xxxx-xxxxxxxxxxxx)

FromUpper64Lower64

static Uuid128 FromUpper64Lower64(ulong hi, ulong low)

Creates a Uuid128 from the upper 64-bit and lower 64-bit parts

  • hi — 64 upper bits (xxxxxxxx-xxxx-xxxx-....-............)
  • low — 64 lower bits (........-....-....-xxxx-xxxxxxxxxxxx)

static Uuid128 FromUpper64Lower64(Uuid64 hi, Uuid64 low)

Creates a Uuid128 from the upper 64-bit and lower 64-bit parts

  • hi — 64 upper bits (xxxxxxxx-xxxx-xxxx-....-............)
  • low — 64 lower bits (........-....-....-xxxx-xxxxxxxxxxxx)

FromUpper64Middle32Lower32

static Uuid128 FromUpper64Middle32Lower32(ulong hi, uint middle, uint low)

Creates a Uuid128 from the upper 64-bit, middle 32-bit and lower 32-bit parts

  • hi — 64 upper bits (xxxxxxxx-xxxx-xxxx-....-............)
  • middle — 32 middle bits (........-....-....-xxxx-xxxx........)
  • low — 32 lower bits (........-....-....-....-....xxxxxxxx)

FromUpper80Lower48

static Uuid128 FromUpper80Lower48(Uuid80 hi, Uuid48 low)

Creates a Uuid128 from the upper 80-bit and lower 48-bit parts

  • hi — 80 upper bits (xxxxxxxx-xxxx-xxxx-xxxx-............)
  • low — 48 lower bits (........-....-....-....-xxxxxxxxxxxx)

FromUpper96Lower32

static Uuid128 FromUpper96Lower32(Uuid96 hi, uint low)

Creates a Uuid128 from the upper 96-bit and lower 32-bit parts

  • hi — 96 upper bits (xxxxxxxx-xxxx-xxxx-xxxx-xxxx........)
  • low — 32 lower bits (........-....-....-....-....xxxxxxxx)

GetHashCode

int GetHashCode()

Increment

Uuid128 Increment(int value)

Increment the value of this UUID

  • value — Positive value

Returns: Incremented UUID

Uuid128 Increment(long value)

Increment the value of this UUID

  • value — Positive value

Returns: Incremented UUID

Uuid128 Increment(ulong value)

Increment the value of this UUID

  • value — Value to add to this UUID

Returns: Incremented UUID

NewUuid

static Uuid128 NewUuid()

Generate a new random 128-bit UUID.

Parse

static Uuid128 Parse(string input)

Parses a string into a Uuid128

  • input — The string to parse.

Returns: The result of parsing input.

static Uuid128 Parse(ReadOnlySpan<char> input)

Parses a span of characters into a Uuid128

  • input — The span of characters to parse.

Returns: The result of parsing input.

static Uuid128 Parse(string input, IFormatProvider provider)

Parses a string into a Uuid128

  • input — The string to parse.
  • provider — This argument is ignored.

Returns: The result of parsing input.

static Uuid128 Parse(ReadOnlySpan<char> input, IFormatProvider provider)

Parses a span of characters into a Uuid128

  • input — The span of characters to parse.
  • provider — This argument is ignored.

Returns: The result of parsing input.

static Uuid128 Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider provider = null)

Parses a span of UTF-8 characters into a Uuid128

  • utf8Text — The span of UTF-8 characters to parse.
  • provider — This argument is ignored.

Returns: The result of parsing utf8Text.

ParseExact

static Uuid128 ParseExact(string input, string format)

Parses a string representation of an UUid128

static Uuid128 ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format)

Parses a string representation of an UUid128

Read

static Uuid128 Read(byte[] source)

Reads a 128-bit Guid from a byte array.

  • source — Source buffer, that should either be empty, or hold at least 16 bytes.

Returns: Value stored in the buffer

static Uuid128 Read(Slice source)

Reads a 128-bit Guid from a byte buffer.

  • source — Source buffer, that should either be empty, or hold at least 16 bytes.

Returns: Value stored in the buffer

static Uuid128 Read(ReadOnlySpan<byte> source)

Reads a Uuid128 from a byte buffer.

  • source — Source buffer, that should either be empty, or hold at least 16 bytes.

Returns: Value stored in the buffer

ReadExact

static Uuid128 ReadExact(ReadOnlySpan<byte> source)

Reads a Uuid128 from a byte buffer that must contain exactly 16 bytes.

  • source — Source buffer of length 16.

Returns: Value stored in the buffer

ReadGuid

static Guid ReadGuid(ReadOnlySpan<byte> source)

Reads a 128-bit Guid from a byte buffer.

  • source — Source buffer, that should either be empty, or hold at least 16 bytes.

Returns: Value stored in the buffer

ReadGuidExact

static Guid ReadGuidExact(ReadOnlySpan<byte> source)

Reads a 128-bit Guid from a byte buffer that must contain exactly 16 bytes.

  • source — Source buffer of length 16.

Returns: Value stored in the buffer

Split

void Split(out Uuid64 high, out Uuid64 low)

Splits this 128-bit UUID into two 64-bit UUIDs

  • high — Receives the first 8 bytes (in network order) of this UUID
  • low — Receives the last 8 bytes (in network order) of this UUID

void Split(out ulong a, out ulong b)

Splits this 128-bit UUID into two 64-bit numbers

  • axxxxxxxx-xxxx-xxxx-....-............
  • b........-....-....-xxxx-xxxxxxxxxxxx

ToBase62

string ToBase62(bool padded = false)

Returns a string representation of the value of this instance of the Uuid128 structure in Base62 format.

  • padded — If false (default), the shortest possible literal is returned. If true, the literal is padded with 0 so that the resulting string can be sorted lexicographically

Returns: The value of this Uuid128, represented using the Base62 characters that are safe to be included in any Uri without escaping.

ToByteArray

byte[] ToByteArray()

Returns newly allocated array of bytes that represents this UUID

ToGuid

Guid ToGuid()

Returns the equivalent Guid

ToInt128

Int128 ToInt128()

Return the equivalent Int128

The integer correspond to the big-endian version of this instance serialized as a byte array

ToSlice

Slice ToSlice()

Returns a newly allocated Slice that represents this UUID

ToString

string ToString()

Returns a string representation of the value of this instance of the Uuid128 structure.

Returns: The value of this Guid, formatted by using the "D" format specifier as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

string ToString(string format)

Returns a string representation of the value of this instance of the Uuid128 structure.

  • format — A single format specifier that indicates how to format the value of this Uuid128. The format parameter can be "N", "D", "B", "P", "C", "Z" or "X". If format is null or an empty string (""), "D" is used.

Returns: The value of this Uuid128, represented as a series of lowercase hexadecimal digits in the specified format.

string ToString(string format, IFormatProvider provider)

Returns a string representation of the value of this instance of the Uuid128 structure.

  • format — A single format specifier that indicates how to format the value of this Uuid128. The format parameter can be "N", "D", "B", "P", "C", "Z" or "X". If format is null or an empty string (""), "D" is used.
  • provider — An object that supplies culture-specific formatting information.

Returns: The value of this Uuid128, represented as a series of lowercase hexadecimal digits in the specified format.

ToUInt128

UInt128 ToUInt128()

Return the equivalent UInt128

The integer correspond to the big-endian version of this instance serialized as a byte array

TryFormat

bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = null, IFormatProvider provider = null)

Tries to format the value of the current instance into the provided span of characters.

  • destination — The span in which to write this instance's value formatted as a span of characters.
  • charsWritten — When this method returns, contains the number of characters that were written in destination.
  • format — A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.
  • provider — This parameter is ignored.

Returns: true if the formatting was successful; otherwise, false.

bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format = null, IFormatProvider provider = null)

Tries to format the value of the current instance UTF-8 into the provided span of bytes.

  • utf8Destination — The span in which to write this instance's value formatted as a span of bytes.
  • bytesWritten — When this method returns, contains the number of bytes that were written in utf8Destination.
  • format — A span containing the characters that represent a standard or custom format string that defines the acceptable format for utf8Destination.
  • provider — This parameter is ignored.

Returns: true if the formatting was successful; otherwise, false.

TryParse

static bool TryParse(ReadOnlySpan<byte> utf8Text, out Uuid128 result)

Tries to parse a span of UTF-8 characters into a Uuid128.

  • utf8Text — The span of UTF-8 characters to parse.
  • result — On return, contains the result of successfully parsing utf8Text or an undefined value on failure.

Returns: true if utf8Text was successfully parsed; otherwise, false.

static bool TryParse(string input, out Uuid128 result)

Tries to parse a string into a Uuid128

  • input — The string to parse.
  • result — When this method returns, contains the result of successfully parsing input, or an undefined value on failure.

Returns: true if input was successfully parsed; otherwise, false.

static bool TryParse(ReadOnlySpan<char> input, out Uuid128 result)

Tries to parse a span of characters into a Uuid128

  • input — The span of characters to parse.
  • result — When this method returns, contains the result of successfully parsing input, or an undefined value on failure.

Returns: true if input was successfully parsed; otherwise, false.

static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider provider, out Uuid128 result)

Tries to parse a span of UTF-8 characters into a Uuid128.

  • utf8Text — The span of UTF-8 characters to parse.
  • provider — An object that provides culture-specific formatting information about utf8Text.
  • result — On return, contains the result of successfully parsing utf8Text or an undefined value on failure.

Returns: true if utf8Text was successfully parsed; otherwise, false.

static bool TryParse(string input, IFormatProvider provider, out Uuid128 result)

Tries to parse a string into a Uuid128

  • input — The string to parse.
  • provider — This argument is ignored.
  • result — When this method returns, contains the result of successfully parsing input, or an undefined value on failure.

Returns: true if input was successfully parsed; otherwise, false.

static bool TryParse(ReadOnlySpan<char> input, IFormatProvider provider, out Uuid128 result)

Tries to parse a span of characters into a Uuid128

  • input — The span of characters to parse.
  • provider — This argument is ignored.
  • result — When this method returns, contains the result of successfully parsing input, or an undefined value on failure.

Returns: true if input was successfully parsed; otherwise, false.

TryParseBase62

static bool TryParseBase62(string input, out Uuid128 result)

static bool TryParseBase62(ReadOnlySpan<char> input, out Uuid128 result)

TryParseExact

static bool TryParseExact(string input, string format, out Uuid128 result)

Parse a string representation of an UUid128

static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, out Uuid128 result)

Parse a string representation of an UUid128

TryRead

static bool TryRead(ReadOnlySpan<byte> source, out Uuid128 result)

Reads a Uuid128 from a byte buffer, if it is large enough.

  • source — Source buffer, that should have at least 16 bytes.
  • result — Value stored in the buffer

Returns: true if the buffer was large enough; otherwise, false

TryReadExact

static bool TryReadExact(ReadOnlySpan<byte> source, out Uuid128 result)

Reads a Uuid128 from a byte buffer that must contain exactly 16 bytes.

  • source — Source buffer of length 16.
  • result — Value stored in the buffer

Returns: true if the buffer has a length of 16; otherwise, false

TryWrite

static bool TryWrite(in Guid value, Span<byte> buffer)

Writes a Guid into a buffer, if it is large enough.

  • value — Value to write
  • buffer — Destination buffer, that must have a length of at least 16 bytes.

Returns: true if the buffer was large enough; otherwise, false

TryWriteTo

bool TryWriteTo(Span<byte> buffer)

Writes the bytes of this instance to the specified buffer, if it is large enough

  • buffer — Buffer where the bytes will be written to, with a capacity of at least 16 bytes

Returns: true if buffer was large enough; otherwise, false.

bool TryWriteTo(Span<byte> buffer, out int bytesWritten)

Writes the bytes of this instance to the specified buffer, if it is large enough

  • buffer — Buffer where the bytes will be written to, with a capacity of at least 16 bytes
  • bytesWritten — Receives the number of bytes written (either 16 or 0)

Returns: true if buffer was large enough; otherwise, false.

Write

static void Write(in Guid value, Span<byte> buffer)

Writes a Guid into a buffer.

  • value — Value to write
  • buffer — Destination buffer, that must have a length of at least 16 bytes.

WriteTo

void WriteTo(Span<byte> buffer)

Writes the bytes of this instance to the specified buffer

  • buffer — Buffer where the bytes will be written to, with a capacity of at least 16 bytes

void WriteTo(ref SliceWriter writer)

Writes this UUID to the specified writer

WriteToUnsafe

void WriteToUnsafe(Span<byte> buffer)

[OBSOLETE] => WriteTo()

Fields

AllBitsSet

static readonly Uuid128 AllBitsSet

Uuid128 with all bits set to 1 ("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")

Empty

static readonly Uuid128 Empty

Uuid128 with all bits set to 0 ("00000000-0000-0000-0000-000000000000")

MaxValue

static readonly Uuid128 MaxValue

Uuid128 with all bits set to 0 ("00000000-0000-0000-0000-000000000000")

MinValue

static readonly Uuid128 MinValue

Uuid128 with all bits set to 0 ("00000000-0000-0000-0000-000000000000")

SizeOf

const int SizeOf

Size is 16 bytes