|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- unit uIdGeneratorOptions;
-
- interface
-
- uses
- System.DateUtils, System.SysUtils;
-
- type
- TIdGeneratorOptions = class
- private
- FMethod: SmallInt;
- // FBaseTime: TDateTime;
- FBaseTime: Int64;
- FWorkerId: Word;
- FWorkerIdBitLength: Byte;
- FSeqBitLength: Byte;
- FMaxSeqNumber: Integer;
- FMinSeqNumber: Word;
- FTopOverCostCount: Integer;
- FDataCenterId: Cardinal;
- FDataCenterIdBitLength: Byte;
- FTimestampType: Byte;
- public
- /// <summary>
- /// ѩ㷽
- /// 1-Ư㷨|2-ͳ㷨Ĭ1
- /// </summary>
- property Method: SmallInt read FMethod write FMethod default 1;
- /// <summary>
- /// ʱ䣨UTCʽ
- /// ܳǰϵͳʱ
- /// </summary>
- // property BaseTime: TDateTime read FBaseTime write FBaseTime;
- property BaseTime: Int64 read FBaseTime write FBaseTime;
- /// <summary>
- ///
- /// ⲿ趨ֵ 2^WorkerIdBitLength-1
- /// </summary>
- property WorkerId: Word read FWorkerId write FWorkerId default 0;
- /// <summary>
- /// λ
- /// Ĭֵ6ȡֵΧ [1, 15]Ҫλ+λ22
- /// </summary>
- property WorkerIdBitLength: Byte read FWorkerIdBitLength write FWorkerIdBitLength default 6; // 10;
- /// <summary>
- /// λ
- /// Ĭֵ6ȡֵΧ [3, 21]Ҫλ+λ22
- /// </summary>
- property SeqBitLength: Byte read FSeqBitLength write FSeqBitLength default 6; // 10;
- /// <summary>
- ///
- /// ÷Χ [MinSeqNumber, 2^SeqBitLength-1]Ĭֵ0ʾȡֵ2^SeqBitLength-1]
- /// </summary>
- property MaxSeqNumber: Integer read FMaxSeqNumber write FMaxSeqNumber default 0;
- /// <summary>
- /// С
- /// Ĭֵ5ȡֵΧ [5, MaxSeqNumber]ÿǰ5Ӧ0-4DZλ1-4ʱزӦԤλ0ֵֹԤλ
- /// </summary>
- property MinSeqNumber: Word read FMinSeqNumber write FMinSeqNumber default 5;
- /// <summary>
- /// Ưƴ
- /// Ĭ2000ƼΧ500-10000йأ
- /// </summary>
- property TopOverCostCount: Integer read FTopOverCostCount write FTopOverCostCount default 2000;
- /// <summary>
- /// IDĬ0
- /// </summary>
- property DataCenterId: Cardinal read FDataCenterId write FDataCenterId default 0;
- /// <summary>
- /// IDȣĬ0
- /// </summary>
- property DataCenterIdBitLength: Byte read FDataCenterIdBitLength write FDataCenterIdBitLength default 0;
- /// <summary>
- /// ʱͣ0-룬1-룩Ĭ0
- /// </summary>
- property TimestampType: Byte read FTimestampType write FTimestampType default 0;
-
- constructor Create(); overload;
- constructor Create(WorkerId: Word); overload;
- end;
-
- implementation
-
- { TIdGeneratorOptions }
-
- constructor TIdGeneratorOptions.Create(WorkerId: Word);
- begin
- FBaseTime := 1582136402000; // EncodeDateTime(2020, 2, 20, 2, 20, 2, 20);
- FWorkerId := WorkerId;
- end;
-
- constructor TIdGeneratorOptions.Create();
- begin
- FBaseTime := 1582136402000; // EncodeDateTime(2020, 2, 20, 2, 20, 2, 20);
- end;
-
- end.
|