Uuid48
Namespace: System · struct
Implements: IEquatable<Uuid48>, IComparable<Uuid48>, IEquatable<ulong>, IComparable<ulong>, IEquatable<long>, IComparable<long>, IEquatable<uint>, IComparable<uint>, IEquatable<int>, IComparable<int>, IEquatable<Slice>, ISpanFormattable, IFormattable, ISpanEncodable, IComparisonOperators<Uuid48, Uuid48, bool>, IEqualityOperators<Uuid48, Uuid48, bool>, IAdditiveIdentity<Uuid48, int>, IAdditiveIdentity<Uuid48, uint>, IAdditiveIdentity<Uuid48, long>, IAdditiveIdentity<Uuid48, ulong>, IIncrementOperators<Uuid48>, IAdditionOperators<Uuid48, int, Uuid48>, IAdditionOperators<Uuid48, long, Uuid48>, IAdditionOperators<Uuid48, uint, Uuid48>, IAdditionOperators<Uuid48, ulong, Uuid48>, IDecrementOperators<Uuid48>, ISubtractionOperators<Uuid48, int, Uuid48>, ISubtractionOperators<Uuid48, long, Uuid48>, ISubtractionOperators<Uuid48, uint, Uuid48>, ISubtractionOperators<Uuid48, ulong, Uuid48>, IBitwiseOperators<Uuid48, Uuid48, Uuid48>, ISpanParsable<Uuid48>, IParsable<Uuid48>, IEquatable<ReadOnlySpan<byte>>
Represents a 48-bit UUID that is stored in high-endian format in the output
Constructors
Uuid48
Uuid48(ulong value)
Creates a new Uuid48 from a 48-bit unsigned integer
Uuid48(long value)
Creates a new Uuid48 from a 48-bit signed integer
Uuid48(ushort a, uint b)
Creates a new Uuid48 from two 32-bits components
a— Upper 16 bits (XXXX-........)b— Lower 32 bits (....-XXXXXXXX)
Uuid48(ushort a, ushort b, ushort c)
Creates a new Uuid48 from three 16-bits components
a— Upper 16 bits of the first part (xxxx-........)b— Middle 16 bits of the first part (....-xxxx....)c— Lower 16 bits of the second part (....-xxxxxxxx)
Properties
Lower16
ushort Lower16 { get; }
Returns the 16 lower bits ....-....xxxx
Lower32
uint Lower32 { get; }
Returns the 32 lower bits ....-xxxxxxxx
Upper16
ushort Upper16 { get; }
Returns the 16 upper bits xxxx-........
Upper32
uint Upper32 { get; }
Returns the 32 upper bits xxxx-xxxx....
Methods
CompareTo
int CompareTo(Uuid48 other)
int CompareTo(ulong other)
int CompareTo(long other)
int CompareTo(uint other)
int CompareTo(int other)
Deconstruct
void Deconstruct(out ushort a, out ushort b, out ushort c)
Split into three 16-bits parts
a— xxxx-........b— ....-xxxx....c— ....-....xxxx
Equals
bool Equals(object obj)
bool Equals(Uuid48 other)
bool Equals(ulong other)
bool Equals(long other)
bool Equals(uint other)
bool Equals(int other)
bool Equals(Slice other)
bool Equals(ReadOnlySpan<byte> other)
FromBase62
static Uuid48 FromBase62(string buffer)
Parse a Base62 encoded string representation of an Uuid48
static Uuid48 FromBase62(ReadOnlySpan<char> buffer)
Parse a Base62 encoded string representation of an Uuid48
FromInt32
static Uuid48 FromInt32(int value)
Returns a Uuid48 from a Int32
value— Value that must be positive
Returns: Equivalent Uuid48
The upper 16-bits are set to 0
FromInt64
static Uuid48 FromInt64(long value)
Returns a Uuid48 from a Int64
value— Value that must be positive and not greater than MaxRawValue
Returns: Equivalent Uuid48
FromLower32
static Uuid48 FromLower32(int value)
Returns a Uuid48 from a Int32
value— Value to convert
Returns: Equivalent Uuid48
The upper 16-bits are set to 0
static Uuid48 FromLower32(uint value)
Returns a Uuid48 from a Int32
value— Value to convert
Returns: Equivalent Uuid48
The upper 16-bits are set to 0
FromLower48
static Uuid48 FromLower48(long value)
Returns a Uuid48 from the lower 48 bits of a Int64
value— Value to convert (upper 16 bits are ignored)
Returns: Equivalent Uuid48
static Uuid48 FromLower48(ulong value)
Returns a Uuid48 from the lower 48 bits of a Int64
value— Value to convert (upper 16 bits are ignored)
Returns: Equivalent Uuid48
FromUInt32
static Uuid48 FromUInt32(uint value)
Returns a Uuid48 from a UInt32
value— Value to convert
Returns: Equivalent Uuid48
The upper 16-bits are set to 0
FromUInt64
static Uuid48 FromUInt64(ulong value)
Returns a Uuid48 from a Int64
value— Value that must not be greater than MaxRawValue
Returns: Equivalent Uuid48
FromUpper16Lower32
static Uuid48 FromUpper16Lower32(ushort upper16, uint lower32)
FromUpper32Lower16
static Uuid48 FromUpper32Lower16(uint upper32, ushort lower16)
GetHashCode
int GetHashCode()
NewUuid
static Uuid48 NewUuid()
Generate a new random 48-bit UUID.
If you need sequential or cryptographic uuids, you should use a different generator.
Parse
static Uuid48 Parse(string input)
Parses a string into a Uuid48
input— The string to parse.
Returns: The result of parsing input.
static Uuid48 Parse(ReadOnlySpan<char> input)
Parses a string into a Uuid128
input— The string to parse.
Returns: The result of parsing input.
static Uuid48 Parse(string input, IFormatProvider provider)
Parses a string into a Uuid48
input— The string to parse.provider— This argument is ignored.
Returns: The result of parsing input.
static Uuid48 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 Uuid48 Random(Random rng)
Generates a new random 48-bit UUID, using the specified random number generator
rng— Random number generator
Returns: A random Uuid48 that is less than MaxValue
static Uuid48 Random(Random rng, Uuid48 maxValue)
Generates a new random 48-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 Uuid48 that is less than maxValue
static Uuid48 Random(Random rng, ulong maxValue)
Generates a new random 48-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 Uuid48 that is less than maxValue
static Uuid48 Random(Random rng, Uuid48 minValue, Uuid48 maxValue)
Generates a new random 48-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 Uuid48 that is greater than or equal to minValue and less than maxValue
static Uuid48 Random(Random rng, ulong minValue, ulong maxValue)
Generates a new random 48-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 Uuid48 that is greater than or equal to minValue and less than maxValue
Read
static Uuid48 Read(byte[] value)
Read a 48-bit UUID from a byte array
value— Array of bytes that is either empty, or holds at least 6 bytes
Returns: Corresponding Uuid48 if the read is successful
If value is larger than 6 bytes, the additional bytes will be ignored.
static Uuid48 Read(Slice value)
Read a 48-bit UUID from slice of memory
value— Slice of bytes that is either empty, or holds at least 6 bytes
Returns: Corresponding Uuid48 if the read is successful
If value is larger than 6 bytes, the additional bytes will be ignored.
static Uuid48 Read(ReadOnlySpan<byte> value)
Read a 48-bit UUID from slice of memory
value— Span of bytes that is either empty, or holds at least 6 bytes
Returns: Corresponding Uuid48 if the read is successful
If value is larger than 6 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
The 16 upper bits will be set to 0
ToSlice
Slice ToSlice()
Converts this instance into a Slice of 6 bytes
ToString
string ToString()
Returns a string representation of the value of this instance.
Returns: String using the format "xxxx-xxxxxxxx", where x is a lower-case hexadecimal digit
Strings returned by this method will always to 17 characters long.
string ToString(string format, IFormatProvider formatProvider = null)
Returns a string representation of the value of this instance of the Uuid48 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 Uuid48, 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 9 characters long.
ToUInt64
ulong ToUInt64()
Returns the equivalent 64-bit unsigned integer
The 16 upper bits will be set to 0
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 Uuid48 result)
Tries to parse a string into a Uuid48
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 Uuid48 result)
Tries to parse a span of characters into a Uuid48
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 Uuid48 result)
Tries to parse a span of characters into a Uuid48
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 Uuid48 result)
Tries to parse a string into a Uuid48
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 Uuid48 result)
Tries to parse a span of characters into a Uuid48
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 Uuid48 result)
Tries to parse a base-62 encoded literal into a Uuid48
static bool TryParseBase62(ReadOnlySpan<char> input, out Uuid48 result)
Tries to parse a base-62 encoded literal into a Uuid48
TryRead
static bool TryRead(byte[] value, out Uuid48 result)
Reads a 48-bit UUID from slice of memory
value— Array of bytes that is either empty, or holds at least 6 bytesresult— Corresponding Uuid48, if the read is successful
Returns: true if value has length 0 or at least 6; otherwise, false.
If value is larger than 6 bytes, the additional bytes will be ignored.
static bool TryRead(Slice value, out Uuid48 result)
Reads a 48-bit UUID from slice of memory
value— Slice of bytes that is either empty, or holds at least 6 bytesresult— Corresponding Uuid48, if the read is successful
Returns: true if value has length 0 or at least 6; otherwise, false.
If value is larger than 6 bytes, the additional bytes will be ignored.
static bool TryRead(ReadOnlySpan<byte> value, out Uuid48 result)
Reads a 48-bit UUID from slice of memory
value— Span of bytes that is either empty, or holds at least 6 bytesresult— Corresponding Uuid48, if the read is successful
Returns: true if value has length 0 or at least 6; otherwise, false.
If value is larger than 6 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 6 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 6 bytesbytesWritten— Receives the number of bytes written (either6or0)
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 6 bytes
Fields
AllBitsSet
static readonly Uuid48 AllBitsSet
Uuid48 with all bits set to 1 ("FFFF-FFFFFFFF")
Empty
static readonly Uuid48 Empty
Uuid48 with all bits set to 0 ("0000-00000000")
MaxRawValue
const ulong MaxRawValue
Maximum integer value that can be represented by a Uuid48 (2^48 - 1)
MaxValue
static readonly Uuid48 MaxValue
Uuid48 with all bits set to 1 ("FFFF-FFFFFFFF")
MinValue
static readonly Uuid48 MinValue
Uuid48 with all bits set to 0 ("0000-00000000")
One
static readonly Uuid48 One
Uuid48 with only bit 0 set to 1 ("0000-00000001")
SizeOf
const int SizeOf
Size is 6 bytes