예제 #1
0
 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;
 }
예제 #2
0
        public TimeGuid(Guid guid)
        {
            var timeGuidBytes = ReorderGuidBytesInCassandraWay(guid.ToByteArray());

            if (TimeGuidBitsLayout.GetVersion(timeGuidBytes) != GuidVersion.TimeBased)
            {
                throw new InvalidOperationException($"Invalid v1 guid: {guid}");
            }
            bytes = timeGuidBytes;
        }
예제 #3
0
        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);
        }
예제 #4
0
 public byte[] GetNode()
 {
     return(TimeGuidBitsLayout.GetNode(bytes));
 }
예제 #5
0
 public ushort GetClockSequence()
 {
     return(TimeGuidBitsLayout.GetClockSequence(bytes));
 }
예제 #6
0
 public Timestamp GetTimestamp()
 {
     return(TimeGuidBitsLayout.GetTimestamp(bytes));
 }
예제 #7
0
        public static bool IsTimeGuid(Guid guid)
        {
            var timeGuidBytes = ReorderGuidBytesInCassandraWay(guid.ToByteArray());

            return(TimeGuidBitsLayout.GetVersion(timeGuidBytes) == GuidVersion.TimeBased);
        }
예제 #8
0
 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()));
        }