sharp-chat/SharpChat.Common/SharpId.cs

14 lines
380 B
C#
Raw Permalink Normal View History

2022-08-30 15:05:29 +00:00
using System;
using System.Threading;
namespace SharpChat {
public static class SharpId {
private const long EPOCH = 1588377600000;
private static int Counter = 0;
public static long Next()
=> ((DateTimeOffset.Now.ToUnixTimeMilliseconds() - EPOCH) << 8)
| (ushort)(Interlocked.Increment(ref Counter) & 0xFFFF);
}
}