Skip to content

Commit

Permalink
uuid json converter supporting uuid as dictionary key (#15)
Browse files Browse the repository at this point in the history
* uuid json converter supporting uuid as dictionary key

* up version

* add tests for Read adn write DictionaryPropertyUuid

* Upgrade SDK. Fix .editorconfig. Upgrade deps.

---------

Co-authored-by: Roman Bukin <[email protected]>
  • Loading branch information
bruzhmelev and vanbukin authored Aug 13, 2023
1 parent 43b85da commit c78f9f3
Show file tree
Hide file tree
Showing 39 changed files with 3,151 additions and 1,056 deletions.
330 changes: 313 additions & 17 deletions .editorconfig

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ jobs:
fi
echo "version_with_suffix_dst=${version_with_suffix}" >> $GITHUB_ENV
echo "has_suffix_dst=${has_suffix}" >> $GITHUB_ENV
- name: Setup .NET Core SDK 7.0.100
- name: Setup .NET Core SDK 7.0.400
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100
dotnet-version: 7.0.400
- name: Checkout source branch back
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -107,14 +107,14 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup .NET Core SDK 6.0.403
- name: Setup .NET Core SDK 6.0.413
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.403
- name: Setup .NET Core SDK 7.0.100
dotnet-version: 6.0.413
- name: Setup .NET Core SDK 7.0.400
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100
dotnet-version: 7.0.400
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push_to_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup .NET Core SDK 6.0.403
- name: Setup .NET Core SDK 6.0.413
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.403
- name: Setup .NET Core SDK 7.0.100
dotnet-version: 6.0.413
- name: Setup .NET Core SDK 7.0.400
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100
dotnet-version: 7.0.400
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup .NET Core SDK 6.0.403
- name: Setup .NET Core SDK 6.0.413
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.403
- name: Setup .NET Core SDK 7.0.100
dotnet-version: 6.0.413
- name: Setup .NET Core SDK 7.0.400
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100
dotnet-version: 7.0.400
- name: Create coverage directory and promote absolute paths to env
shell: bash
run: |
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Dodo.Primitives

[![Latest release](https://img.shields.io/badge/nuget-2.0.0-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/2.0.0)
[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/2.0.0&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/2.0.0)
[![Latest release](https://img.shields.io/badge/nuget-2.0.1-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/2.0.1)
[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/2.0.1&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/2.0.1)

Library provides .NET primitive types:

- [Uuid](./src/Dodo.Primitives/Uuid.cs)
- [Uuid](./src/Dodo.Primitives/Uuid.cs)

and utils to work with types:

- [Hex](./src/Dodo.Primitives/Hex.cs)
- [Hex](./src/Dodo.Primitives/Hex.cs)

## Project goal

Expand All @@ -19,22 +19,22 @@ The main goal is Uuid implementation according to the [RFC4122](https://tools.ie

Our goal is to provide Uuid fully compliant with RFC4122 (big-endian layout) and preserve System.Guid-like behaviour. Also project contains generators to create different Uuid variants. Currently supported variants:

- Time-based (like [Uuid v1](https://tools.ietf.org/html/rfc4122#section-4.1.3)).
- Time-based (like [Uuid v1](https://tools.ietf.org/html/rfc4122#section-4.1.3)).

```csharp
var uuid = Uuid.NewTimeBased();
```
```csharp
var uuid = Uuid.NewTimeBased();
```

- Time-based, optimized for MySQL.
- Time-based, optimized for MySQL.

```csharp
var uuid = Uuid.NewMySqlOptimized();
```
```csharp
var uuid = Uuid.NewMySqlOptimized();
```

Equals `UUID_TO_BIN(UUID(), 1)` from [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin)
Equals `UUID_TO_BIN(UUID(), 1)` from [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin)
## Project documentation

- [Prerequisites, build and development](https://github.com/dodopizza/primitives/wiki/Prerequisites,-build-and-development)
- [Benchmarks](https://github.com/dodopizza/primitives/wiki/Benchmarks)
- [Prerequisites, build and development](https://github.com/dodopizza/primitives/wiki/Prerequisites,-build-and-development)
- [Benchmarks](https://github.com/dodopizza/primitives/wiki/Benchmarks)
8 changes: 4 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"rollForward": "latestPatch"
}
"sdk": {
"version": "7.0.400",
"rollForward": "latestPatch"
}
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
80 changes: 76 additions & 4 deletions src/Dodo.Primitives.Benchmarks/Benchmarks/CtorBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,51 @@ public class CtorBenchmarks
// byte[]
[Benchmark]
[BenchmarkCategory("byte[]")]
[Arguments(new byte[] { 253, 47, 238, 170, 214, 83, 143, 78, 140, 107, 139, 132, 94, 5, 145, 199 })]
[Arguments(new byte[]
{
253,
47,
238,
170,
214,
83,
143,
78,
140,
107,
139,
132,
94,
5,
145,
199
})]
public Guid guid_CtorByteArray(byte[] guidBytes)
{
return new Guid(guidBytes);
}

[Benchmark]
[BenchmarkCategory("byte[]")]
[Arguments(new byte[] { 170, 238, 47, 253, 83, 214, 78, 143, 140, 107, 139, 132, 94, 5, 145, 199 })]
[Arguments(new byte[]
{
170,
238,
47,
253,
83,
214,
78,
143,
140,
107,
139,
132,
94,
5,
145,
199
})]
public Uuid uuid_CtorByteArray(byte[] uuidBytes)
{
return new Uuid(uuidBytes);
Expand All @@ -31,7 +67,25 @@ public Uuid uuid_CtorByteArray(byte[] uuidBytes)
// ReadOnlySpan<byte>
[Benchmark(OperationsPerInvoke = 16)]
[BenchmarkCategory("ReadOnlySpan<byte>")]
[Arguments(new byte[] { 253, 47, 238, 170, 214, 83, 143, 78, 140, 107, 139, 132, 94, 5, 145, 199 })]
[Arguments(new byte[]
{
253,
47,
238,
170,
214,
83,
143,
78,
140,
107,
139,
132,
94,
5,
145,
199
})]
[SuppressMessage("ReSharper", "ObjectCreationAsStatement")]
public void guid_CtorReadOnlySpan(byte[] guidBytes)
{
Expand Down Expand Up @@ -59,7 +113,25 @@ public void guid_CtorReadOnlySpan(byte[] guidBytes)

[Benchmark(OperationsPerInvoke = 16)]
[BenchmarkCategory("ReadOnlySpan<byte>")]
[Arguments(new byte[] { 170, 238, 47, 253, 83, 214, 78, 143, 140, 107, 139, 132, 94, 5, 145, 199 })]
[Arguments(new byte[]
{
170,
238,
47,
253,
83,
214,
78,
143,
140,
107,
139,
132,
94,
5,
145,
199
})]
[SuppressMessage("ReSharper", "ObjectCreationAsStatement")]
public void uuid_CtorReadOnlySpan(byte[] uuidBytes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,38 @@ public IEnumerable<Uuid> UuidArgs()

public IEnumerable<object[]> GuidSameValues()
{
yield return new object[] { _guid, _guidSame };
yield return new object[]
{
_guid,
_guidSame
};
}

public IEnumerable<object[]> UuidSameValues()
{
yield return new object[] { _uuid, _uuidSame };
yield return new object[]
{
_uuid,
_uuidSame
};
}

public IEnumerable<object[]> GuidDifferentValues()
{
yield return new object[] { _guid, _guidDifferent };
yield return new object[]
{
_guid,
_guidDifferent
};
}

public IEnumerable<object[]> UuidDifferentValues()
{
yield return new object[] { _uuid, _uuidDifferent };
yield return new object[]
{
_uuid,
_uuidDifferent
};
}

// IEquatable<T>.Equals with same value
Expand Down Expand Up @@ -173,7 +189,7 @@ public int guid_CompareTo_T_DifferentValue(Guid guid, Guid differentValue)
[SuppressMessage("ReSharper", "RedundantCast")]
public int uuid_CompareToNull(Uuid uuid)
{
return uuid.CompareTo((object)null);
return uuid.CompareTo((object) null);
}

[Benchmark]
Expand All @@ -182,7 +198,6 @@ public int uuid_CompareToNull(Uuid uuid)
[SuppressMessage("ReSharper", "RedundantCast")]
public int guid_CompareToNull(Guid guid)
{
return guid.CompareTo((object)null);
return guid.CompareTo((object) null);
}
#nullable restore
}
28 changes: 22 additions & 6 deletions src/Dodo.Primitives.Benchmarks/Benchmarks/OverridesBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,38 @@ public IEnumerable<Uuid> UuidArgs()

public IEnumerable<object[]> GuidSameValues()
{
yield return new object[] { _guid, _guidSame };
yield return new object[]
{
_guid,
_guidSame
};
}

public IEnumerable<object[]> UuidSameValues()
{
yield return new object[] { _uuid, _uuidSame };
yield return new object[]
{
_uuid,
_uuidSame
};
}

public IEnumerable<object[]> GuidDifferentTypesValues()
{
yield return new[] { _guid, new object() };
yield return new[]
{
_guid,
new object()
};
}

public IEnumerable<object[]> UuidDifferentTypesValues()
{
yield return new[] { _uuid, new object() };
yield return new[]
{
_uuid,
new object()
};
}

// GetHashCode
Expand Down Expand Up @@ -118,7 +134,7 @@ public bool guid_EqualsDifferentTypesValues(Guid guid, object differentTypeValue
[MethodImpl(MethodImplOptions.NoInlining)]
public bool uuid_EqualsWithNull(Uuid uuid)
{
return uuid.Equals((object?)null);
return uuid.Equals((object?) null);
}

[Benchmark]
Expand All @@ -128,6 +144,6 @@ public bool uuid_EqualsWithNull(Uuid uuid)
[MethodImpl(MethodImplOptions.NoInlining)]
public bool guid_EqualsWithNull(Guid guid)
{
return guid.Equals((object?)null);
return guid.Equals((object?) null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private static string[] GenerateSometimesBrokenGuidsNStringsArray(int count)
var random = new Random();
int* uuidIntegers = stackalloc int[4];
char* charToBreakPtr = stackalloc char[1];
var charBytesPtr = (byte*)charToBreakPtr;
var charBytesPtr = (byte*) charToBreakPtr;
var result = new string[count];
var breakUpperByteOnCharArray = new bool[32];
for (var i = 0; i < breakUpperByteOnCharArray.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2"/>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7"/>
</ItemGroup>

</Project>
Loading

0 comments on commit c78f9f3

Please sign in to comment.