void Init() { int i = 0; // machineId Array.Copy(MachineId, 0, this.data, i, MachineIdLen); i += MachineIdLen; // processId i = this.WriteInt(i, ProcessId); // sequence i = this.WriteInt(i, Interlocked.Increment(ref nextSequence)); // timestamp (kind of) long ticks = Stopwatch.GetTimestamp(); long nanos = (ticks / Stopwatch.Frequency) * 1000000000; long millis = (ticks / Stopwatch.Frequency) * 1000; i = this.WriteLong(i, ByteBufferUtil.SwapLong(nanos) ^ millis); // random int random = ThreadLocalRandom.Value.Next(); this.hashCode = random; i = this.WriteInt(i, random); Debug.Assert(i == this.data.Length); }
public void Swap_Test() { Assert.Equal(16777216, ByteBufferUtil.SwapInt(1)); Assert.Equal(2560, ByteBufferUtil.SwapShort(10)); Assert.Equal(-6879810281250226176, ByteBufferUtil.SwapLong(100000)); }