Remove unused MessagePack runtime resolvers
This commit is contained in:
parent
949907de65
commit
dc39187119
10 changed files with 9 additions and 449 deletions
|
|
@ -1,226 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class Float2Formatter : MessagePack.Formatters.IMessagePackFormatter<float2>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, float2 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
}
|
||||
|
||||
public float2 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var length = reader.ReadArrayHeader();
|
||||
var x = default(float);
|
||||
var y = default(float);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
x = reader.ReadSingle();
|
||||
break;
|
||||
case 1:
|
||||
y = reader.ReadSingle();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = float2(x, y);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class Int2Formatter : MessagePack.Formatters.IMessagePackFormatter<int2>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, int2 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
}
|
||||
|
||||
public int2 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var length = reader.ReadArrayHeader();
|
||||
var x = default(int);
|
||||
var y = default(int);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
x = reader.ReadInt32();
|
||||
break;
|
||||
case 1:
|
||||
y = reader.ReadInt32();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = int2(x, y);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class Bool2Formatter : MessagePack.Formatters.IMessagePackFormatter<bool2>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, bool2 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
}
|
||||
|
||||
public bool2 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var length = reader.ReadArrayHeader();
|
||||
var x = default(bool);
|
||||
var y = default(bool);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
x = reader.ReadBoolean();
|
||||
break;
|
||||
case 1:
|
||||
y = reader.ReadBoolean();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = bool2(x, y);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class Float3Formatter : MessagePack.Formatters.IMessagePackFormatter<float3>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, float3 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(3);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
writer.Write(value.z);
|
||||
}
|
||||
|
||||
public float3 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var length = reader.ReadArrayHeader();
|
||||
var x = default(float);
|
||||
var y = default(float);
|
||||
var z = default(float);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
x = reader.ReadSingle();
|
||||
break;
|
||||
case 1:
|
||||
y = reader.ReadSingle();
|
||||
break;
|
||||
case 2:
|
||||
z = reader.ReadSingle();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = float3(x, y, z);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class Float4Formatter : MessagePack.Formatters.IMessagePackFormatter<float4>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, float4 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(4);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
writer.Write(value.z);
|
||||
writer.Write(value.w);
|
||||
}
|
||||
|
||||
public float4 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var length = reader.ReadArrayHeader();
|
||||
var x = default(float);
|
||||
var y = default(float);
|
||||
var z = default(float);
|
||||
var w = default(float);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
x = reader.ReadSingle();
|
||||
break;
|
||||
case 1:
|
||||
y = reader.ReadSingle();
|
||||
break;
|
||||
case 2:
|
||||
z = reader.ReadSingle();
|
||||
break;
|
||||
case 3:
|
||||
w = reader.ReadSingle();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = float4(x, y, z, w);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02bc8e83a7f1cf54d94ebebcd3272a0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
|
||||
public class MathResolver : IFormatterResolver
|
||||
{
|
||||
public static readonly MathResolver Instance = new MathResolver();
|
||||
|
||||
private MathResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class FormatterCache<T>
|
||||
{
|
||||
public static readonly IMessagePackFormatter<T> Formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
Formatter = (IMessagePackFormatter<T>)MathResolverResolverGetFormatterHelper.GetFormatter(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class MathResolverResolverGetFormatterHelper
|
||||
{
|
||||
private static readonly Dictionary<Type, object> FormatterMap = new Dictionary<Type, object>()
|
||||
{
|
||||
// standard
|
||||
{ typeof(float2), new Float2Formatter() },
|
||||
{ typeof(int2), new Int2Formatter() },
|
||||
{ typeof(bool2), new Bool2Formatter() },
|
||||
{ typeof(float3), new Float3Formatter() },
|
||||
{ typeof(float4), new Float4Formatter() },
|
||||
{ typeof(float2?), new StaticNullableFormatter<float2>(new Float2Formatter()) },
|
||||
{ typeof(int2?), new StaticNullableFormatter<int2>(new Int2Formatter()) },
|
||||
{ typeof(float3?), new StaticNullableFormatter<float3>(new Float3Formatter()) },
|
||||
{ typeof(float4?), new StaticNullableFormatter<float4>(new Float4Formatter()) },
|
||||
|
||||
// standard + array
|
||||
{ typeof(float2[]), new ArrayFormatter<float2>() },
|
||||
{ typeof(int2[]), new ArrayFormatter<int2>() },
|
||||
{ typeof(float3[]), new ArrayFormatter<float3>() },
|
||||
{ typeof(float4[]), new ArrayFormatter<float4>() },
|
||||
{ typeof(float2?[]), new ArrayFormatter<float2?>() },
|
||||
{ typeof(int2?[]), new ArrayFormatter<float2?>() },
|
||||
{ typeof(float3?[]), new ArrayFormatter<float3?>() },
|
||||
{ typeof(float4?[]), new ArrayFormatter<float4?>() },
|
||||
|
||||
// standard + list
|
||||
{ typeof(List<float2>), new ListFormatter<float2>() },
|
||||
{ typeof(List<int2>), new ListFormatter<int2>() },
|
||||
{ typeof(List<float3>), new ListFormatter<float3>() },
|
||||
{ typeof(List<float4>), new ListFormatter<float4>() },
|
||||
{ typeof(List<float2?>), new ListFormatter<float2?>() },
|
||||
{ typeof(List<int2?>), new ListFormatter<int2?>() },
|
||||
{ typeof(List<float3?>), new ListFormatter<float3?>() },
|
||||
{ typeof(List<float4?>), new ListFormatter<float4?>() },
|
||||
};
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
{
|
||||
object formatter;
|
||||
if (FormatterMap.TryGetValue(t, out formatter))
|
||||
{
|
||||
return formatter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80366c67f842eaf4dba339ed553e447c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
using MessagePack;
|
||||
using MessagePack.ReactivePropertyExtension;
|
||||
using MessagePack.Resolvers;
|
||||
|
||||
public static class RegisterResolver
|
||||
{
|
||||
private static bool registered = false;
|
||||
public static void Register()
|
||||
{
|
||||
if (registered) return;
|
||||
|
||||
// Set extensions to default resolver.
|
||||
var resolver = CompositeResolver.Create(
|
||||
MathResolver.Instance,
|
||||
TypeResolver.Instance,
|
||||
NativeGuidResolver.Instance,
|
||||
StandardResolver.Instance,
|
||||
ReactivePropertyResolver.Instance
|
||||
);
|
||||
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
|
||||
MessagePackSerializer.DefaultOptions = options;
|
||||
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cc638a5fae4350643871d45495a49643
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
|
||||
public class TypeFormatter : MessagePack.Formatters.IMessagePackFormatter<Type>
|
||||
{
|
||||
public static readonly IMessagePackFormatter<Type> Instance = new TypeFormatter();
|
||||
|
||||
private TypeFormatter()
|
||||
{
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, Type value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.Write(value == null ? "" : value.AssemblyQualifiedName);
|
||||
}
|
||||
|
||||
public Type Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
return null; //throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
}
|
||||
|
||||
var assemblyQualifiedName = reader.ReadString();
|
||||
if (string.IsNullOrEmpty(assemblyQualifiedName)) return null;
|
||||
|
||||
return Type.GetType(assemblyQualifiedName);
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeResolver : IFormatterResolver
|
||||
{
|
||||
public static readonly TypeResolver Instance = new TypeResolver();
|
||||
|
||||
private TypeResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static object GetFormatterHelper(Type t)
|
||||
{
|
||||
if (t == typeof(Type))
|
||||
{
|
||||
return TypeFormatter.Instance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class FormatterCache<T>
|
||||
{
|
||||
public static readonly IMessagePackFormatter<T> Formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
Formatter = (IMessagePackFormatter<T>)GetFormatterHelper(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ede4e7a24e20d134fb02868d010af83d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue