From eb6b93bb63794566ebb4d36e37ea173782851c79 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 23 Jul 2022 08:03:47 -0600 Subject: [PATCH] Revise the fix slightly --- .../MessagePackSerializer.NonGeneric.cs | 22 ++++++++++++++++--- .../MessagePack/MessagePackSerializer.cs | 12 ---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs index 019eb8e78..bd6f9b431 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs @@ -82,6 +82,22 @@ public static object Deserialize(Type type, ReadOnlySequence bytes, Messag return GetOrAdd(type).Deserialize_ReadOnlySequence_Options_CancellationToken.Invoke(bytes, options, cancellationToken); } + /// + /// Helper method used by reflection. + /// + private static void SerializeSemiGeneric(ref MessagePackWriter writer, object valueObject, MessagePackSerializerOptions options = null) + { + Serialize(ref writer, (T)valueObject, options); + } + + /// + /// Helper method used by reflection. + /// + private static object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) + { + return Deserialize(ref reader, options); + } + private static async ValueTask DeserializeObjectAsync(Stream stream, MessagePackSerializerOptions options, CancellationToken cancellationToken) => await DeserializeAsync(stream, options, cancellationToken).ConfigureAwait(false); private static CompiledMethods GetOrAdd(Type type) @@ -219,8 +235,8 @@ internal CompiledMethods(Type type) } { - // public static void Serialize(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options) - MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(Object), typeof(MessagePackSerializerOptions) }); + // private static void SerializeSemiGeneric(ref MessagePackWriter writer, object obj, MessagePackSerializerOptions options) + MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(object), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Serialize_MessagePackWriter_T_Options = (ref MessagePackWriter x, object y, MessagePackSerializerOptions z) => ThrowRefStructNotSupported(); #else @@ -229,7 +245,7 @@ internal CompiledMethods(Type type) } { - // public static T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + // private static object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options) MethodInfo deserialize = GetMethod(nameof(DeserializeSemiGeneric), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); #if ENABLE_IL2CPP this.Deserialize_MessagePackReader_Options = (ref MessagePackReader reader, MessagePackSerializerOptions options) => { ThrowRefStructNotSupported(); return null; }; diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index 9510ea893..8c4a454c6 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -71,13 +71,6 @@ public static void Serialize(IBufferWriter writer, T value, MessagePack fastWriter.Flush(); } - internal static void SerializeSemiGeneric(ref MessagePackWriter writer, Object valueObject, MessagePackSerializerOptions options = null) - { - T value = (T)valueObject; - - Serialize(ref writer, value, options); - } - /// /// Serializes a given value with the specified buffer writer. /// @@ -271,11 +264,6 @@ public static T Deserialize(ref MessagePackReader reader, MessagePackSerializ } } - internal static Object DeserializeSemiGeneric(ref MessagePackReader reader, MessagePackSerializerOptions options = null) - { - return Deserialize(ref reader, options); - } - /// /// Deserializes a value of a given type from a sequence of bytes. ///