-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Cysharp/netstandard21
.NET Standard 2.1 Support(.NET 5, 6 and Unity)
- Loading branch information
Showing
264 changed files
with
20,303 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# MemoryPack | ||
[![GitHub Actions](https://github.com/Cysharp/MemoryPack/workflows/Build-Debug/badge.svg)](https://github.com/Cysharp/MemoryPack/actions) [![Releases](https://img.shields.io/github/release/Cysharp/MemoryPack.svg)](https://github.com/Cysharp/MemoryPack/releases) | ||
|
||
Zero encoding extreme performance binary serializer for C#. | ||
Zero encoding extreme performance binary serializer for C# and Unity. | ||
|
||
![image](https://user-images.githubusercontent.com/46207/192748136-262ac2e7-4646-46e1-afb8-528a51a4a987.png) | ||
|
||
For standard object, MemoryPack is x3 faster than MessagePack for C#. For struct array, MemoryPack gots boosted power, x50~100 faster than other serializers. | ||
|
||
MemoryPack is my 4th serializer, previously I've created well known serializers, ~~[ZeroFormatter](https://github.com/neuecc/ZeroFormatter)~~, ~~[Utf8Json](https://github.com/neuecc/Utf8Json)~~, [MessagePack for C#](https://github.com/neuecc/MessagePack-CSharp). The reason for MemoryPack's speed is due to its C#-specific, C#-optimized binary format and a well tuned implementation based on my past experience. It is also a completely new design utilizing .NET 7 and C# 11 and the Incremental Source Generator. | ||
MemoryPack is my 4th serializer, previously I've created well known serializers, ~~[ZeroFormatter](https://github.com/neuecc/ZeroFormatter)~~, ~~[Utf8Json](https://github.com/neuecc/Utf8Json)~~, [MessagePack for C#](https://github.com/neuecc/MessagePack-CSharp). The reason for MemoryPack's speed is due to its C#-specific, C#-optimized binary format and a well tuned implementation based on my past experience. It is also a completely new design utilizing .NET 7 and C# 11 and the Incremental Source Generator(.NET Standard 2.1(.NET 5, 6) and Unity support is also exists). | ||
|
||
Other serializers performs many encoding operations such as VarInt encoding, tag, string, etc. MemoryPack format uses a zero-encoding design that copies as much of the C# memory as possible. zero-encoding is similar as FlatBuffers but don't need special type, MemoryPack's serialize target is POCO. | ||
|
||
|
@@ -20,22 +20,17 @@ Other than performance, MemoryPack has these features. | |
* Polymorphism(Union) serialization | ||
* PipeWriter/Reader based streaming serialization | ||
* TypeScript code generation and ASP.NET Core Formatter | ||
|
||
> Currently support target framework is .NET 7 only, however, I'm now working for .NET Standard 2.1(.NET 5, 6) and Unity(2021.2) support. Stay tuned. | ||
* Unity(2021.3) IL2CPP Support via .NET Source Generator | ||
|
||
Installation | ||
--- | ||
This library is distributed via NuGet. Minimum requirement is `.NET 7 RC1`. | ||
This library is distributed via NuGet. For best performance, recommend to use `.NET 7`. Minimum requirement is `.NET Standard 2.1`. | ||
|
||
> PM> Install-Package [MemoryPack](https://www.nuget.org/packages/MemoryPack) | ||
And you need to enable preview features to `.csproj`. | ||
And also editor requires Roslyn 4.3.0 support, for example Visual Studio 2022 version 17.3. For details, see [Roslyn Version Support](https://learn.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support2) document. | ||
|
||
```xml | ||
<PropertyGroup> | ||
<EnablePreviewFeatures>True</EnablePreviewFeatures> | ||
</PropertyGroup> | ||
``` | ||
For Unity, the requirements and installation process are completely different. See the [Unity](#unity) section for details. | ||
|
||
Quick Start | ||
--- | ||
|
@@ -745,11 +740,19 @@ The created formatter is registered with `MemoryPackFormatterProvider`. | |
MemoryPackFormatterProvider.Register(new SkeltonFormatter()); | ||
``` | ||
|
||
Unity support | ||
Unity | ||
--- | ||
Currently MemoryPack dependents .NET 7 runtime, incremental generator and C# 11. Therefore it will not work in Unity. .NET 7 support is planned for Unity 2025. | ||
Install via UPM git URL package or asset package(MemoryPack.*.*.*.unitypackage) available in [MemoryPack/releases](https://github.com/Cysharp/MemoryPack/releases) page. | ||
|
||
* https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack | ||
|
||
Supporting minimum Unity version is `2021.3`. The dependency managed DLL `System.Runtime.CompilerSErvices.Unsafe/6.0.0` is included with unitypackage. For git references, you will need to add them in another way as they are not included to avoid unnecessary dependencies; either extract the dll from unitypackage or download it from the [NuGet page](https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/6.0.0). | ||
|
||
As with the .NET version, the code is generated by a code generator(`MemoryPack.Generator.Roslyn3.dll`). Reflection-free implementation also provides the best performance in IL2CPP. | ||
|
||
For more information on Unity and Source Generator, please refer to the [Unity documentation](https://docs.unity3d.com/Manual/roslyn-analyzers.html). | ||
|
||
However, now working for .NET Standard 2.1 support(see [PR #27](https://github.com/Cysharp/MemoryPack/pull/27)), it can run on Unity 2021. Stay tuned. | ||
Source Generator is also used officially by Unity by [com.unity.properties](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) and [com.unity.entities](https://docs.unity3d.com/Packages/[email protected]/changelog/CHANGELOG.html). In other words, it is the standard for code generation in the next generation of Unity. | ||
|
||
Binary wire format specification | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using MemoryPack; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SandboxNet6 | ||
{ | ||
[MemoryPackable] | ||
public partial class NamespaceTest | ||
{ | ||
public int MyProperty { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using MemoryPack; | ||
using System.Buffers; | ||
using System.Runtime.CompilerServices; | ||
|
||
|
||
// System.Buffers.IBufferWriter<byte> | ||
Console.WriteLine("Hello, World!"); | ||
|
||
[MemoryPackable] | ||
public partial class HelloMemoryPackable | ||
{ | ||
public int MyProperty { get; set; } | ||
} | ||
|
||
|
||
[MemoryPackable] | ||
public partial class HelloMemoryPackable2 | ||
{ | ||
public HelloMemoryPackable? MyProperty { get; set; } | ||
// public TypeAccessException My3Property { get; set; } | ||
} | ||
|
||
|
||
[MemoryPackable] | ||
[MemoryPackUnion(0, typeof(FooClass))] | ||
[MemoryPackUnion(249, typeof(BarClass))] | ||
public partial interface IUnionSample | ||
{ | ||
} | ||
|
||
[MemoryPackable] | ||
public partial class FooClass : IUnionSample | ||
{ | ||
public int XYZ { get; set; } | ||
} | ||
|
||
[MemoryPackable] | ||
public partial class BarClass : IUnionSample | ||
{ | ||
public string? OPQ { get; set; } | ||
} | ||
|
||
|
||
[MemoryPackable] | ||
public partial struct IncludesReferenceStruct | ||
{ | ||
public int X; | ||
public string? Y; | ||
} | ||
|
||
|
||
[MemoryPackable] | ||
[MemoryPackUnion(0, typeof(GenricUnionA<>))] | ||
[MemoryPackUnion(1, typeof(GenricUnionB<>))] | ||
public partial interface IGenericUnion<ToaruHoge> | ||
{ | ||
ToaruHoge? Value { get; set; } | ||
} | ||
|
||
|
||
[MemoryPackable] | ||
public partial class GenricUnionA<T> : IGenericUnion<T> | ||
{ | ||
public T? Value { get; set; } | ||
public int MyProperty { get; set; } | ||
} | ||
|
||
[MemoryPackable] | ||
public partial class GenricUnionB<T> : IGenericUnion<T> | ||
{ | ||
public T? Value { get; set; } | ||
public double MyProperty { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<LangVersion>10.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\MemoryPack.Core\MemoryPack.Core.csproj" /> | ||
<ProjectReference Include="..\..\src\MemoryPack.Generator.Roslyn3\MemoryPack.Generator.Roslyn3.csproj"> | ||
<OutputItemType>Analyzer</OutputItemType> | ||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
<!--<ItemGroup> | ||
<CompilerVisibleProperty Include="MemoryPackGenerator_SerializationInfoOutputDirectory" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<MemoryPackGenerator_SerializationInfoOutputDirectory>$(MSBuildProjectDirectory)\MemoryPackLogs</MemoryPackGenerator_SerializationInfoOutputDirectory> | ||
</PropertyGroup>--> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.