Beispiel #1
0
        internal UIDGeneratorImpl(UIDOptions options)
        {
            ValidOptions(options);

            EpochDateTime = options.EpochDateTime;

            WorkId       = options.WorkId;
            WorkIdBit    = options.WorkIdBit;
            TimeCheckBit = options.TimeCheckBit;
            SequenceBit  = options.SequenceBit;

            MaxTimestamp = BitUtils.MaxVaue(TimestampBit);
            MaxWorkId    = BitUtils.MaxVaue(WorkIdBit);
            MaxSequence  = BitUtils.MaxVaue(SequenceBit);
            MaxTimeCheck = BitUtils.MaxVaue(TimeCheckBit);

            SequenceShift  = 0;
            TimeCheckShift = SequenceBit;
            WorkIdShift    = TimeCheckBit + SequenceBit;
            TimestampShift = WorkIdBit + TimeCheckBit + SequenceBit;

            if (WorkId > MaxWorkId)
            {
                throw new Exception("workdId超过最大值");
            }
        }
Beispiel #2
0
 private void ValidOptions(UIDOptions options)
 {
     if (options.WorkIdBit <= 0)
     {
         throw new Exception("WorkIdBit不能小于等于0");
     }
     if (options.SequenceBit <= 0)
     {
         throw new Exception("SequenceBit不能小于等于0");
     }
     if (options.WorkIdBit + options.TimeCheckBit + options.SequenceBit != 22)
     {
         throw new Exception("WorkIdBit+TimeCheckBit+SequenceBit=24");
     }
 }
 /// <summary>
 /// 创建UID生成器
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public IUIDGenerator CreateUIDGenerator(UIDOptions options)
 {
     return(new UIDGeneratorImpl(options));
 }