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

Migrate Unity support to NuGetUnity #241

Merged
merged 15 commits into from
Mar 14, 2024
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
44 changes: 15 additions & 29 deletions .github/workflows/build-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,31 @@ jobs:

build-unity:
if: "((github.event_name == 'push' && github.repository_owner == 'Cysharp') || startsWith(github.event.pull_request.head.label, 'Cysharp:'))"
strategy:
matrix:
unity: ["2021.3.11f1"]
# strategy:
# matrix:
# unity: ["2021.3.11f1"]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
# Execute scripts: RuntimeUnitTestToolkit
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
- name: Build UnitTest(Linux64, mono)
uses: Cysharp/Actions/.github/actions/unity-builder@main
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: src/MemoryPack.Unity
unityVersion: ${{ matrix.unity }}
targetPlatform: StandaloneLinux64
buildMethod: UnitTestBuilder.BuildUnitTest
customParameters: /headless /ScriptBackend mono
# - name: Build UnitTest(Linux64, mono)
# uses: Cysharp/Actions/.github/actions/unity-builder@main
# env:
# UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
# UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
# UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
# with:
# projectPath: src/MemoryPack.Unity
# unityVersion: ${{ matrix.unity }}
# targetPlatform: StandaloneLinux64
# buildMethod: UnitTestBuilder.BuildUnitTest
# customParameters: /headless /ScriptBackend mono
# Unity 2021.2 and above changed Headless mode. It seems require Dedicated Server currently and investigating alternative api to enable batch mode.
# - name: Execute UnitTest
# run: ./src/MemoryPack.Unity/bin/UnitTest/StandaloneLinux64_Mono2x/test -batchmode

# Execute scripts: Export Package
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
- name: Build Unity (.unitypacakge)
uses: Cysharp/Actions/.github/actions/unity-builder@main
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: src/MemoryPack.Unity
unityVersion: ${{ matrix.unity }}
targetPlatform: StandaloneLinux64
buildMethod: PackageExporter.Export

- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
with:
directory: src/MemoryPack.Unity
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,17 @@ jobs:

build-unity:
needs: [update-packagejson]
strategy:
matrix:
unity: ["2021.3.11f1"]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- run: echo ${{ needs.update-packagejson.outputs.sha }}
- uses: actions/checkout@v3
with:
ref: ${{ needs.update-packagejson.outputs.sha }}
# Execute scripts: Export Package
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
- name: Build Unity (.unitypacakge)
uses: Cysharp/Actions/.github/actions/unity-builder@main
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: src/MemoryPack.Unity
unityVersion: ${{ matrix.unity }}
targetPlatform: StandaloneLinux64
buildMethod: PackageExporter.Export

# check meta files
- uses: Cysharp/Actions/.github/actions/check-metas@main
with:
directory: src/MemoryPack.Unity
# Store artifacts.
- uses: actions/upload-artifact@v3
with:
name: MemoryPack.${{ inputs.tag }}.unitypackage
path: ./src/MemoryPack.Unity/MemoryPack.${{ inputs.tag }}.unitypackage
if-no-files-found: error

# release
create-release:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ src/MemoryPack.Unity/Logs/*
src/MemoryPack.Unity/*.csproj
src/MemoryPack.Unity/*.sln
src/MemoryPack.Unity/MemoryPack.*.unitypackage

.DS_Store
27 changes: 0 additions & 27 deletions MemoryPack.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandboxNet6", "sandbox\Sand
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{C56A9A52-EE3A-44A5-A8EA-AE36C79FFB6C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostBuildUtility", "tools\PostBuildUtility\PostBuildUtility.csproj", "{06384E50-13CE-4AA2-90B3-5EC116B06D01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Tests.Roslyn3", "tests\MemoryPack.Tests.Roslyn3\MemoryPack.Tests.Roslyn3.csproj", "{E2C01D05-E7F1-4151-B536-90B138AF18EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Generator.Roslyn3", "src\MemoryPack.Generator.Roslyn3\MemoryPack.Generator.Roslyn3.csproj", "{0F57F162-9C68-4E0F-B89B-2EED31B69F38}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary", "sandbox\ClassLibrary\ClassLibrary.csproj", "{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeAot", "sandbox\NativeAot\NativeAot.csproj", "{6E18AECF-34B2-48F9-9694-54150FB156EB}"
Expand Down Expand Up @@ -112,24 +106,6 @@ Global
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Release|Any CPU.Build.0 = Release|Any CPU
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.ActiveCfg = Release|Any CPU
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.Build.0 = Release|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Release|Any CPU.Build.0 = Release|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.WinBenchmark|Any CPU.ActiveCfg = WinBenchmark|Any CPU
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.WinBenchmark|Any CPU.Build.0 = WinBenchmark|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Release|Any CPU.Build.0 = Release|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Release|Any CPU.Build.0 = Release|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -169,9 +145,6 @@ Global
{F9D66CB1-8D28-426B-BB12-C9F5D30EC6A0} = {796FB992-A35C-405B-82A7-4C90C5673174}
{64B20612-4990-40C7-8191-E2A033CD1EF5} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF}
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2} = {796FB992-A35C-405B-82A7-4C90C5673174}
{06384E50-13CE-4AA2-90B3-5EC116B06D01} = {C56A9A52-EE3A-44A5-A8EA-AE36C79FFB6C}
{E2C01D05-E7F1-4151-B536-90B138AF18EF} = {204004F9-9B91-4DD1-812C-80D629169ED5}
{0F57F162-9C68-4E0F-B89B-2EED31B69F38} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF}
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE} = {796FB992-A35C-405B-82A7-4C90C5673174}
{6E18AECF-34B2-48F9-9694-54150FB156EB} = {796FB992-A35C-405B-82A7-4C90C5673174}
{5612B811-586A-4EB3-9AE7-60CAD4969A1B} = {796FB992-A35C-405B-82A7-4C90C5673174}
Expand Down
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public abstract class MemoryPackCustomFormatterAttribute<T> : Attribute
}
```

MemorySharp provides the following formatting attributes: `Utf8StringFormatterAttribute`, `Utf16StringFormatterAttribute`, `InternStringFormatterAttribute`, `OrdinalIgnoreCaseStringDictionaryFormatterAttribute<TValue>`, `BitPackFormatterAttribute`, `BrotliFormatter`, `BrotliStringFormatter`, `BrotliFormatter<T>`, `MemoryPoolFormatter<T>`, `ReadOnlyMemoryPoolFormatter<T>`.
MemoryPack provides the following formatting attributes: `Utf8StringFormatterAttribute`, `Utf16StringFormatterAttribute`, `InternStringFormatterAttribute`, `OrdinalIgnoreCaseStringDictionaryFormatterAttribute<TValue>`, `BitPackFormatterAttribute`, `BrotliFormatter`, `BrotliStringFormatter`, `BrotliFormatter<T>`, `MemoryPoolFormatter<T>`, `ReadOnlyMemoryPoolFormatter<T>`.

```csharp
[MemoryPackable]
Expand Down Expand Up @@ -1311,36 +1311,43 @@ RPC

Unity
---
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
Minimum supported Unity version is `2022.3.12f1`.

If you want to set a target version, MemoryPack uses the `*.*.*` release tag, so you can specify a version like #1.8.0. For example `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack#1.8.0`.
The `MemoryPack` core package is provided by nuget. It is also available in Unity. If you want to get Unity built-in type support, we additionally provide MemoryPack.Unity extension.

Minimum supported 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).
1. Install `MemoryPack` from NuGet using [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)

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.
* Open Window from NuGet -> Manage NuGet Packages, Search "MemoryPack" and Press Install.
![screenshot](https://github.com/Cysharp/MemoryPack/assets/727159/599ff1ed-6cca-4724-be67-3edddb5e62ee)

* If you encount version conflicts error, please disable version validation in Player Settings(Edit -> Project Settings -> Player -> Scroll down and expand "Other Settings" than uncheck "Assembly Version Validation" under the "Configuration" section).

2. Install the `MemoryPack.Unity` package by referencing the git URL

* `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/MemoryPack.Unity`
![screenshot](https://github.com/Cysharp/ZLogger/assets/46207/7325d266-05b4-47c9-b06a-a67a40368dd2)
![screenshot](https://github.com/Cysharp/MemoryPack/assets/727159/9a4af1df-ce07-49d7-9420-922dfb139b55)


MemoryPack uses the *.*.* release tag, so you can specify a version like #1.0.0. For example: `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/MemoryPack.Unity#1.0.0`


As with the .NET version, the code is generated by a code generator (`MemoryPack.Generator.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).

Source Generator is also used officially by Unity by [com.unity.properties](https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/index.html) and [com.unity.entities](https://docs.unity3d.com/Packages/com.unity.properties@2.0/changelog/CHANGELOG.html). In other words, it is the standard for code generation in the next generation of Unity.

Unity version does not support CustomFormatter and ImmutableCollections.
> [!WARNING]
> Unity version does not support CustomFormatter.

You can serialize all unmanaged types (such as `Vector3`, `Rect`, etc...) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`). If you want to serialize other Unity-specific types, see [Serialize external types](#serialize-external-types) section.

In Unity performance, MemoryPack is x3~x10 faster than JsonUtility.

![image](https://user-images.githubusercontent.com/46207/209254561-79ec18fe-c421-4d8c-9c86-b55276dd1a45.png)

Unity version's MemoryPack does not compatible with .NET MemoryPack in NuGet so can't do creating netstandard 2.1 dll in .NET and use in Unity. If you want to share type between .NET and Unity, share source-code, for example place source code in Unity directory and .NET project reference by code link.

```xml
<ItemGroup>
<Compile Include="..\ChatApp.Unity\Assets\Scripts\ServerShared\**\*.cs" />
</ItemGroup>
```

If shared code has Unity's type(`Vector2`, etc...), MemoryPack provides `MemoryPack.UnityShims` package in NuGet.

The `MemoryPack.UnityShims` package provides shims for Unity's standard structs (`Vector2`, `Vector3`, `Vector4`, `Quaternion`, `Color`, `Bounds`, `Rect`, `Keyframe`, `WrapMode`, `Matrix4x4`, `GradientColorKey`, `GradientAlphaKey`, `GradientMode`, `Color32`, `LayerMask`, `Vector2Int`, `Vector3Int`, `RangeInt`, `RectInt`, `BoundsInt`) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`).
Expand Down
2 changes: 1 addition & 1 deletion sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<PublishAot>true</PublishAot>
<!-- <PublishAot>true</PublishAot> -->
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/MemoryPack.Core/Compression/BrotliCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ public void CopyTo<TBufferWriter>(in TBufferWriter destBufferWriter)
var writtenNotAdvanced = 0;
foreach (var item in bufferWriter)
{
writtenNotAdvanced = CompressCore(ref encoder, item.Span, ref Unsafe.AsRef(destBufferWriter), initialLength: null, isFinalBlock: false);
writtenNotAdvanced = CompressCore(ref encoder, item.Span, ref Unsafe.AsRef(in destBufferWriter), initialLength: null, isFinalBlock: false);
}

// call BrotliEncoderOperation.Finish
var finalBlockLength = (writtenNotAdvanced == 0) ? null : (int?)(writtenNotAdvanced + 10);
CompressCore(ref encoder, ReadOnlySpan<byte>.Empty, ref Unsafe.AsRef(destBufferWriter), initialLength: finalBlockLength, isFinalBlock: true);
CompressCore(ref encoder, ReadOnlySpan<byte>.Empty, ref Unsafe.AsRef(in destBufferWriter), initialLength: finalBlockLength, isFinalBlock: true);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class MemoryPackableFormatter<T> : MemoryPackFormatter<T>
[Preserve]
public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, scoped ref T? value)
{
T.Serialize(ref writer, ref Unsafe.AsRef(value));
T.Serialize(ref writer, ref Unsafe.AsRef(in value));
}

[Preserve]
Expand Down
15 changes: 0 additions & 15 deletions src/MemoryPack.Core/MemoryPack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,4 @@
</Compile>
</ItemGroup>

<!-- Copy files for Unity -->
<PropertyGroup>
<DestinationRoot>$(MSBuildProjectDirectory)\..\MemoryPack.Unity\Assets\Plugins\MemoryPack\Runtime\MemoryPack.Core</DestinationRoot>
</PropertyGroup>
<ItemGroup>
<TargetFiles1 Include="$(MSBuildProjectDirectory)\**\*.cs" Exclude="**\bin\**\*.*;**\obj\**\*.*;**\CollectionsMarshalEx.cs;**\ImmutableCollectionFormatters.cs" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="$(TargetFramework) == 'net7.0'">
<Copy SourceFiles="@(TargetFiles1)" DestinationFiles="$(DestinationRoot)\%(RecursiveDir)%(Filename)%(Extension)" SkipUnchangedFiles="true" />

<!-- After copy, replace for unity codes -->
<Exec Command="dotnet run -c $(ConfigurationName) --project $(MSBuildProjectDirectory)\..\..\tools\PostBuildUtility\PostBuildUtility.csproj -- $(DestinationRoot)" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static unsafe void Serialize<TBufferWriter>(Type type, in TBufferWriter b

try
{
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(bufferWriter), state);
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(in bufferWriter), state);
Serialize(type, ref writer, value);
}
finally
Expand Down
2 changes: 1 addition & 1 deletion src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static unsafe void Serialize<T, TBufferWriter>(in TBufferWriter bufferWri

try
{
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(bufferWriter), state);
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(in bufferWriter), state);
Serialize(ref writer, value);
}
finally
Expand Down
14 changes: 7 additions & 7 deletions src/MemoryPack.Core/MemoryPackWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void WriteUtf16(string? value)
Unsafe.WriteUnaligned(ref dest, value.Length);

#if NET7_0_OR_GREATER
ref var src = ref Unsafe.As<char, byte>(ref Unsafe.AsRef(value.GetPinnableReference()));
ref var src = ref Unsafe.As<char, byte>(ref Unsafe.AsRef(in value.GetPinnableReference()));
Unsafe.CopyBlockUnaligned(ref Unsafe.Add(ref dest, 4), ref src, (uint)copyByteCount);
#else
MemoryMarshal.AsBytes(value.AsSpan()).CopyTo(MemoryMarshal.CreateSpan(ref Unsafe.Add(ref dest, 4), copyByteCount));
Expand Down Expand Up @@ -405,7 +405,7 @@ public void WritePackable<T>(scoped in T? value)
{
depth++;
if (depth == DepthLimit) MemoryPackSerializationException.ThrowReachedDepthLimit(typeof(T));
T.Serialize(ref this, ref Unsafe.AsRef(value));
T.Serialize(ref this, ref Unsafe.AsRef(in value));
depth--;
}

Expand All @@ -426,7 +426,7 @@ public void WriteValue<T>(scoped in T? value)
{
depth++;
if (depth == DepthLimit) MemoryPackSerializationException.ThrowReachedDepthLimit(typeof(T));
GetFormatter<T>().Serialize(ref this, ref Unsafe.AsRef(value));
GetFormatter<T>().Serialize(ref this, ref Unsafe.AsRef(in value));
depth--;
}

Expand All @@ -444,7 +444,7 @@ public void WriteValueWithFormatter<TFormatter, T>(TFormatter formatter, scoped
where TFormatter : IMemoryPackFormatter<T>
{
depth++;
formatter.Serialize(ref this, ref Unsafe.AsRef(value));
formatter.Serialize(ref this, ref Unsafe.AsRef(in value));
depth--;
}

Expand Down Expand Up @@ -503,7 +503,7 @@ public void WriteSpan<T>(scoped ReadOnlySpan<T?> value)
WriteCollectionHeader(value.Length);
for (int i = 0; i < value.Length; i++)
{
formatter.Serialize(ref this, ref Unsafe.AsRef(value[i]));
formatter.Serialize(ref this, ref Unsafe.AsRef(in value[i]));
}
}

Expand Down Expand Up @@ -575,7 +575,7 @@ public void WritePackableSpan<T>(scoped ReadOnlySpan<T?> value)
WriteCollectionHeader(value.Length);
for (int i = 0; i < value.Length; i++)
{
T.Serialize(ref this, ref Unsafe.AsRef(value[i]));
T.Serialize(ref this, ref Unsafe.AsRef(in value[i]));
}
#endif
}
Expand Down Expand Up @@ -697,7 +697,7 @@ public void WriteSpanWithoutLengthHeader<T>(scoped ReadOnlySpan<T?> value)
var formatter = GetFormatter<T>();
for (int i = 0; i < value.Length; i++)
{
formatter.Serialize(ref this, ref Unsafe.AsRef(value[i]));
formatter.Serialize(ref this, ref Unsafe.AsRef(in value[i]));
}
}
}
Expand Down
Loading
Loading