public TimeGuid([NotNull] byte[] bytes) { if (TimeGuidBitsLayout.GetVersion(bytes) != GuidVersion.TimeBased) { throw new InvalidOperationException($"Invalid v1 guid: [{string.Join(", ", bytes.Select(x => x.ToString("x2")))}]"); } this.bytes = bytes; }
public TimeGuid(Guid guid) { var timeGuidBytes = ReorderGuidBytesInCassandraWay(guid.ToByteArray()); if (TimeGuidBitsLayout.GetVersion(timeGuidBytes) != GuidVersion.TimeBased) { throw new InvalidOperationException($"Invalid v1 guid: {guid}"); } bytes = timeGuidBytes; }
public static bool TryParse([CanBeNull] string str, out TimeGuid result) { result = null; if (!Guid.TryParse(str, out var guid)) { return(false); } var timeGuidBytes = ReorderGuidBytesInCassandraWay(guid.ToByteArray()); if (TimeGuidBitsLayout.GetVersion(timeGuidBytes) != GuidVersion.TimeBased) { return(false); } result = new TimeGuid(timeGuidBytes); return(true); }
public byte[] GetNode() { return(TimeGuidBitsLayout.GetNode(bytes)); }
public ushort GetClockSequence() { return(TimeGuidBitsLayout.GetClockSequence(bytes)); }
public Timestamp GetTimestamp() { return(TimeGuidBitsLayout.GetTimestamp(bytes)); }
public static bool IsTimeGuid(Guid guid) { var timeGuidBytes = ReorderGuidBytesInCassandraWay(guid.ToByteArray()); return(TimeGuidBitsLayout.GetVersion(timeGuidBytes) == GuidVersion.TimeBased); }
public TimeGuid([NotNull] Timestamp timestamp, ushort clockSequence, [NotNull] byte[] node) : this(TimeGuidBitsLayout.Format(timestamp, clockSequence, node)) { }
public byte[] NewGuid([NotNull] Timestamp timestamp, ushort clockSequence) { return(TimeGuidBitsLayout.Format(timestamp, clockSequence, GenerateRandomNode())); }
public byte[] NewGuid() { var nowTimestamp = new Timestamp(preciseTimestampGenerator.NowTicks()); return(TimeGuidBitsLayout.Format(nowTimestamp, GenerateRandomClockSequence(), GenerateRandomNode())); }