Uuid64
Namespace: System · struct
Implements: IEquatable<Uuid64>, IComparable<Uuid64>, IEquatable<ulong>, IComparable<ulong>, IEquatable<long>, IComparable<long>, IEquatable<Slice>, ISpanFormattable, IFormattable, ISpanEncodable, ISpanParsable<Uuid64>, IParsable<Uuid64>, IEquatable<ReadOnlySpan<byte>>
Represents a 64-bit UUID that is stored in high-endian format in the output
Constructors
Uuid64
Uuid64(ulong value)
Creates a new Uuid64 from a 64-bit unsigned integer
Uuid64(long value)
Creates a new Uuid64 from a 64-bit signed integer
Uuid64(uint a, uint b)
Creates a new Uuid64 from two 32-bits components
a— Upper 32 bits (XXXXXXXX-........)b— Lower 32 bits (........-XXXXXXXX)
Uuid64(ushort a, long b)
Creates a new Uuid64 from a 16-bit and 48-bits components
a— Upper 16 bits (XXXX....-........)b— Lower 48 bits (....XXXX-XXXXXXXX)
Uuid64(ushort a, ushort b, ushort c, ushort d)
Creates a new Uuid64 from four 16-bits components
a— Upper 16 bits of the first part (XXXX....-........)b— Upper 16 bits of the first part (....XXXX-........)c— Upper 16 bits of the second part (........-XXXX....)d— Lower 16 bits of the second part (........-....XXXX)
Properties
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 ....xxxx-xxxxxxxx
Upper16
ushort Upper16 { get; }
Returns the 48 upper bits xxxx....-........
Upper32
uint Upper32 { get; }
Returns the 32 upper bits xxxxxxxxx-........
Upper48
Uuid48 Upper48 { get; }
Returns the 48 upper bits xxxxxxxx-xxxx....
Methods
CompareTo
int CompareTo(Uuid64 other)
int CompareTo(ulong other)
int CompareTo(long other)
Deconstruct
void Deconstruct(out uint a, out uint b)
Split into two 32-bit halves
a—xxxxxxxx-........b—........-xxxxxxxx
void Deconstruct(out ushort a, out ushort b, out ushort c, out ushort d)
Split into two halves
a—xxxx....-........b—....xxxx-........c—........-xxxx....d—........-....xxxx
Equals
bool Equals(object obj)
bool Equals(Uuid64 other)
bool Equals(ulong other)
bool Equals(long other)
bool Equals(Slice other)
bool Equals(ReadOnlySpan<byte> other)
FromBase62
static Uuid64 FromBase62(string buffer)
Parse a Base62 encoded string representation of an UUid64
static Uuid64 FromBase62(ReadOnlySpan<char> buffer)
Parse a Base62 encoded string representation of an UUid64
FromInt64
static Uuid64 FromInt64(long value)
FromUInt64
static Uuid64 FromUInt64(ulong value)
FromUpper16Lower48
static Uuid64 FromUpper16Lower48(ushort hi, Uuid48 low)
Creates a Uuid64 from the upper 16-bit and lower 48-bit parts
hi— 16 upper bits (xxxx....-........)low— 48 lower bits (....xxxx-xxxxxxxx)
static Uuid64 FromUpper16Lower48(ushort hi, ulong low)
Creates a Uuid64 from the upper 16-bit and lower 48-bit parts
hi— 16 upper bits (xxxx....-........)low— 48 lower bits (....xxxx-xxxxxxxx)
FromUpper32Lower32
static Uuid64 FromUpper32Lower32(uint hi, uint low)
Creates a Uuid64 from the upper 32-bit and lower 32-bit parts
hi— 32 upper bits (xxxxxxxx-........)low— 32 lower bits (........-xxxxxxxx)
FromUpper48Lower16
static Uuid64 FromUpper48Lower16(ulong hi, ushort low)
Creates a Uuid64 from the upper 48-bit and lower 16-bit parts
hi— 48 upper bits (xxxxxxxx-xxxx....)low— 16 lower bits (........-....xxxx)
static Uuid64 FromUpper48Lower16(Uuid48 hi, ushort low)
Creates a Uuid64 from the upper 48-bit and lower 16-bit parts
hi— 48 upper bits (xxxxxxxx-xxxx....)low— 16 lower bits (........-....xxxx)
GetHashCode
int GetHashCode()
NewUuid
static Uuid64 NewUuid()
Generate a new random 64-bit UUID.
If you need sequential or cryptographic uuids, you should use a different generator.
Parse
static Uuid64 Parse(string input)
Parses a string into a Uuid64
input— The string to parse.
Returns: The result of parsing input.
static Uuid64 Parse(ReadOnlySpan<char> input)
Parses a string into a Uuid128
input— The string to parse.
Returns: The result of parsing input.
static Uuid64 Parse(string input, IFormatProvider provider)
Parses a string into a Uuid64
input— The string to parse.provider— This argument is ignored.
Returns: The result of parsing input.
static Uuid64 Parse(ReadOnlySpan<char> 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.
Random
static Uuid64 Random(Random rng)
Generates a new random 64-bit UUID, using the specified random number generator
rng— Random number generator
Returns: A random Uuid64 that is less than MaxValue
static Uuid64 Random(Random rng, Uuid64 maxValue)
Generates a new random 64-bit UUID, using the specified random number generator
rng— Random number generatormaxValue— The exclusive upper bound of the random UUID to be generated.
Returns: A random Uuid64 that is less than maxValue
static Uuid64 Random(Random rng, ulong maxValue)
Generates a new random 64-bit UUID, using the specified random number generator
rng— Random number generatormaxValue— The exclusive upper bound of the random UUID to be generated.
Returns: A random Uuid64 that is less than maxValue
static Uuid64 Random(Random rng, Uuid64 minValue, Uuid64 maxValue)
Generates a new random 64-bit UUID, using the specified random number generator
rng— Random number generatorminValue— The inclusive lower bound of the random UUID to be generated.maxValue— The exclusive upper bound of the random UUID to be generated.
Returns: A random Uuid64 that is greater than or equal to minValue and less than maxValue
static Uuid64 Random(Random rng, ulong minValue, ulong maxValue)
Generates a new random 64-bit UUID, using the specified random number generator
rng— Random number generatorminValue— The inclusive lower bound of the random UUID to be generated.maxValue— The exclusive upper bound of the random UUID to be generated.
Returns: A random Uuid64 that is greater than or equal to minValue and less than maxValue
Read
static Uuid64 Read(byte[] value)
Reads a 64-bit UUID from a byte array
value— Array of bytes that is either empty, or holds at least 8 bytes
Returns: Corresponding Uuid64 if the read is successful
If value is larger than 8 bytes, the additional bytes will be ignored.
static Uuid64 Read(Slice value)
Reads a 64-bit UUID from slice of memory
value— Slice of bytes that is either empty, or holds at least 8 bytes
Returns: Corresponding Uuid64 if the read is successful
If value is larger than 8 bytes, the additional bytes will be ignored.
static Uuid64 Read(ReadOnlySpan<byte> value)
Reads a 64-bit UUID from slice of memory
value— Span of bytes that is either empty, or holds at least 8 bytes
Returns: Corresponding Uuid64 if the read is successful
If value is larger than 8 bytes, the additional bytes will be ignored.
ToBase62
string ToBase62(bool padded = false)
Encodes this value into a base-62 encoded text literal
This literal can be parsed back into a by calling or
ToByteArray
byte[] ToByteArray()
Converts this instance into a byte array
ToInt64
long ToInt64()
Returns the equivalent 64-bit signed integer
ToSlice
Slice ToSlice()
Converts this instance into a Slice
ToString
string ToString()
Returns a string representation of the value of this instance.
Returns: String using the format "xxxxxxxx-xxxxxxxx", where 'x' is a lower-case hexadecimal digit
Strings returned by this method will always to 17 characters long.
string ToString(string format)
Returns a string representation of the value of this Uuid64 instance, according to the provided format specifier.
format— A single format specifier that indicates how to format the value of this Guid. The format parameter can be "D", "B", "X", "G", "Z" or "N". If format is null or an empty string (""), "D" is used.
Returns: The value of this Uuid64, using the specified format.
See for a description of the different formats
string ToString(string format, IFormatProvider formatProvider)
Returns a string representation of the value of this instance of the Uuid64 class, according to the provided format specifier and culture-specific format information.
format— A single format specifier that indicates how to format the value of this Guid. The format parameter can be "D", "N", "Z", "R", "X" or "B". If format is null or an empty string (""), "D" is used.formatProvider— An object that supplies culture-specific formatting information. Only used for the "R" format.
Returns: The value of this Uuid64, using the specified format.
The D format encodes the value as two groups of 8 hexadecimal digits, separated by a hyphen: "01234567-89abcdef" (17 characters).The X format encodes the value as a single group of 16 hexadecimal digits: "0123456789abcdef" (16 characters).The B format is equivalent to the D format, but surrounded with '{' and '}': "{01234567-89abcdef}" (19 characters).The R format encodes the value as a decimal number "1234567890" (1 to 20 characters) which can be parsed as an UInt64 without loss.The C format uses a compact base-62 encoding that preserves lexicographical ordering, composed of digits, uppercase alpha and lowercase alpha, suitable for compact representation that can fit in a querystring.The Z format is equivalent to the C format, but with extra padding so that the string is always 11 characters long.
ToUInt64
ulong ToUInt64()
Returns the equivalent 64-bit unsigned integer
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 indestination.format— A span containing the characters that represent a standard or custom format string that defines the acceptable format fordestination.provider— An optional object that supplies culture-specific formatting information fordestination.
Returns: true if the formatting was successful; otherwise, false.
TryParse
static bool TryParse(string input, out Uuid64 result)
Tries to parse a string into a Uuid64
input— The string to parse.result— When this method returns, contains the result of successfully parsinginput, or an undefined value on failure.
Returns: true if input was successfully parsed; otherwise, false.
static bool TryParse(ReadOnlySpan<char> input, out Uuid64 result)
Tries to parse a span of characters into a Uuid64
input— The span of characters to parse.result— When this method returns, contains the result of successfully parsinginput, or an undefined value on failure.
Returns: true if input was successfully parsed; otherwise, false.
static bool TryParse(ReadOnlySpan<byte> utf8Text, out Uuid64 result)
Tries to parse a span of UTF-8 bytes into a Uuid64
utf8Text— The span of characters to parse.result— When this method returns, contains the result of successfully parsingutf8Text, or an undefined value on failure.
Returns: true if utf8Text was successfully parsed; otherwise, false.
static bool TryParse(string input, IFormatProvider provider, out Uuid64 result)
Tries to parse a string into a Uuid64
input— The string to parse.provider— This argument is ignored.result— When this method returns, contains the result of successfully parsinginput, or an undefined value on failure.
Returns: true if input was successfully parsed; otherwise, false.
static bool TryParse(ReadOnlySpan<char> input, IFormatProvider provider, out Uuid64 result)
Tries to parse a span of characters into a Uuid64
input— The span of characters to parse.provider— This argument is ignored.result— When this method returns, contains the result of successfully parsinginput, or an undefined value on failure.
Returns: true if input was successfully parsed; otherwise, false.
TryParseBase62
static bool TryParseBase62(string input, out Uuid64 result)
Tries to parse a base-62 encoded literal into a Uuid64
static bool TryParseBase62(ReadOnlySpan<char> input, out Uuid64 result)
Tries to parse a base-62 encoded literal into a Uuid64
TryRead
static bool TryRead(byte[] value, out Uuid64 result)
Reads a 64-bit UUID from slice of memory
value— Array of bytes that is either empty, or holds at least 8 bytesresult— Corresponding Uuid64, if the read is successful
Returns: true if value has length 0 or at least 8; otherwise, false.
If value is larger than 8 bytes, the additional bytes will be ignored.
static bool TryRead(Slice value, out Uuid64 result)
Reads a 64-bit UUID from slice of memory
value— Slice of bytes that is either empty, or holds at least 8 bytesresult— Corresponding Uuid64, if the read is successful
Returns: true if value has length 0 or at least 8; otherwise, false.
If value is larger than 8 bytes, the additional bytes will be ignored.
static bool TryRead(ReadOnlySpan<byte> value, out Uuid64 result)
Reads a 64-bit UUID from slice of memory
value— Span of bytes that is either empty, or holds at least 8 bytesresult— Corresponding Uuid64, if the read is successful
Returns: true if value has length 0 or at least 8; otherwise, false.
If value is larger than 8 bytes, the additional bytes will be ignored.
TryWriteTo
bool TryWriteTo(Span<byte> destination)
Writes the bytes of this instance to the specified destination, if it is large enough.
destination— Buffer where the bytes will be written to, with a capacity of at least 8 bytes
Returns: true if the destination is large enough; otherwise, false
bool TryWriteTo(Span<byte> destination, out int bytesWritten)
Writes the bytes of this instance to the specified destination, if it is large enough.
destination— Buffer where the bytes will be written to, with a capacity of at least 8 bytesbytesWritten— Receives the number of bytes written (either8or0)
Returns: true if the destination is large enough; otherwise, false
WriteTo
void WriteTo(Span<byte> destination)
Writes the bytes of this instance to the specified destination
destination— Buffer where the bytes will be written to, with a capacity of at least 8 bytes
Fields
AllBitsSet
static readonly Uuid64 AllBitsSet
Uuid64 with all bits set to 1 ("FFFFFFFF-FFFFFFFF")
Empty
static readonly Uuid64 Empty
Uuid64 with all bits set to 0 ("00000000-00000000")
MaxValue
static readonly Uuid64 MaxValue
Uuid64 with all bits set to 1 ("FFFFFFFF-FFFFFFFF")
MinValue
static readonly Uuid64 MinValue
Uuid64 with all bits set to 0 ("00000000-00000000")
One
static readonly Uuid64 One
Uuid64 with only bit 0 set to 1 ("00000000-00000001")
SizeOf
const int SizeOf
Size is 8 bytes