diff options
author | Yoshifumi Kawai <ils@neue.cc> | 2020-01-19 18:01:35 +0300 |
---|---|---|
committer | Yoshifumi Kawai <ils@neue.cc> | 2020-01-19 18:01:35 +0300 |
commit | f5b557e03f3ac1d3b3f024026c1cab2ac00f8d83 (patch) | |
tree | 9737b110c4776ee01d78bab49df86d91a7b8d35c | |
parent | 9de03c0bb4dd1c308f0a6c97f73bba01961587ec (diff) |
improve BigInteger serialize in .NET Core
-rw-r--r-- | src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StandardClassLibraryFormatter.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StandardClassLibraryFormatter.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StandardClassLibraryFormatter.cs index c82f1a0a..83326d54 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StandardClassLibraryFormatter.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/StandardClassLibraryFormatter.cs @@ -465,6 +465,22 @@ namespace MessagePack.Formatters public void Serialize(ref MessagePackWriter writer, System.Numerics.BigInteger value, MessagePackSerializerOptions options) { +#if NETCOREAPP2_1 + if (!writer.OldSpec) + { + // try to get bin8 buffer. + var span = writer.GetSpan(byte.MaxValue); + if (value.TryWriteBytes(span.Slice(2), out var written)) + { + span[0] = MessagePackCode.Bin8; + span[1] = (byte)written; + + writer.Advance(written + 2); + return; + } + } +#endif + writer.Write(value.ToByteArray()); return; } |