mareek / UUIDNext

A fast and modern .NET library to generate UUID/GUID that are either sequential and database friendly (versions 7), name based (versions 5) or random (version 4).
BSD Zero Clause License
240 stars 13 forks source link

GuidHelper: Swap bytes regardless of the endianness #4

Closed Zireael-N closed 1 year ago

Zireael-N commented 1 year ago

Current implementation makes an incorrect assumption that the Guid(ReadOnlySpan<byte>) constructor and Guid.TryWriteBytes(Span<byte>) produce different results on big-endian and little-endian systems.

However, they always accept/return mixed-endian bytes. See the implementation: https://github.com/dotnet/runtime/blob/9129083c2fc6ef32479168f0555875b54aee4dfb/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L56-L73

https://github.com/dotnet/runtime/blob/9129083c2fc6ef32479168f0555875b54aee4dfb/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L838-L858

mareek commented 1 year ago

I indeed made an incorrect assumption. Thank you the investigation and thank you for the fix