Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Nov 16, 2022
2 parents 9ee151c + f5897bd commit 67f66bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/MemoryPack.Core/IMemoryPackFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ public abstract void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter
[Preserve]
void IMemoryPackFormatter.Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, scoped ref object? value)
{
var v = (T?)value;
var v = (value == null)
? default(T?)
: (T?)value;
Serialize(ref writer, ref v);
}

[Preserve]
void IMemoryPackFormatter.Deserialize(ref MemoryPackReader reader, scoped ref object? value)
{
var v = (T?)value;
var v = (value == null)
? default(T?)
: (T?)value;
Deserialize(ref reader, ref v);
value = v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ public abstract void Serialize(ref MemoryPackWriter writer, ref T? value)
[Preserve]
void IMemoryPackFormatter.Serialize(ref MemoryPackWriter writer, ref object? value)
{
var v = (T?)value;
var v = (value == null)
? default(T?)
: (T?)value;
Serialize(ref writer, ref v);
}

[Preserve]
void IMemoryPackFormatter.Deserialize(ref MemoryPackReader reader, ref object? value)
{
var v = (T?)value;
var v = (value == null)
? default(T?)
: (T?)value;
Deserialize(ref reader, ref v);
value = v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.cysharp.memorypack",
"displayName": "MemoryPack",
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
"version": "1.7.3",
"version": "1.7.4",
"unity": "2021.3",
"description": "Zero encoding extreme performance binary serializer for C#.",
"keywords": [ "Serialization" ],
Expand Down
11 changes: 11 additions & 0 deletions tests/MemoryPack.Tests/PrimitiveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ public void ArrayWriterInt()
var i = MemoryPackSerializer.Deserialize<int>(buffer.WrittenSpan);
i.Should().Be(123);
}

[Fact]
public void NonGenericInt()
{
var bin = MemoryPackSerializer.Serialize(123);
var i = MemoryPackSerializer.Deserialize<int>(bin);
i.Should().Be(123);

var j = (int)MemoryPackSerializer.Deserialize(typeof(int), bin)!;
j.Should().Be(123);
}
}

0 comments on commit 67f66bc

Please sign in to comment.