Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle endianess in SequentialGuidGenerator. #9

Merged
merged 1 commit into from
Feb 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ public class SequentialGuidIdentityGenerator : IIdentityGenerator<Guid>

static SequentialGuidIdentityGenerator()
{
_counter = DateTime.Now.Ticks;
_counter = DateTime.UtcNow.Ticks;
}

public Task<Guid> NextAsync()
{
var guidBytes = Guid.NewGuid().ToByteArray();
var counterBytes = BitConverter.GetBytes(Interlocked.Increment(ref _counter));

if (!BitConverter.IsLittleEndian)
{
Array.Reverse(counterBytes);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Given that little endian is going to be the most common maybe do the reverse when big endian instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind--misread the code.


guidBytes[08] = counterBytes[1];
guidBytes[09] = counterBytes[0];
guidBytes[10] = counterBytes[7];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlServer
public class SequentialGuidIdentityGeneratorTest
{
[Fact]
public async Task Can_get_next_values()
public async Task CanGetNextValues()
{
var sequentialGuidIdentityGenerator = new SequentialGuidIdentityGenerator();
var values = new List<Guid>();
Expand Down