Skip to content

Commit

Permalink
Merge pull request #3 from AArnott/pr1461
Browse files Browse the repository at this point in the history
Revise the fix slightly
  • Loading branch information
MaximMikhisor committed Jul 24, 2022
2 parents 287c4f7 + eb6b93b commit d75c56a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public static object Deserialize(Type type, ReadOnlySequence<byte> bytes, Messag
return GetOrAdd(type).Deserialize_ReadOnlySequence_Options_CancellationToken.Invoke(bytes, options, cancellationToken);
}

/// <summary>
/// Helper method used by reflection.
/// </summary>
private static void SerializeSemiGeneric<T>(ref MessagePackWriter writer, object valueObject, MessagePackSerializerOptions options = null)
{
Serialize(ref writer, (T)valueObject, options);
}

/// <summary>
/// Helper method used by reflection.
/// </summary>
private static object DeserializeSemiGeneric<T>(ref MessagePackReader reader, MessagePackSerializerOptions options = null)
{
return Deserialize<T>(ref reader, options);
}

private static async ValueTask<object> DeserializeObjectAsync<T>(Stream stream, MessagePackSerializerOptions options, CancellationToken cancellationToken) => await DeserializeAsync<T>(stream, options, cancellationToken).ConfigureAwait(false);

private static CompiledMethods GetOrAdd(Type type)
Expand Down Expand Up @@ -219,8 +235,8 @@ internal CompiledMethods(Type type)
}

{
// public static void Serialize<T>(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<T>(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
Expand All @@ -229,7 +245,7 @@ internal CompiledMethods(Type type)
}

{
// public static T Deserialize<T>(ref MessagePackReader reader, MessagePackSerializerOptions options)
// private static object DeserializeSemiGeneric<T>(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; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ public static void Serialize<T>(IBufferWriter<byte> writer, T value, MessagePack
fastWriter.Flush();
}

internal static void SerializeSemiGeneric<T>(ref MessagePackWriter writer, Object valueObject, MessagePackSerializerOptions options = null)
{
T value = (T)valueObject;

Serialize(ref writer, value, options);
}

/// <summary>
/// Serializes a given value with the specified buffer writer.
/// </summary>
Expand Down Expand Up @@ -271,11 +264,6 @@ public static T Deserialize<T>(ref MessagePackReader reader, MessagePackSerializ
}
}

internal static Object DeserializeSemiGeneric<T>(ref MessagePackReader reader, MessagePackSerializerOptions options = null)
{
return Deserialize<T>(ref reader, options);
}

/// <summary>
/// Deserializes a value of a given type from a sequence of bytes.
/// </summary>
Expand Down

0 comments on commit d75c56a

Please sign in to comment.