From fad0f5fd23b357296111837e7501f9795715897a Mon Sep 17 00:00:00 2001 From: hadashiA Date: Thu, 7 Mar 2024 11:18:30 +0900 Subject: [PATCH 1/3] Add attr for AOT and bump dotnet version --- sandbox/Benchmark/Benchmark.csproj | 2 +- sandbox/ClassLibrary/ClassLibrary.csproj | 2 +- sandbox/NativeAot/NativeAot.csproj | 2 +- .../SandboxConsoleApp.csproj | 3 +- src/MemoryPack.Core/MemoryPack.Core.csproj | 2 +- .../MemoryPackSerializer.Deserialize.cs | 30 +++++++++++++++---- .../MemoryPack.UnityShims.csproj | 2 +- .../MemoryPack.Tests/MemoryPack.Tests.csproj | 2 +- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/sandbox/Benchmark/Benchmark.csproj b/sandbox/Benchmark/Benchmark.csproj index 5d88c9cf..f8e99ef0 100644 --- a/sandbox/Benchmark/Benchmark.csproj +++ b/sandbox/Benchmark/Benchmark.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable True enable diff --git a/sandbox/ClassLibrary/ClassLibrary.csproj b/sandbox/ClassLibrary/ClassLibrary.csproj index 3f947bb1..c5177aa5 100644 --- a/sandbox/ClassLibrary/ClassLibrary.csproj +++ b/sandbox/ClassLibrary/ClassLibrary.csproj @@ -1,7 +1,7 @@ - net7.0;netstandard2.1 + net8.0;netstandard2.1 enable 11.0 enable diff --git a/sandbox/NativeAot/NativeAot.csproj b/sandbox/NativeAot/NativeAot.csproj index 6c637551..a05dbdfa 100644 --- a/sandbox/NativeAot/NativeAot.csproj +++ b/sandbox/NativeAot/NativeAot.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable false diff --git a/sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj b/sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj index 96dde651..d1528e86 100644 --- a/sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj +++ b/sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj @@ -2,10 +2,11 @@ Exe - net7.0 + net8.0 disable enable false + true diff --git a/src/MemoryPack.Core/MemoryPack.Core.csproj b/src/MemoryPack.Core/MemoryPack.Core.csproj index f0acc414..772da2e2 100644 --- a/src/MemoryPack.Core/MemoryPack.Core.csproj +++ b/src/MemoryPack.Core/MemoryPack.Core.csproj @@ -1,7 +1,7 @@  - net7.0;netstandard2.1 + net7.0;net8.0;netstandard2.1 enable enable True diff --git a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs index 37b69f9a..718ebb88 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs @@ -11,14 +11,22 @@ public static partial class MemoryPackSerializer [ThreadStatic] static MemoryPackReaderOptionalState? threadStaticReaderOptionalState; - public static T? Deserialize(ReadOnlySpan buffer, MemoryPackSerializerOptions? options = default) + public static T? Deserialize< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#endif + T>(ReadOnlySpan buffer, MemoryPackSerializerOptions? options = default) { T? value = default; Deserialize(buffer, ref value, options); return value; } - public static int Deserialize(ReadOnlySpan buffer, ref T? value, MemoryPackSerializerOptions? options = default) + public static int Deserialize< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#endif + T>(ReadOnlySpan buffer, ref T? value, MemoryPackSerializerOptions? options = default) { if (!RuntimeHelpers.IsReferenceOrContainsReferences()) { @@ -50,14 +58,22 @@ public static int Deserialize(ReadOnlySpan buffer, ref T? value, Memory } } - public static T? Deserialize(in ReadOnlySequence buffer, MemoryPackSerializerOptions? options = default) + public static T? Deserialize< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#endif + T>(in ReadOnlySequence buffer, MemoryPackSerializerOptions? options = default) { T? value = default; Deserialize(buffer, ref value, options); return value; } - public static int Deserialize(in ReadOnlySequence buffer, ref T? value, MemoryPackSerializerOptions? options = default) + public static int Deserialize< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#endif + T>(in ReadOnlySequence buffer, ref T? value, MemoryPackSerializerOptions? options = default) { var state = threadStaticReaderOptionalState; if (state == null) @@ -79,7 +95,11 @@ public static int Deserialize(in ReadOnlySequence buffer, ref T? value, } } - public static async ValueTask DeserializeAsync(Stream stream, MemoryPackSerializerOptions? options = default, CancellationToken cancellationToken = default) + public static async ValueTask DeserializeAsync< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#endif + T>(Stream stream, MemoryPackSerializerOptions? options = default, CancellationToken cancellationToken = default) { if (stream is MemoryStream ms && ms.TryGetBuffer(out ArraySegment streamBuffer)) { diff --git a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj index 7c98db34..6aa97c32 100644 --- a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj +++ b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj @@ -1,7 +1,7 @@  - net7.0;netstandard2.1 + net8.0;netstandard2.1 enable enable True diff --git a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj index b3b9d023..46caab61 100644 --- a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj +++ b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable false true From 80edf2af32897181eca6c5bd19ab32dc7010211b Mon Sep 17 00:00:00 2001 From: hadashiA Date: Thu, 7 Mar 2024 11:22:13 +0900 Subject: [PATCH 2/3] Add aot sample from #189 --- sandbox/SandboxConsoleApp/Program.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sandbox/SandboxConsoleApp/Program.cs b/sandbox/SandboxConsoleApp/Program.cs index e6aab77e..834037ea 100644 --- a/sandbox/SandboxConsoleApp/Program.cs +++ b/sandbox/SandboxConsoleApp/Program.cs @@ -28,6 +28,21 @@ using System.Text; using System.Xml.Linq; +using MemoryPack; +using System.Runtime.InteropServices; + +Console.WriteLine($"{RuntimeInformation.FrameworkDescription}"); + +//var r = new MemPackTestObj() { Strings = new[] { "a", "b", "c" } }; +//var bytes = MemoryPackSerializer.Serialize(r); + +var bytes = Convert.FromBase64String("AwMAAAD+////AQAAAGH+////AQAAAGL+////AQAAAGMAAAAAAAAAAP////8="); +Console.WriteLine(Convert.ToBase64String(bytes)); +var r2 = MemoryPackSerializer.Deserialize(bytes); +foreach (var s in r2!.Strings) +{ + Console.WriteLine(s); +} var value = new ListBytesSample(); @@ -48,6 +63,15 @@ var span = CollectionsMarshal.AsSpan(value.Payload); +[MemoryPackable] +public partial record MemPackTestObj +{ + public string[] Strings { get; set; } + public DateTime Date { get; set; } + public string Name { get; set; } +} + + [MemoryPackable] public partial class CctorSample { @@ -206,7 +230,7 @@ public partial struct BrotliValue -//BrotliDecoder.TryDecompress(written, +//BrotliDecoder.TryDecompress(written, From 48c014376070014363eb0956374a40140f64f0c9 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Thu, 14 Mar 2024 14:12:26 +0900 Subject: [PATCH 3/3] Fix targetframeworks --- src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj index 6aa97c32..a7cd01d5 100644 --- a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj +++ b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj @@ -1,7 +1,7 @@  - net8.0;netstandard2.1 + net7.0;net8.0;netstandard2.1 enable enable True