/// <summary>Split this 128-bit UUID into two 64-bit numbers</summary> /// <param name="high">Receives the first 8 bytes (in network order) of this UUID</param> /// <param name="low">Receives the last 8 bytes (in network order) of this UUID</param> public void Split(out ulong high, out ulong low) { unsafe { byte *buffer = stackalloc byte[16]; WriteUnsafe(m_packed, buffer); high = Uuid64.ReadUnsafe(buffer); low = Uuid64.ReadUnsafe(buffer + 8); } }
/// <summary>Split this 128-bit UUID into two 64-bit UUIDs</summary> /// <param name="high">Receives the first 8 bytes (in network order) of this UUID</param> /// <param name="low">Receives the last 8 bytes (in network order) of this UUID</param> public void Split(out Uuid64 high, out Uuid64 low) { unsafe { byte *buffer = stackalloc byte[16]; WriteUnsafe(m_packed, buffer); high = new Uuid64(Uuid64.ReadUnsafe(buffer)); low = new Uuid64(Uuid64.ReadUnsafe(buffer + 8)); } }
public static Guid Convert(Uuid64 a, Uuid64 b) { unsafe { byte *buf = stackalloc byte[16]; a.WriteToUnsafe(buf); b.WriteToUnsafe(buf + 8); return(ReadUnsafe(buf)); } }
/// <summary>Split this 128-bit UUID into two 64-bit numbers</summary> /// <param name="high">Receives the first 8 bytes (in network order) of this UUID</param> /// <param name="mid">Receives the middle 4 bytes (in network order) of this UUID</param> /// <param name="low">Receives the last 4 bytes (in network order) of this UUID</param> public void Split(out ulong high, out uint mid, out uint low) { unsafe { byte *buffer = stackalloc byte[16]; WriteUnsafe(m_packed, buffer); high = Uuid64.ReadUnsafe(buffer); var id = Uuid64.ReadUnsafe(buffer + 8); mid = (uint)(id >> 32); low = (uint)id; } }
public Uuid64 NewUuid() { //REVIEW: OPTIMIZE: use a per-thread instance of the rng and scratch buffer? // => right now, NewUuid() is a Global Lock for the whole process! lock (this.Rng) { // get 8 bytes of randomness (0 allowed) this.Rng.GetBytes(this.Scratch); //note: do *NOT* call GetBytes(byte[], int, int) because it creates creates a temp buffer, calls GetBytes(byte[]) and copy the result back! (as of .NET 4.7.1) //TODO: PERF: use Span<byte> APIs once (if?) they become available! return(Uuid64.Read(this.Scratch)); } }
public static Guid Convert(Uuid64 a, uint b, uint c) { unsafe { byte *buf = stackalloc byte[16]; a.WriteToUnsafe(buf); buf[8] = (byte)b; buf[9] = (byte)(b >> 8); buf[10] = (byte)(b >> 16); buf[11] = (byte)(b >> 24); buf[12] = (byte)c; buf[13] = (byte)(c >> 8); buf[14] = (byte)(c >> 16); buf[15] = (byte)(c >> 24); return(ReadUnsafe(buf)); } }
public Uuid128(Uuid64 a, uint b, uint c) : this() { m_packed = Convert(a, b, c); }
public Uuid128(Uuid64 a, Uuid64 b) : this() { m_packed = Convert(a, b); }