share xUnit test between unity and netcore and modify to run in unity
This commit is contained in:
Родитель
a717c7d734
Коммит
785ea71e43
|
@ -1,153 +0,0 @@
|
|||
// ChainingAssertion for Unity
|
||||
// https://github.com/neuecc/ChainingAssertion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace RuntimeUnitTestToolkit
|
||||
{
|
||||
public static partial class AssertExtensions
|
||||
{
|
||||
/// <summary>Assert.AreEqual.</summary>
|
||||
public static void Is<T>(this T actual, T expected, string message = "")
|
||||
{
|
||||
Assert.AreEqual(expected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsTrue(predicate(value))</summary>
|
||||
public static void Is<T>(this T value, Func<T, bool> predicate, string message = "")
|
||||
{
|
||||
Assert.IsTrue(predicate(value), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, params T[] expected)
|
||||
{
|
||||
IsCollection(actual, expected.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, string message = "")
|
||||
{
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray(), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, IEqualityComparer<T> comparer, string message = "")
|
||||
{
|
||||
IsCollection(actual, expected, comparer.Equals, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, Func<T, T, bool> equalityComparison, string message = "")
|
||||
{
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray(), new ComparisonComparer<T>(equalityComparison), message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreNotEqual</summary>
|
||||
public static void IsNot<T>(this T actual, T notExpected, string message = "")
|
||||
{
|
||||
Assert.AreNotEqual(notExpected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, params T[] notExpected)
|
||||
{
|
||||
IsNotCollection(actual, notExpected.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, string message = "")
|
||||
{
|
||||
CollectionAssert.AreNotEqual(notExpected.ToArray(), actual.ToArray(), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, IEqualityComparer<T> comparer, string message = "")
|
||||
{
|
||||
IsNotCollection(actual, notExpected, comparer.Equals, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, Func<T, T, bool> equalityComparison, string message = "")
|
||||
{
|
||||
CollectionAssert.AreNotEqual(notExpected.ToArray(), actual.ToArray(), new ComparisonComparer<T>(equalityComparison), message);
|
||||
}
|
||||
|
||||
/// <summary>Asset Collefction is empty?</summary>
|
||||
public static void IsEmpty<T>(this IEnumerable<T> source)
|
||||
{
|
||||
source.Any().IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNull</summary>
|
||||
public static void IsNull<T>(this T value, string message = "")
|
||||
{
|
||||
Assert.IsNull(value, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNotNull</summary>
|
||||
public static void IsNotNull<T>(this T value, string message = "")
|
||||
{
|
||||
Assert.IsNotNull(value, message);
|
||||
}
|
||||
|
||||
/// <summary>Is(true)</summary>
|
||||
public static void IsTrue(this bool value, string message = "")
|
||||
{
|
||||
value.Is(true, message);
|
||||
}
|
||||
|
||||
/// <summary>Is(false)</summary>
|
||||
public static void IsFalse(this bool value, string message = "")
|
||||
{
|
||||
value.Is(false, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreSame</summary>
|
||||
public static void IsSameReferenceAs<T>(this T actual, T expected, string message = "")
|
||||
{
|
||||
Assert.AreSame(expected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreNotSame</summary>
|
||||
public static void IsNotSameReferenceAs<T>(this T actual, T notExpected, string message = "")
|
||||
{
|
||||
Assert.AreNotSame(notExpected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsInstanceOf</summary>
|
||||
public static TExpected IsInstanceOf<TExpected>(this object value, string message = "")
|
||||
{
|
||||
Assert.IsInstanceOf<TExpected>(value, message);
|
||||
return (TExpected)value;
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNotInstanceOf</summary>
|
||||
public static void IsNotInstanceOf<TWrong>(this object value, string message = "")
|
||||
{
|
||||
Assert.IsNotInstanceOf<TWrong>(value, message);
|
||||
}
|
||||
|
||||
/// <summary>EqualityComparison to IComparer Converter for CollectionAssert</summary>
|
||||
private class ComparisonComparer<T> : IComparer
|
||||
{
|
||||
readonly Func<T, T, bool> comparison;
|
||||
|
||||
public ComparisonComparer(Func<T, T, bool> comparison)
|
||||
{
|
||||
this.comparison = comparison;
|
||||
}
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
return (this.comparison != null)
|
||||
? this.comparison((T)x, (T)y) ? 0 : -1
|
||||
: object.Equals(x, y) ? 0 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -136,6 +136,15 @@ public static partial class UnitTestBuilder
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Test/LoadUnitTestScene")]
|
||||
public static void LoadUnitTestScene()
|
||||
{
|
||||
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
||||
BuildUnitTestRunnerScene();
|
||||
EditorSceneManager.MarkSceneDirty(scene);
|
||||
}
|
||||
|
||||
static RuntimeUnitTestSettings LoadOrGetDefaultSettings()
|
||||
{
|
||||
var key = SettingsKeyBase + Application.productName;
|
||||
|
@ -512,4 +521,4 @@ public static partial class UnitTestBuilder
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace RuntimeUnitTestToolkit
|
|||
{
|
||||
UnityEngine.Application.logMessageReceived += (a, b, c) =>
|
||||
{
|
||||
logText.text += "[" + c + "]" + a + "\n";
|
||||
AppendToGraphicText("[" + c + "]" + a + "\n");
|
||||
};
|
||||
|
||||
// register all test types
|
||||
|
@ -169,7 +169,7 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
}
|
||||
|
||||
NEXT_ASSEMBLY:
|
||||
NEXT_ASSEMBLY:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,30 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid).");
|
||||
var testData = GetTestData(item);
|
||||
if (testData.Count != 0)
|
||||
{
|
||||
foreach (var item2 in testData)
|
||||
{
|
||||
Func<IEnumerator> factory;
|
||||
if (item.IsGenericMethod)
|
||||
{
|
||||
var method2 = InferGenericType(item, item2);
|
||||
factory = () => (IEnumerator)method2.Invoke(test, item2);
|
||||
}
|
||||
else
|
||||
{
|
||||
factory = () => (IEnumerator)item.Invoke(test, item2);
|
||||
}
|
||||
var name = item.Name + "(" + string.Join(", ", item2.Select(x => x?.ToString() ?? "null")) + ")";
|
||||
name = name.Replace(Char.MinValue, ' ').Replace(Char.MaxValue, ' ').Replace("<", "[").Replace(">", "]");
|
||||
AddAsyncTest(test.GetType().Name, name, factory, setups, teardowns);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter without TestCase or return type is invalid).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +291,30 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid).");
|
||||
var testData = GetTestData(item);
|
||||
if (testData.Count != 0)
|
||||
{
|
||||
foreach (var item2 in testData)
|
||||
{
|
||||
Action invoke = null;
|
||||
if (item.IsGenericMethod)
|
||||
{
|
||||
var method2 = InferGenericType(item, item2);
|
||||
invoke = () => method2.Invoke(test, item2);
|
||||
}
|
||||
else
|
||||
{
|
||||
invoke = () => item.Invoke(test, item2);
|
||||
}
|
||||
var name = item.Name + "(" + string.Join(", ", item2.Select(x => x?.ToString() ?? "null")) + ")";
|
||||
name = name.Replace(Char.MinValue, ' ').Replace(Char.MaxValue, ' ').Replace("<", "[").Replace(">", "]");
|
||||
AddTest(test.GetType().Name, name, invoke, setups, teardowns);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter without TestCase or return type is invalid).");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +330,88 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
}
|
||||
|
||||
List<object[]> GetTestData(MethodInfo methodInfo)
|
||||
{
|
||||
List<object[]> testCases = new List<object[]>();
|
||||
|
||||
var inlineData = methodInfo.GetCustomAttributes<NUnit.Framework.TestCaseAttribute>(true);
|
||||
foreach (var item in inlineData)
|
||||
{
|
||||
testCases.Add(item.Arguments);
|
||||
}
|
||||
|
||||
var sourceData = methodInfo.GetCustomAttributes<NUnit.Framework.TestCaseSourceAttribute>(true);
|
||||
foreach (var item in sourceData)
|
||||
{
|
||||
var enumerator = GetTestCaseSource(methodInfo, item.SourceType, item.SourceName, item.MethodParams);
|
||||
foreach (var item2 in enumerator)
|
||||
{
|
||||
var item3 = item2 as IEnumerable; // object[][]
|
||||
if (item3 != null)
|
||||
{
|
||||
var l = new List<object>();
|
||||
foreach (var item4 in item3)
|
||||
{
|
||||
l.Add(item4);
|
||||
}
|
||||
testCases.Add(l.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return testCases;
|
||||
}
|
||||
|
||||
IEnumerable GetTestCaseSource(MethodInfo method, Type sourceType, string sourceName, object[] methodParams)
|
||||
{
|
||||
Type type = sourceType ?? method.DeclaringType;
|
||||
|
||||
MemberInfo[] member = type.GetMember(sourceName, BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
|
||||
if (member.Length == 1)
|
||||
{
|
||||
MemberInfo memberInfo = member[0];
|
||||
FieldInfo fieldInfo = memberInfo as FieldInfo;
|
||||
if ((object)fieldInfo != null)
|
||||
{
|
||||
return (!fieldInfo.IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null) ? ((IEnumerable)fieldInfo.GetValue(null)) : ReturnErrorAsParameter("You have specified a data source field but also given a set of parameters. Fields cannot take parameters, please revise the 3rd parameter passed to the TestCaseSourceAttribute and either remove it or specify a method."));
|
||||
}
|
||||
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
|
||||
if ((object)propertyInfo != null)
|
||||
{
|
||||
return (!propertyInfo.GetGetMethod(nonPublic: true).IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null) ? ((IEnumerable)propertyInfo.GetValue(null, null)) : ReturnErrorAsParameter("You have specified a data source property but also given a set of parameters. Properties cannot take parameters, please revise the 3rd parameter passed to the TestCaseSource attribute and either remove it or specify a method."));
|
||||
}
|
||||
MethodInfo methodInfo = memberInfo as MethodInfo;
|
||||
if ((object)methodInfo != null)
|
||||
{
|
||||
return (!methodInfo.IsStatic) ? ReturnErrorAsParameter("The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method.") : ((methodParams == null || methodInfo.GetParameters().Length == methodParams.Length) ? ((IEnumerable)methodInfo.Invoke(null, methodParams)) : ReturnErrorAsParameter("You have given the wrong number of arguments to the method in the TestCaseSourceAttribute, please check the number of parameters passed in the object is correct in the 3rd parameter for the TestCaseSourceAttribute and this matches the number of parameters in the target method and try again."));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
MethodInfo InferGenericType(MethodInfo methodInfo, object[] parameters)
|
||||
{
|
||||
var set = new HashSet<Type>();
|
||||
List<Type> genericParameters = new List<Type>();
|
||||
foreach (var item in methodInfo.GetParameters()
|
||||
.Select((x, i) => new { x.ParameterType, i })
|
||||
.Where(x => x.ParameterType.IsGenericParameter)
|
||||
.OrderBy(x => x.ParameterType.GenericParameterPosition))
|
||||
{
|
||||
if (set.Add(item.ParameterType)) // DistinctBy
|
||||
{
|
||||
genericParameters.Add(parameters[item.i].GetType());
|
||||
}
|
||||
}
|
||||
|
||||
return methodInfo.MakeGenericMethod(genericParameters.ToArray());
|
||||
}
|
||||
|
||||
IEnumerable ReturnErrorAsParameter(string name)
|
||||
{
|
||||
throw new Exception(name);
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator ScrollLogToEndNextFrame()
|
||||
{
|
||||
yield return null;
|
||||
|
@ -306,7 +434,7 @@ namespace RuntimeUnitTestToolkit
|
|||
|
||||
var allGreen = true;
|
||||
|
||||
logText.text += "<color=yellow>" + actionList.Key + "</color>\n";
|
||||
AppendToGraphicText("<color=yellow>" + actionList.Key + "</color>\n");
|
||||
WriteToConsole("Begin Test Class: " + actionList.Key);
|
||||
yield return null;
|
||||
|
||||
|
@ -326,7 +454,7 @@ namespace RuntimeUnitTestToolkit
|
|||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
logText.text += "<color=teal>" + item2.Key + "</color>\n";
|
||||
AppendToGraphicText("<color=teal>" + item2.Key + "</color>\n");
|
||||
yield return null;
|
||||
|
||||
var v = item2.Value;
|
||||
|
@ -368,14 +496,14 @@ namespace RuntimeUnitTestToolkit
|
|||
totalExecutionTime.Add(methodStopwatch.Elapsed.TotalMilliseconds);
|
||||
if (exception == null)
|
||||
{
|
||||
logText.text += "OK, " + methodStopwatch.Elapsed.TotalMilliseconds.ToString("0.00") + "ms\n";
|
||||
AppendToGraphicText("OK, " + methodStopwatch.Elapsed.TotalMilliseconds.ToString("0.00") + "ms\n");
|
||||
WriteToConsoleResult(item2.Key + ", " + methodStopwatch.Elapsed.TotalMilliseconds.ToString("0.00") + "ms", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// found match line...
|
||||
var line = string.Join("\n", exception.StackTrace.Split('\n').Where(x => x.Contains(actionList.Key) || x.Contains(item2.Key)).ToArray());
|
||||
logText.text += "<color=red>" + exception.Message + "\n" + line + "</color>\n";
|
||||
AppendToGraphicText("<color=red>" + exception.Message + "\n" + line + "</color>\n");
|
||||
WriteToConsoleResult(item2.Key + ", " + exception.Message, false);
|
||||
WriteToConsole(line);
|
||||
allGreen = false;
|
||||
|
@ -391,7 +519,7 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
}
|
||||
|
||||
logText.text += "[" + actionList.Key + "]" + totalExecutionTime.Sum().ToString("0.00") + "ms\n\n";
|
||||
AppendToGraphicText("[" + actionList.Key + "]" + totalExecutionTime.Sum().ToString("0.00") + "ms\n\n");
|
||||
foreach (var btn in list.GetComponentsInChildren<Button>()) btn.interactable = true;
|
||||
if (self != null)
|
||||
{
|
||||
|
@ -480,6 +608,21 @@ namespace RuntimeUnitTestToolkit
|
|||
}
|
||||
}
|
||||
|
||||
void AppendToGraphicText(string msg)
|
||||
{
|
||||
if (!Application.isBatchMode)
|
||||
{
|
||||
try
|
||||
{
|
||||
logText.text += msg;
|
||||
}
|
||||
catch
|
||||
{
|
||||
logText.text = ""; // clear
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteToConsoleResult(string msg, bool green)
|
||||
{
|
||||
if (Application.isBatchMode)
|
||||
|
|
|
@ -0,0 +1,309 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 11
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 256
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 1
|
||||
m_PVRDenoiserTypeDirect: 1
|
||||
m_PVRDenoiserTypeIndirect: 1
|
||||
m_PVRDenoiserTypeAO: 1
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ShowResolutionOverlay: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_UseShadowmask: 1
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &40532277
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 40532279}
|
||||
- component: {fileID: 40532278}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &40532278
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 40532277}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 9
|
||||
m_Type: 1
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 1
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 4
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &40532279
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 40532277}
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
--- !u!1 &615848358
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 615848361}
|
||||
- component: {fileID: 615848360}
|
||||
- component: {fileID: 615848359}
|
||||
- component: {fileID: 615848362}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &615848359
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 615848358}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &615848360
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 615848358}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &615848361
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 615848358}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &615848362
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 615848358}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ef6ee41dd7e44fb448f9e956f3010f4e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MessagePack;
|
||||
using UnityEngine;
|
||||
using System.Buffers;
|
||||
|
||||
public class SandboxBehaviour : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
// 'あ' is [227, 129, 130]
|
||||
var bin = MessagePackSerializer.Serialize(new string('あ', 11));
|
||||
|
||||
// expected: 217, 33, 227, 129, 130, 227, 129, 130, ....
|
||||
// actual: 217, 33, 227, 227, 227, 227, 227, 227, 227, 227
|
||||
UnityEngine.Debug.Log(string.Join(", ", bin));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleBufferWriter : IBufferWriter<byte>
|
||||
{
|
||||
public byte[] buffer = new byte[1024];
|
||||
public int index;
|
||||
|
||||
public void Advance(int count)
|
||||
{
|
||||
index += count;
|
||||
}
|
||||
|
||||
public Memory<byte> GetMemory(int sizeHint = 0)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public Span<byte> GetSpan(int sizeHint = 0)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
@ -102,5 +100,3 @@ namespace MessagePack.Formatters
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MessagePack.Formatters
|
||||
{
|
||||
|
@ -52,69 +51,4 @@ namespace MessagePack.Formatters
|
|||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GenericEnumFormatter<T> : IMessagePackFormatter<T>
|
||||
where T : Enum
|
||||
{
|
||||
private delegate void EnumSerialize(ref MessagePackWriter writer, ref T value);
|
||||
|
||||
private delegate T EnumDeserialize(ref MessagePackReader reader);
|
||||
|
||||
private readonly EnumSerialize serializer;
|
||||
private readonly EnumDeserialize deserializer;
|
||||
|
||||
public GenericEnumFormatter()
|
||||
{
|
||||
var underlyingType = typeof(T).GetEnumUnderlyingType();
|
||||
switch (Type.GetTypeCode(underlyingType))
|
||||
{
|
||||
#pragma warning disable SA1107 // Avoid multiple statements on same line.
|
||||
case TypeCode.Byte:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Byte>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadByte(); return Unsafe.As<Byte, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int16:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int16>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt16(); return Unsafe.As<Int16, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int32:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int32>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt32(); return Unsafe.As<Int32, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int64:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int64>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt64(); return Unsafe.As<Int64, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.SByte:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, SByte>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadSByte(); return Unsafe.As<SByte, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt16:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt16>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt16(); return Unsafe.As<UInt16, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt32:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt32>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt32(); return Unsafe.As<UInt32, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt64:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt64>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt64(); return Unsafe.As<UInt64, T>(ref v); };
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
#pragma warning restore SA1107 // Avoid multiple statements on same line.
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options)
|
||||
{
|
||||
serializer(ref writer, ref value);
|
||||
}
|
||||
|
||||
public T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
return deserializer(ref reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MessagePack.Formatters
|
||||
{
|
||||
public sealed class GenericEnumFormatter<T> : IMessagePackFormatter<T>
|
||||
where T : Enum
|
||||
{
|
||||
private delegate void EnumSerialize(ref MessagePackWriter writer, ref T value);
|
||||
|
||||
private delegate T EnumDeserialize(ref MessagePackReader reader);
|
||||
|
||||
private readonly EnumSerialize serializer;
|
||||
private readonly EnumDeserialize deserializer;
|
||||
|
||||
public GenericEnumFormatter()
|
||||
{
|
||||
var underlyingType = typeof(T).GetEnumUnderlyingType();
|
||||
switch (Type.GetTypeCode(underlyingType))
|
||||
{
|
||||
#pragma warning disable SA1107 // Avoid multiple statements on same line.
|
||||
case TypeCode.Byte:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Byte>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadByte(); return Unsafe.As<Byte, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int16:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int16>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt16(); return Unsafe.As<Int16, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int32:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int32>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt32(); return Unsafe.As<Int32, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.Int64:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, Int64>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadInt64(); return Unsafe.As<Int64, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.SByte:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, SByte>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadSByte(); return Unsafe.As<SByte, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt16:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt16>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt16(); return Unsafe.As<UInt16, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt32:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt32>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt32(); return Unsafe.As<UInt32, T>(ref v); };
|
||||
break;
|
||||
case TypeCode.UInt64:
|
||||
serializer = (ref MessagePackWriter writer, ref T value) => writer.Write(Unsafe.As<T, UInt64>(ref value));
|
||||
deserializer = (ref MessagePackReader reader) => { var v = reader.ReadUInt64(); return Unsafe.As<UInt64, T>(ref v); };
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
#pragma warning restore SA1107 // Avoid multiple statements on same line.
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options)
|
||||
{
|
||||
serializer(ref writer, ref value);
|
||||
}
|
||||
|
||||
public T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
return deserializer(ref reader);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
|
||||
|
@ -101,4 +99,3 @@ namespace MessagePack.Formatters
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,8 +52,6 @@ namespace MessagePack
|
|||
throw new FormatterNotRegisteredException(t.FullName + " is not registered in this resolver. resolver:" + resolver.GetType().Name);
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
public static object GetFormatterDynamic(this IFormatterResolver resolver, Type type)
|
||||
{
|
||||
MethodInfo methodInfo = typeof(IFormatterResolver).GetRuntimeMethod(nameof(IFormatterResolver.GetFormatter), Type.EmptyTypes);
|
||||
|
@ -61,8 +59,6 @@ namespace MessagePack
|
|||
var formatter = methodInfo.MakeGenericMethod(type).Invoke(resolver, null);
|
||||
return formatter;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public class FormatterNotRegisteredException : Exception
|
||||
|
|
|
@ -417,9 +417,7 @@ namespace MessagePack.Internal
|
|||
/// </remarks>
|
||||
public static class AutomataKeyGen
|
||||
{
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
public static readonly MethodInfo GetKeyMethod = typeof(AutomataKeyGen).GetRuntimeMethod(nameof(GetKey), new[] { typeof(ReadOnlySpan<byte>).MakeByRefType() });
|
||||
#endif
|
||||
|
||||
public static ulong GetKey(ref ReadOnlySpan<byte> span)
|
||||
{
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
@ -71,5 +69,3 @@ namespace MessagePack.Internal
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -397,5 +395,3 @@ namespace MessagePack.Internal
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,25 +32,25 @@ namespace MessagePack
|
|||
return (Byte)byteResult;
|
||||
case MessagePackCode.Int8:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryRead(out sbyte sbyteResult));
|
||||
return (Byte)sbyteResult;
|
||||
return checked((Byte)sbyteResult);
|
||||
case MessagePackCode.UInt16:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out ushort ushortResult));
|
||||
return (Byte)ushortResult;
|
||||
return checked((Byte)ushortResult);
|
||||
case MessagePackCode.Int16:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out short shortResult));
|
||||
return (Byte)shortResult;
|
||||
return checked((Byte)shortResult);
|
||||
case MessagePackCode.UInt32:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out uint uintResult));
|
||||
return (Byte)uintResult;
|
||||
return checked((Byte)uintResult);
|
||||
case MessagePackCode.Int32:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out int intResult));
|
||||
return (Byte)intResult;
|
||||
return checked((Byte)intResult);
|
||||
case MessagePackCode.UInt64:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out ulong ulongResult));
|
||||
return (Byte)ulongResult;
|
||||
return checked((Byte)ulongResult);
|
||||
case MessagePackCode.Int64:
|
||||
ThrowInsufficientBufferUnless(this.reader.TryReadBigEndian(out long longResult));
|
||||
return (Byte)longResult;
|
||||
return checked((Byte)longResult);
|
||||
default:
|
||||
if (code >= MessagePackCode.MinNegativeFixInt && code <= MessagePackCode.MaxNegativeFixInt)
|
||||
{
|
||||
|
|
|
@ -611,6 +611,8 @@ namespace MessagePack
|
|||
int byteLength = this.GetStringLengthInBytes();
|
||||
|
||||
ReadOnlySpan<byte> unreadSpan = this.reader.UnreadSpan;
|
||||
//UnityEngine.Debug.Log(reader.CurrentSpan[0]);
|
||||
//UnityEngine.Debug.Log(unreadSpan[0]);
|
||||
if (unreadSpan.Length >= byteLength)
|
||||
{
|
||||
// Fast path: all bytes to decode appear in the same span.
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -217,5 +215,3 @@ namespace MessagePack
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,21 +16,13 @@ namespace MessagePack
|
|||
/// <summary>
|
||||
/// A good default set of options that uses the <see cref="Resolvers.StandardResolver"/> and no compression.
|
||||
/// </summary>
|
||||
public static readonly MessagePackSerializerOptions Standard = new MessagePackSerializerOptions();
|
||||
public static MessagePackSerializerOptions Standard => MessagePackSerializerOptionsDefaultSettingsLazyInitializationHelper.Standard;
|
||||
|
||||
/// <summary>
|
||||
/// A good default set of options that includes LZ4 compression and uses the <see cref="Resolvers.StandardResolver"/>.
|
||||
/// </summary>
|
||||
public static readonly MessagePackSerializerOptions LZ4Standard = Standard.WithLZ4Compression(true);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MessagePackSerializerOptions"/> class
|
||||
/// with default options.
|
||||
/// </summary>
|
||||
private MessagePackSerializerOptions()
|
||||
: this(Resolvers.StandardResolver.Instance, useLZ4Compression: false)
|
||||
{
|
||||
}
|
||||
public static MessagePackSerializerOptions LZ4Standard => MessagePackSerializerOptionsDefaultSettingsLazyInitializationHelper.LZ4Standard;
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
@ -92,5 +84,13 @@ namespace MessagePack
|
|||
/// <param name="oldSpec">The new value for the <see cref="OldSpec"/>.</param>
|
||||
/// <returns>The new instance; or the original if the value is unchanged.</returns>
|
||||
public MessagePackSerializerOptions WithOldSpec(bool? oldSpec = true) => this.OldSpec != oldSpec ? new MessagePackSerializerOptions(this.Resolver, this.UseLZ4Compression, oldSpec) : this;
|
||||
|
||||
#if !DYNAMICCODEDUMPER
|
||||
static class MessagePackSerializerOptionsDefaultSettingsLazyInitializationHelper
|
||||
{
|
||||
public static readonly MessagePackSerializerOptions Standard = new MessagePackSerializerOptions(Resolvers.StandardResolver.Instance, useLZ4Compression: false);
|
||||
public static readonly MessagePackSerializerOptions LZ4Standard = Standard.WithLZ4Compression(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,12 +136,10 @@ namespace MessagePack.Internal
|
|||
{ typeof(ArraySegment<byte>), ByteArraySegmentFormatter.Instance },
|
||||
{ typeof(ArraySegment<byte>?), new StaticNullableFormatter<ArraySegment<byte>>(ByteArraySegmentFormatter.Instance) },
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
{ typeof(System.Numerics.BigInteger), BigIntegerFormatter.Instance },
|
||||
{ typeof(System.Numerics.BigInteger?), new StaticNullableFormatter<System.Numerics.BigInteger>(BigIntegerFormatter.Instance) },
|
||||
{ typeof(System.Numerics.Complex), ComplexFormatter.Instance },
|
||||
{ typeof(System.Numerics.Complex?), new StaticNullableFormatter<System.Numerics.Complex>(ComplexFormatter.Instance) },
|
||||
#endif
|
||||
};
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using MessagePack.Formatters;
|
||||
|
@ -73,5 +71,3 @@ namespace MessagePack.Resolvers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Reflection;
|
||||
|
@ -125,5 +123,3 @@ namespace MessagePack.Resolvers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -124,14 +124,6 @@ namespace MessagePack.Internal
|
|||
{
|
||||
return CreateInstance(typeof(KeyValuePairFormatter<,>), ti.GenericTypeArguments);
|
||||
}
|
||||
else if (isNullable && nullableElementType.GetTypeInfo().IsConstructedGenericType() && nullableElementType.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
|
||||
{
|
||||
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
|
||||
}
|
||||
else if (isNullable && nullableElementType.IsConstructedGenericType && nullableElementType.GetGenericTypeDefinition() == typeof(ValueTask<>))
|
||||
{
|
||||
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
|
||||
}
|
||||
|
||||
// Tuple
|
||||
else if (ti.FullName.StartsWith("System.Tuple"))
|
||||
|
@ -219,16 +211,11 @@ namespace MessagePack.Internal
|
|||
return CreateInstance(typeof(ArraySegmentFormatter<>), ti.GenericTypeArguments);
|
||||
}
|
||||
}
|
||||
else if (isNullable && nullableElementType.GetTypeInfo().IsConstructedGenericType() && nullableElementType.GetGenericTypeDefinition() == typeof(ArraySegment<>))
|
||||
|
||||
// Standard Nullable
|
||||
else if (isNullable)
|
||||
{
|
||||
if (nullableElementType == typeof(ArraySegment<byte>))
|
||||
{
|
||||
return new StaticNullableFormatter<ArraySegment<byte>>(ByteArraySegmentFormatter.Instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
|
||||
}
|
||||
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
|
||||
}
|
||||
|
||||
// Mapped formatter
|
||||
|
@ -260,6 +247,10 @@ namespace MessagePack.Internal
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (ti.IsEnum)
|
||||
{
|
||||
return typeof(GenericEnumFormatter<>).MakeGenericType(ti.GetElementType());
|
||||
}
|
||||
else
|
||||
{
|
||||
// NonGeneric Collection
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
@ -2022,5 +2020,3 @@ namespace MessagePack.Internal
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,8 +17,6 @@ using MessagePack.Internal;
|
|||
|
||||
namespace MessagePack.Resolvers
|
||||
{
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
/// <summary>
|
||||
/// UnionResolver by dynamic code generation.
|
||||
/// </summary>
|
||||
|
@ -481,8 +479,7 @@ namespace MessagePack.Resolvers
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
|
|
|
@ -25,9 +25,7 @@ namespace MessagePack.Resolvers
|
|||
/// </summary>
|
||||
public static readonly MessagePackSerializerOptions Options;
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
public static readonly IMessagePackFormatter<object> ObjectFallbackFormatter = new DynamicObjectTypeFallbackFormatter(StandardResolverCore.Instance);
|
||||
#endif
|
||||
|
||||
static StandardResolver()
|
||||
{
|
||||
|
@ -53,7 +51,7 @@ namespace MessagePack.Resolvers
|
|||
if (typeof(T) == typeof(object))
|
||||
{
|
||||
// final fallback
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
#if !ENABLE_IL2CPP
|
||||
Formatter = (IMessagePackFormatter<T>)ObjectFallbackFormatter;
|
||||
#else
|
||||
Formatter = PrimitiveObjectResolver.Instance.GetFormatter<T>();
|
||||
|
@ -85,9 +83,7 @@ namespace MessagePack.Resolvers
|
|||
Options = new MessagePackSerializerOptions(Instance);
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
public static readonly IMessagePackFormatter<object> ObjectFallbackFormatter = new DynamicObjectTypeFallbackFormatter(ContractlessStandardResolverCore.Instance);
|
||||
#endif
|
||||
|
||||
private ContractlessStandardResolver()
|
||||
{
|
||||
|
@ -107,7 +103,7 @@ namespace MessagePack.Resolvers
|
|||
if (typeof(T) == typeof(object))
|
||||
{
|
||||
// final fallback
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
#if !ENABLE_IL2CPP
|
||||
Formatter = (IMessagePackFormatter<T>)ObjectFallbackFormatter;
|
||||
#else
|
||||
Formatter = PrimitiveObjectResolver.Instance.GetFormatter<T>();
|
||||
|
@ -139,9 +135,7 @@ namespace MessagePack.Resolvers
|
|||
Options = new MessagePackSerializerOptions(Instance);
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
public static readonly IMessagePackFormatter<object> ObjectFallbackFormatter = new DynamicObjectTypeFallbackFormatter(StandardResolverAllowPrivateCore.Instance);
|
||||
#endif
|
||||
|
||||
private StandardResolverAllowPrivate()
|
||||
{
|
||||
|
@ -161,7 +155,7 @@ namespace MessagePack.Resolvers
|
|||
if (typeof(T) == typeof(object))
|
||||
{
|
||||
// final fallback
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
#if !ENABLE_IL2CPP
|
||||
Formatter = (IMessagePackFormatter<T>)ObjectFallbackFormatter;
|
||||
#else
|
||||
Formatter = PrimitiveObjectResolver.Instance.GetFormatter<T>();
|
||||
|
@ -193,9 +187,7 @@ namespace MessagePack.Resolvers
|
|||
Options = new MessagePackSerializerOptions(Instance);
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
public static readonly IMessagePackFormatter<object> ObjectFallbackFormatter = new DynamicObjectTypeFallbackFormatter(ContractlessStandardResolverAllowPrivateCore.Instance);
|
||||
#endif
|
||||
|
||||
private ContractlessStandardResolverAllowPrivate()
|
||||
{
|
||||
|
@ -215,7 +207,7 @@ namespace MessagePack.Resolvers
|
|||
if (typeof(T) == typeof(object))
|
||||
{
|
||||
// final fallback
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
#if !ENABLE_IL2CPP
|
||||
Formatter = (IMessagePackFormatter<T>)ObjectFallbackFormatter;
|
||||
#else
|
||||
Formatter = PrimitiveObjectResolver.Instance.GetFormatter<T>();
|
||||
|
@ -243,11 +235,13 @@ namespace MessagePack.Internal
|
|||
MessagePack.Unity.UnityResolver.Instance,
|
||||
#endif
|
||||
|
||||
DynamicGenericResolver.Instance, // Try Array, Tuple, Collection
|
||||
|
||||
#if !ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicEnumResolver.Instance, // Try Enum
|
||||
#endif
|
||||
|
||||
DynamicGenericResolver.Instance, // Try Array, Tuple, Collection, Enum(Generic Fallback)
|
||||
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicUnionResolver.Instance, // Try Union(Interface)
|
||||
#endif
|
||||
};
|
||||
|
@ -259,7 +253,7 @@ namespace MessagePack.Internal
|
|||
|
||||
private static readonly IFormatterResolver[] Resolvers = StandardResolverHelper.DefaultResolvers.Concat(new IFormatterResolver[]
|
||||
{
|
||||
#if !ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicObjectResolver.Instance, // Try Object
|
||||
#endif
|
||||
}).ToArray();
|
||||
|
@ -298,7 +292,7 @@ namespace MessagePack.Internal
|
|||
|
||||
private static readonly IFormatterResolver[] Resolvers = StandardResolverHelper.DefaultResolvers.Concat(new IFormatterResolver[]
|
||||
{
|
||||
#if !ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicObjectResolver.Instance, // Try Object
|
||||
DynamicContractlessObjectResolver.Instance, // Serializes keys as strings
|
||||
#endif
|
||||
|
@ -338,7 +332,7 @@ namespace MessagePack.Internal
|
|||
|
||||
private static readonly IFormatterResolver[] Resolvers = StandardResolverHelper.DefaultResolvers.Concat(new IFormatterResolver[]
|
||||
{
|
||||
#if !ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicObjectResolverAllowPrivate.Instance, // Try Object
|
||||
#endif
|
||||
}).ToArray();
|
||||
|
@ -377,7 +371,7 @@ namespace MessagePack.Internal
|
|||
|
||||
private static readonly IFormatterResolver[] Resolvers = StandardResolverHelper.DefaultResolvers.Concat(new IFormatterResolver[]
|
||||
{
|
||||
#if !ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER && !NET_STANDARD_2_0
|
||||
#if !ENABLE_IL2CPP && !NET_STANDARD_2_0
|
||||
DynamicObjectResolverAllowPrivate.Instance, // Try Object
|
||||
DynamicContractlessObjectResolverAllowPrivate.Instance, // Serializes keys as strings
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace MessagePack
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
var array = bytes.ToArray();
|
||||
|
||||
fixed (byte* pBytes = bytes)
|
||||
{
|
||||
return encoding.GetString(pBytes, bytes.Length);
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using SharedData;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class CollectionFormatterTest
|
||||
{
|
||||
private T Convert<T>(T value)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, MsgPackUnsafeDefaultResolver.Options), MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryTestAll()
|
||||
{
|
||||
var dict = new Dictionary<int, int>() { { 1, 100 } };
|
||||
var dict2 = Convert(dict);
|
||||
dict2[1].Is(100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InterfaceDictionaryTest()
|
||||
{
|
||||
var a = (IDictionary<int, int>)new Dictionary<int, int>() { { 1, 100 } };
|
||||
var c = (IDictionary<int, int>)null;
|
||||
|
||||
Convert(a)[1].Is(100);
|
||||
Convert(c).IsNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CollectionTest()
|
||||
{
|
||||
Convert(new[] { 1, 10, 100 }).IsCollection(1, 10, 100);
|
||||
Convert(new List<string> { "1", "10", "100" }).IsCollection("1", "10", "100");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,181 +0,0 @@
|
|||
using NUnit.Framework;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using SharedData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class Contractless
|
||||
{
|
||||
T Convert<T>(T value)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Versioning()
|
||||
{
|
||||
var v1 = MessagePackSerializer.Serialize(new V1 { ABCDEFG1 = 10, ABCDEFG3 = 99 });
|
||||
var v2 = MessagePackSerializer.Serialize(new V2 { ABCDEFG1 = 350, ABCDEFG2 = 34, ABCDEFG3 = 500 });
|
||||
|
||||
var v1_1 = MessagePackSerializer.Deserialize<V1>(v1);
|
||||
var v1_2 = MessagePackSerializer.Deserialize<V1>(v2);
|
||||
var v2_1 = MessagePackSerializer.Deserialize<V2>(v1);
|
||||
var v2_2 = MessagePackSerializer.Deserialize<V2>(v2);
|
||||
|
||||
v1_1.ABCDEFG1.Is(10); v1_1.ABCDEFG3.Is(99);
|
||||
v1_2.ABCDEFG1.Is(350); v1_2.ABCDEFG3.Is(500);
|
||||
v2_1.ABCDEFG1.Is(10); v2_1.ABCDEFG2.Is(0); v2_1.ABCDEFG3.Is(99);
|
||||
v2_2.ABCDEFG1.Is(350); v2_2.ABCDEFG2.Is(34); v2_2.ABCDEFG3.Is(500);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DuplicateAutomata()
|
||||
{
|
||||
var bin = MessagePackSerializer.Serialize(new Dup { ABCDEFGH = 10, ABCDEFGHIJKL = 99 });
|
||||
var v = MessagePackSerializer.Deserialize<Dup>(bin);
|
||||
|
||||
v.ABCDEFGH.Is(10);
|
||||
v.ABCDEFGHIJKL.Is(99);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BinSearchSmallCheck()
|
||||
{
|
||||
var o = new BinSearchSmall
|
||||
{
|
||||
MyP1 = 1,
|
||||
MyP2 = 10,
|
||||
MyP3 = 1000,
|
||||
MyP4 = 100000,
|
||||
MyP5 = 32421,
|
||||
MyP6 = 52521,
|
||||
MyP7 = 46363631,
|
||||
MyP8 = 7373731,
|
||||
MyP9 = 73573731,
|
||||
};
|
||||
var bin = MessagePackSerializer.Serialize(o);
|
||||
var v = MessagePackSerializer.Deserialize<BinSearchSmall>(bin);
|
||||
|
||||
v.MyP1.Is(o.MyP1);
|
||||
v.MyP2.Is(o.MyP2);
|
||||
v.MyP3.Is(o.MyP3);
|
||||
v.MyP4.Is(o.MyP4);
|
||||
v.MyP5.Is(o.MyP5);
|
||||
v.MyP6.Is(o.MyP6);
|
||||
v.MyP7.Is(o.MyP7);
|
||||
v.MyP8.Is(o.MyP8);
|
||||
v.MyP9.Is(o.MyP9);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BinSearchWithBranchCheck()
|
||||
{
|
||||
var o = new BinSearchWithBranch
|
||||
{
|
||||
MyProperty1 = 1,
|
||||
MyProperty2 = 10,
|
||||
MyProperty3 = 1000,
|
||||
MyProperty4 = 100000,
|
||||
MyProperty5 = 32421,
|
||||
MyProperty6 = 52521,
|
||||
MyProperty7 = 46363631,
|
||||
MyProperty8 = 7373731,
|
||||
MyProperty9 = 73573731,
|
||||
};
|
||||
var bin = MessagePackSerializer.Serialize(o);
|
||||
var v = MessagePackSerializer.Deserialize<BinSearchWithBranch>(bin);
|
||||
|
||||
v.MyProperty1.Is(o.MyProperty1);
|
||||
v.MyProperty2.Is(o.MyProperty2);
|
||||
v.MyProperty3.Is(o.MyProperty3);
|
||||
v.MyProperty4.Is(o.MyProperty4);
|
||||
v.MyProperty5.Is(o.MyProperty5);
|
||||
v.MyProperty6.Is(o.MyProperty6);
|
||||
v.MyProperty7.Is(o.MyProperty7);
|
||||
v.MyProperty8.Is(o.MyProperty8);
|
||||
v.MyProperty9.Is(o.MyProperty9);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LongestStringCheck()
|
||||
{
|
||||
var o = new LongestString
|
||||
{
|
||||
MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1 = 431413,
|
||||
MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2 = 352525252,
|
||||
MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2MyProperty = 532525252,
|
||||
OAFADFZEWFSDFSDFKSLJFWEFNWOZFUSEWWEFWEWFFFFFFFFFFFFFFZFEWBFOWUEGWHOUDGSOGUDSZNOFRWEUFWGOWHOGHWOG000000000000000000000000000000000000000HOGZ = 3352666,
|
||||
};
|
||||
var bin = MessagePackSerializer.Serialize(o);
|
||||
var v = MessagePackSerializer.Deserialize<LongestString>(bin);
|
||||
|
||||
v.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1.Is(o.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1);
|
||||
v.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2.Is(o.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2);
|
||||
v.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2MyProperty.Is(o.MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2MyProperty);
|
||||
v.OAFADFZEWFSDFSDFKSLJFWEFNWOZFUSEWWEFWEWFFFFFFFFFFFFFFZFEWBFOWUEGWHOUDGSOGUDSZNOFRWEUFWGOWHOGHWOG000000000000000000000000000000000000000HOGZ.Is(o.OAFADFZEWFSDFSDFKSLJFWEFNWOZFUSEWWEFWEWFFFFFFFFFFFFFFZFEWBFOWUEGWHOUDGSOGUDSZNOFRWEUFWGOWHOGHWOG000000000000000000000000000000000000000HOGZ);
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class V1
|
||||
{
|
||||
public int ABCDEFG1 { get; set; }
|
||||
public int ABCDEFG3 { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class V2
|
||||
{
|
||||
public int ABCDEFG1 { get; set; }
|
||||
public int ABCDEFG2 { get; set; }
|
||||
public int ABCDEFG3 { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class Dup
|
||||
{
|
||||
public int ABCDEFGH { get; set; }
|
||||
public int ABCDEFGHIJKL { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class BinSearchSmall
|
||||
{
|
||||
public int MyP1 { get; set; }
|
||||
public int MyP2 { get; set; }
|
||||
public int MyP3 { get; set; }
|
||||
public int MyP4 { get; set; }
|
||||
public int MyP5 { get; set; }
|
||||
public int MyP6 { get; set; }
|
||||
public int MyP7 { get; set; }
|
||||
public int MyP8 { get; set; }
|
||||
public int MyP9 { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class BinSearchWithBranch
|
||||
{
|
||||
public int MyProperty1 { get; set; }
|
||||
public int MyProperty2 { get; set; }
|
||||
public int MyProperty3 { get; set; }
|
||||
public int MyProperty4 { get; set; }
|
||||
public int MyProperty5 { get; set; }
|
||||
public int MyProperty6 { get; set; }
|
||||
public int MyProperty7 { get; set; }
|
||||
public int MyProperty8 { get; set; }
|
||||
public int MyProperty9 { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject(true)]
|
||||
public class LongestString
|
||||
{
|
||||
public int MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1 { get; set; }
|
||||
public int MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2 { get; set; }
|
||||
public int MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty1MyProperty2MyProperty { get; set; }
|
||||
public int OAFADFZEWFSDFSDFKSLJFWEFNWOZFUSEWWEFWEWFFFFFFFFFFFFFFZFEWBFOWUEGWHOUDGSOGUDSZNOFRWEUFWGOWHOGHWOG000000000000000000000000000000000000000HOGZ { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using SharedData;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class FormatterTest
|
||||
{
|
||||
private static T Convert<T>(T value)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, MsgPackUnsafeDefaultResolver.Options), MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrimitiveFormatterTest()
|
||||
{
|
||||
Convert(Int32.MaxValue).Is(Int32.MaxValue);
|
||||
Convert(Double.MinValue).Is(Double.MinValue);
|
||||
Convert(DateTime.MinValue.ToUniversalTime()).Is(DateTime.MinValue.ToUniversalTime());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnumFormatterTest()
|
||||
{
|
||||
Convert(UShortEnum.A).Is(UShortEnum.A);
|
||||
Convert(IntEnum.A).Is(IntEnum.A);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,85 +0,0 @@
|
|||
using System;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class LZ4Test
|
||||
{
|
||||
[Test]
|
||||
public void TestSmall()
|
||||
{
|
||||
new MessagePackReader(MessagePackSerializer.Serialize(100, MessagePackSerializerOptions.LZ4Standard)).NextMessagePackType.Is(MessagePackType.Integer);
|
||||
new MessagePackReader(MessagePackSerializer.Serialize("test", MessagePackSerializerOptions.LZ4Standard)).NextMessagePackType.Is(MessagePackType.String);
|
||||
new MessagePackReader(MessagePackSerializer.Serialize(false, MessagePackSerializerOptions.LZ4Standard)).NextMessagePackType.Is(MessagePackType.Boolean);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompressionData()
|
||||
{
|
||||
var originalData = Enumerable.Range(1, 1000).Select(x => x).ToArray();
|
||||
var lz4Data = MessagePackSerializer.Serialize(originalData, MessagePackSerializerOptions.LZ4Standard);
|
||||
|
||||
var reader = new MessagePackReader(lz4Data);
|
||||
reader.NextMessagePackType.Is(MessagePackType.Extension);
|
||||
var header = reader.ReadExtensionFormatHeader();
|
||||
header.TypeCode.Is((sbyte)MessagePackSerializer.LZ4ExtensionTypeCode);
|
||||
|
||||
var decompress = MessagePackSerializer.Deserialize<int[]>(lz4Data, MessagePackSerializerOptions.LZ4Standard);
|
||||
decompress.IsCollection(originalData);
|
||||
}
|
||||
|
||||
////public void PrimitiveCompression()
|
||||
////{
|
||||
//// var data = Encoding.UTF8.GetBytes("あいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそ");
|
||||
//// var data2 = LZ4.LZ4Codec.Encode32Unsafe(data, 0, data.Length);
|
||||
//// var data3 = LZ4.LZ4Codec.Encode64Unsafe(data, 0, data.Length);
|
||||
//// var bytes = new byte[LZ4.LZ4Codec.MaximumOutputLength(data.Length)];
|
||||
//// var data4Len = LZ4.LZ4Codec.Encode64Unsafe(data, 0, data.Length, bytes, 0, bytes.Length);
|
||||
|
||||
//// var out1 = new byte[data.Length];
|
||||
//// var out2 = new byte[data.Length];
|
||||
//// var out3 = new byte[data.Length];
|
||||
|
||||
//// bytes = MessagePackBinary.FastCloneWithResize(bytes, data4Len);
|
||||
//// var len1 = LZ4.LZ4Codec.Decode32Unsafe(data2, 0, data2.Length, out1, 0, out1.Length, true);
|
||||
//// var len2 = LZ4.LZ4Codec.Decode64Unsafe(data3, 0, data3.Length, out2, 0, out2.Length, true);
|
||||
//// var len3 = LZ4.LZ4Codec.Decode(bytes, 0, bytes.Length, out3, 0, out3.Length, true);
|
||||
|
||||
//// var str1 = Encoding.UTF8.GetString(out1);
|
||||
//// var str2 = Encoding.UTF8.GetString(out2);
|
||||
//// var str3 = Encoding.UTF8.GetString(out3);
|
||||
|
||||
//// str1.Is("あいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそ");
|
||||
//// str2.Is("あいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそ");
|
||||
//// str3.Is("あいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそあいうえおかきくけこさしすせそ");
|
||||
////}
|
||||
|
||||
////public void PrimitiveCompression2()
|
||||
////{
|
||||
//// var originalData = Enumerable.Range(1, 1000).Select(x => x).ToArray();
|
||||
//// var data = MessagePackSerializer.Serialize(originalData);
|
||||
|
||||
//// var data2 = LZ4.LZ4Codec.Encode32(data, 0, data.Length);
|
||||
//// var data3 = LZ4.LZ4Codec.Encode64(data, 0, data.Length);
|
||||
//// var bytes = new byte[LZ4.LZ4Codec.MaximumOutputLength(data.Length)];
|
||||
//// var data4Len = LZ4.LZ4Codec.Encode64(data, 0, data.Length, bytes, 0, bytes.Length);
|
||||
|
||||
//// var out1 = new byte[data.Length];
|
||||
//// var out2 = new byte[data.Length];
|
||||
//// var out3 = new byte[data.Length];
|
||||
|
||||
//// bytes = MessagePackBinary.FastCloneWithResize(bytes, data4Len);
|
||||
//// var len1 = LZ4.LZ4Codec.Decode32(data2, 0, data2.Length, out1, 0, out1.Length, true);
|
||||
//// var len2 = LZ4.LZ4Codec.Decode64(data3, 0, data3.Length, out2, 0, out2.Length, true);
|
||||
//// var len3 = LZ4.LZ4Codec.Decode(bytes, 0, bytes.Length, out3, 0, out3.Length, true);
|
||||
|
||||
//// MessagePackSerializer.Deserialize<int[]>(out1).IsCollection(originalData);
|
||||
//// MessagePackSerializer.Deserialize<int[]>(out2).IsCollection(originalData);
|
||||
//// MessagePackSerializer.Deserialize<int[]>(out3).IsCollection(originalData);
|
||||
////}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using SharedData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -16,18 +15,18 @@ namespace Assets.Scripts.Tests
|
|||
{
|
||||
// adhoc resolver registration to running test.
|
||||
|
||||
var resolver = MessagePack.Resolvers.CompositeResolver.Create(new IMessagePackFormatter[]
|
||||
{
|
||||
new GenericEnumFormatter<UShortEnum>(),
|
||||
new GenericEnumFormatter<IntEnum>(),
|
||||
new NullableFormatter<Vector2>()
|
||||
},
|
||||
new[]{
|
||||
MessagePack.Resolvers.GeneratedResolver.Instance,
|
||||
MessagePack.Resolvers.StandardResolver.Instance
|
||||
});
|
||||
//var resolver = MessagePack.Resolvers.CompositeResolver.Create(new IMessagePackFormatter[]
|
||||
//{
|
||||
// new GenericEnumFormatter<UShortEnum>(),
|
||||
// new GenericEnumFormatter<IntEnum>(),
|
||||
// new NullableFormatter<Vector2>()
|
||||
//},
|
||||
//new[]{
|
||||
// MessagePack.Resolvers.GeneratedResolver.Instance,
|
||||
// MessagePack.Resolvers.StandardResolver.Instance
|
||||
//});
|
||||
|
||||
MessagePackSerializer.DefaultOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver);
|
||||
//MessagePackSerializer.DefaultOptions = MessagePackSerializerOptions.Standard.WithResolver(resolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,231 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// このコードはツールによって生成されました。
|
||||
// ランタイム バージョン:4.0.30319.42000
|
||||
//
|
||||
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
|
||||
// コードが再生成されるときに損失したりします。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Sandbox.Shared.GeneratedSerializers {
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("MsgPack.Serialization.CodeDomSerializers.CodeDomSerializerBuilder", "0.9.0.0")]
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public class PersonSerializer : MsgPack.Serialization.MessagePackSerializer<Person> {
|
||||
|
||||
private MsgPack.Serialization.MessagePackSerializer<int> _serializer0;
|
||||
|
||||
private MsgPack.Serialization.MessagePackSerializer<string> _serializer1;
|
||||
|
||||
private MsgPack.Serialization.MessagePackSerializer<Sex> _serializer2;
|
||||
|
||||
private System.Collections.Generic.IList<System.Action<MsgPack.Packer, Person>> _packOperationList;
|
||||
|
||||
private System.Collections.Generic.IDictionary<string, System.Action<MsgPack.Packer, Person>> _packOperationTable;
|
||||
|
||||
private System.Collections.Generic.IDictionary<string, System.Func<Person, bool>> _nullCheckersTable;
|
||||
|
||||
private System.Action<Person, int> this_SetUnpackedValueOfAgeDelegate;
|
||||
|
||||
private System.Func<MsgPack.Unpacker, System.Type, string, int> MsgPack_Serialization_UnpackHelpers_UnpackInt32ValueDelegate;
|
||||
|
||||
private System.Action<Person, string> this_SetUnpackedValueOfFirstNameDelegate;
|
||||
|
||||
private System.Func<MsgPack.Unpacker, System.Type, string, string> MsgPack_Serialization_UnpackHelpers_UnpackStringValueDelegate;
|
||||
|
||||
private System.Action<Person, string> this_SetUnpackedValueOfLastNameDelegate;
|
||||
|
||||
private System.Action<Person, Sex> this_SetUnpackedValueOfSexDelegate;
|
||||
|
||||
private System.Collections.Generic.IList<string> _memberNames;
|
||||
|
||||
private System.Collections.Generic.IList<System.Action<MsgPack.Unpacker, Person, int, int>> _unpackOperationList;
|
||||
|
||||
private System.Collections.Generic.IDictionary<string, System.Action<MsgPack.Unpacker, Person, int, int>> _unpackOperationTable;
|
||||
|
||||
public PersonSerializer(MsgPack.Serialization.SerializationContext context) :
|
||||
base(context, (MsgPack.Serialization.SerializerCapabilities.PackTo | MsgPack.Serialization.SerializerCapabilities.UnpackFrom)) {
|
||||
MsgPack.Serialization.PolymorphismSchema schema0 = default(MsgPack.Serialization.PolymorphismSchema);
|
||||
schema0 = null;
|
||||
this._serializer0 = context.GetSerializer<int>(schema0);
|
||||
MsgPack.Serialization.PolymorphismSchema schema1 = default(MsgPack.Serialization.PolymorphismSchema);
|
||||
schema1 = null;
|
||||
this._serializer1 = context.GetSerializer<string>(schema1);
|
||||
this._serializer2 = context.GetSerializer<Sex>(MsgPack.Serialization.EnumMessagePackSerializerHelpers.DetermineEnumSerializationMethod(context, typeof(Sex), MsgPack.Serialization.EnumMemberSerializationMethod.Default));
|
||||
System.Action<MsgPack.Packer, Person>[] packOperationList = default(System.Action<MsgPack.Packer, Person>[]);
|
||||
packOperationList = new System.Action<MsgPack.Packer, Person>[4];
|
||||
packOperationList[0] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfAge);
|
||||
packOperationList[1] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfFirstName);
|
||||
packOperationList[2] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfLastName);
|
||||
packOperationList[3] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfSex);
|
||||
this._packOperationList = packOperationList;
|
||||
System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Packer, Person>> packOperationTable = default(System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Packer, Person>>);
|
||||
packOperationTable = new System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Packer, Person>>(4);
|
||||
packOperationTable["Age"] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfAge);
|
||||
packOperationTable["FirstName"] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfFirstName);
|
||||
packOperationTable["LastName"] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfLastName);
|
||||
packOperationTable["Sex"] = new System.Action<MsgPack.Packer, Person>(this.PackValueOfSex);
|
||||
this._packOperationTable = packOperationTable;
|
||||
System.Collections.Generic.Dictionary<string, System.Func<Person, bool>> nullCheckerTable = default(System.Collections.Generic.Dictionary<string, System.Func<Person, bool>>);
|
||||
nullCheckerTable = new System.Collections.Generic.Dictionary<string, System.Func<Person, bool>>(2);
|
||||
nullCheckerTable["FirstName"] = new System.Func<Person, bool>(this.IsFirstNameNull);
|
||||
nullCheckerTable["LastName"] = new System.Func<Person, bool>(this.IsLastNameNull);
|
||||
this._nullCheckersTable = nullCheckerTable;
|
||||
System.Action<MsgPack.Unpacker, Person, int, int>[] unpackOperationList = default(System.Action<MsgPack.Unpacker, Person, int, int>[]);
|
||||
unpackOperationList = new System.Action<MsgPack.Unpacker, Person, int, int>[4];
|
||||
unpackOperationList[0] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfAge);
|
||||
unpackOperationList[1] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfFirstName);
|
||||
unpackOperationList[2] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfLastName);
|
||||
unpackOperationList[3] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfSex);
|
||||
this._unpackOperationList = unpackOperationList;
|
||||
System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Unpacker, Person, int, int>> unpackOperationTable = default(System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Unpacker, Person, int, int>>);
|
||||
unpackOperationTable = new System.Collections.Generic.Dictionary<string, System.Action<MsgPack.Unpacker, Person, int, int>>(4);
|
||||
unpackOperationTable["Age"] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfAge);
|
||||
unpackOperationTable["FirstName"] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfFirstName);
|
||||
unpackOperationTable["LastName"] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfLastName);
|
||||
unpackOperationTable["Sex"] = new System.Action<MsgPack.Unpacker, Person, int, int>(this.UnpackValueOfSex);
|
||||
this._unpackOperationTable = unpackOperationTable;
|
||||
this._memberNames = new string[] {
|
||||
"Age",
|
||||
"FirstName",
|
||||
"LastName",
|
||||
"Sex"};
|
||||
this.this_SetUnpackedValueOfAgeDelegate = new System.Action<Person, int>(this.SetUnpackedValueOfAge);
|
||||
this.MsgPack_Serialization_UnpackHelpers_UnpackInt32ValueDelegate = new System.Func<MsgPack.Unpacker, System.Type, string, int>(MsgPack.Serialization.UnpackHelpers.UnpackInt32Value);
|
||||
this.this_SetUnpackedValueOfFirstNameDelegate = new System.Action<Person, string>(this.SetUnpackedValueOfFirstName);
|
||||
this.MsgPack_Serialization_UnpackHelpers_UnpackStringValueDelegate = new System.Func<MsgPack.Unpacker, System.Type, string, string>(MsgPack.Serialization.UnpackHelpers.UnpackStringValue);
|
||||
this.this_SetUnpackedValueOfLastNameDelegate = new System.Action<Person, string>(this.SetUnpackedValueOfLastName);
|
||||
this.this_SetUnpackedValueOfSexDelegate = new System.Action<Person, Sex>(this.SetUnpackedValueOfSex);
|
||||
}
|
||||
|
||||
private void PackValueOfAge(MsgPack.Packer packer, Person objectTree) {
|
||||
this._serializer0.PackTo(packer, objectTree.Age);
|
||||
}
|
||||
|
||||
private void PackValueOfFirstName(MsgPack.Packer packer, Person objectTree) {
|
||||
this._serializer1.PackTo(packer, objectTree.FirstName);
|
||||
}
|
||||
|
||||
private bool IsFirstNameNull(Person objectTree) {
|
||||
return (objectTree.FirstName == null);
|
||||
}
|
||||
|
||||
private void PackValueOfLastName(MsgPack.Packer packer, Person objectTree) {
|
||||
this._serializer1.PackTo(packer, objectTree.LastName);
|
||||
}
|
||||
|
||||
private bool IsLastNameNull(Person objectTree) {
|
||||
return (objectTree.LastName == null);
|
||||
}
|
||||
|
||||
private void PackValueOfSex(MsgPack.Packer packer, Person objectTree) {
|
||||
this._serializer2.PackTo(packer, objectTree.Sex);
|
||||
}
|
||||
|
||||
protected override void PackToCore(MsgPack.Packer packer, Person objectTree) {
|
||||
MsgPack.Serialization.PackToArrayParameters<Person> packHelperParameters = default(MsgPack.Serialization.PackToArrayParameters<Person>);
|
||||
packHelperParameters.Packer = packer;
|
||||
packHelperParameters.Target = objectTree;
|
||||
packHelperParameters.Operations = this._packOperationList;
|
||||
MsgPack.Serialization.PackToMapParameters<Person> packHelperParameters0 = default(MsgPack.Serialization.PackToMapParameters<Person>);
|
||||
packHelperParameters0.Packer = packer;
|
||||
packHelperParameters0.Target = objectTree;
|
||||
packHelperParameters0.Operations = this._packOperationTable;
|
||||
packHelperParameters0.SerializationContext = this.OwnerContext;
|
||||
packHelperParameters0.NullCheckers = this._nullCheckersTable;
|
||||
if ((this.OwnerContext.SerializationMethod == MsgPack.Serialization.SerializationMethod.Array)) {
|
||||
MsgPack.Serialization.PackHelpers.PackToArray(ref packHelperParameters);
|
||||
}
|
||||
else {
|
||||
MsgPack.Serialization.PackHelpers.PackToMap(ref packHelperParameters0);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUnpackedValueOfAge(Person unpackingContext, int unpackedValue) {
|
||||
unpackingContext.Age = unpackedValue;
|
||||
}
|
||||
|
||||
private void UnpackValueOfAge(MsgPack.Unpacker unpacker, Person unpackingContext, int indexOfItem, int itemsCount) {
|
||||
MsgPack.Serialization.UnpackValueTypeValueParameters<Person, int> unpackHelperParameters = default(MsgPack.Serialization.UnpackValueTypeValueParameters<Person, int>);
|
||||
unpackHelperParameters.Unpacker = unpacker;
|
||||
unpackHelperParameters.UnpackingContext = unpackingContext;
|
||||
unpackHelperParameters.Serializer = this._serializer0;
|
||||
unpackHelperParameters.ItemsCount = itemsCount;
|
||||
unpackHelperParameters.Unpacked = indexOfItem;
|
||||
unpackHelperParameters.TargetObjectType = typeof(int);
|
||||
unpackHelperParameters.MemberName = "Age";
|
||||
unpackHelperParameters.DirectRead = this.MsgPack_Serialization_UnpackHelpers_UnpackInt32ValueDelegate;
|
||||
unpackHelperParameters.Setter = this.this_SetUnpackedValueOfAgeDelegate;
|
||||
MsgPack.Serialization.UnpackHelpers.UnpackValueTypeValue(ref unpackHelperParameters);
|
||||
}
|
||||
|
||||
private void SetUnpackedValueOfFirstName(Person unpackingContext, string unpackedValue) {
|
||||
unpackingContext.FirstName = unpackedValue;
|
||||
}
|
||||
|
||||
private void UnpackValueOfFirstName(MsgPack.Unpacker unpacker, Person unpackingContext, int indexOfItem, int itemsCount) {
|
||||
MsgPack.Serialization.UnpackReferenceTypeValueParameters<Person, string> unpackHelperParameters0 = default(MsgPack.Serialization.UnpackReferenceTypeValueParameters<Person, string>);
|
||||
unpackHelperParameters0.Unpacker = unpacker;
|
||||
unpackHelperParameters0.UnpackingContext = unpackingContext;
|
||||
unpackHelperParameters0.Serializer = this._serializer1;
|
||||
unpackHelperParameters0.ItemsCount = itemsCount;
|
||||
unpackHelperParameters0.Unpacked = indexOfItem;
|
||||
unpackHelperParameters0.TargetObjectType = typeof(string);
|
||||
unpackHelperParameters0.MemberName = "FirstName";
|
||||
unpackHelperParameters0.NilImplication = MsgPack.Serialization.NilImplication.MemberDefault;
|
||||
unpackHelperParameters0.DirectRead = this.MsgPack_Serialization_UnpackHelpers_UnpackStringValueDelegate;
|
||||
unpackHelperParameters0.Setter = this.this_SetUnpackedValueOfFirstNameDelegate;
|
||||
MsgPack.Serialization.UnpackHelpers.UnpackReferenceTypeValue(ref unpackHelperParameters0);
|
||||
}
|
||||
|
||||
private void SetUnpackedValueOfLastName(Person unpackingContext, string unpackedValue) {
|
||||
unpackingContext.LastName = unpackedValue;
|
||||
}
|
||||
|
||||
private void UnpackValueOfLastName(MsgPack.Unpacker unpacker, Person unpackingContext, int indexOfItem, int itemsCount) {
|
||||
MsgPack.Serialization.UnpackReferenceTypeValueParameters<Person, string> unpackHelperParameters1 = default(MsgPack.Serialization.UnpackReferenceTypeValueParameters<Person, string>);
|
||||
unpackHelperParameters1.Unpacker = unpacker;
|
||||
unpackHelperParameters1.UnpackingContext = unpackingContext;
|
||||
unpackHelperParameters1.Serializer = this._serializer1;
|
||||
unpackHelperParameters1.ItemsCount = itemsCount;
|
||||
unpackHelperParameters1.Unpacked = indexOfItem;
|
||||
unpackHelperParameters1.TargetObjectType = typeof(string);
|
||||
unpackHelperParameters1.MemberName = "LastName";
|
||||
unpackHelperParameters1.NilImplication = MsgPack.Serialization.NilImplication.MemberDefault;
|
||||
unpackHelperParameters1.DirectRead = this.MsgPack_Serialization_UnpackHelpers_UnpackStringValueDelegate;
|
||||
unpackHelperParameters1.Setter = this.this_SetUnpackedValueOfLastNameDelegate;
|
||||
MsgPack.Serialization.UnpackHelpers.UnpackReferenceTypeValue(ref unpackHelperParameters1);
|
||||
}
|
||||
|
||||
private void SetUnpackedValueOfSex(Person unpackingContext, Sex unpackedValue) {
|
||||
unpackingContext.Sex = unpackedValue;
|
||||
}
|
||||
|
||||
private void UnpackValueOfSex(MsgPack.Unpacker unpacker, Person unpackingContext, int indexOfItem, int itemsCount) {
|
||||
MsgPack.Serialization.UnpackValueTypeValueParameters<Person, Sex> unpackHelperParameters2 = default(MsgPack.Serialization.UnpackValueTypeValueParameters<Person, Sex>);
|
||||
unpackHelperParameters2.Unpacker = unpacker;
|
||||
unpackHelperParameters2.UnpackingContext = unpackingContext;
|
||||
unpackHelperParameters2.Serializer = this._serializer2;
|
||||
unpackHelperParameters2.ItemsCount = itemsCount;
|
||||
unpackHelperParameters2.Unpacked = indexOfItem;
|
||||
unpackHelperParameters2.TargetObjectType = typeof(Sex);
|
||||
unpackHelperParameters2.MemberName = "Sex";
|
||||
unpackHelperParameters2.DirectRead = null;
|
||||
unpackHelperParameters2.Setter = this.this_SetUnpackedValueOfSexDelegate;
|
||||
MsgPack.Serialization.UnpackHelpers.UnpackValueTypeValue(ref unpackHelperParameters2);
|
||||
}
|
||||
|
||||
protected override Person UnpackFromCore(MsgPack.Unpacker unpacker) {
|
||||
Person result = default(Person);
|
||||
result = new Person();
|
||||
if (unpacker.IsArrayHeader) {
|
||||
return MsgPack.Serialization.UnpackHelpers.UnpackFromArray(unpacker, result, MsgPack.Serialization.UnpackHelpers.GetIdentity<Person>(), this._memberNames, this._unpackOperationList);
|
||||
}
|
||||
else {
|
||||
return MsgPack.Serialization.UnpackHelpers.UnpackFromMap(unpacker, result, MsgPack.Serialization.UnpackHelpers.GetIdentity<Person>(), this._unpackOperationTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// このコードはツールによって生成されました。
|
||||
// ランタイム バージョン:4.0.30319.42000
|
||||
//
|
||||
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
|
||||
// コードが再生成されるときに損失したりします。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Sandbox.Shared.GeneratedSerializers {
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("MsgPack.Serialization.CodeDomSerializers.CodeDomSerializerBuilder", "0.9.0.0")]
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public class SexSerializer : MsgPack.Serialization.EnumMessagePackSerializer<Sex> {
|
||||
|
||||
public SexSerializer(MsgPack.Serialization.SerializationContext context) :
|
||||
this(context, MsgPack.Serialization.EnumSerializationMethod.ByName) {
|
||||
}
|
||||
|
||||
public SexSerializer(MsgPack.Serialization.SerializationContext context, MsgPack.Serialization.EnumSerializationMethod enumSerializationMethod) :
|
||||
base(context, enumSerializationMethod) {
|
||||
}
|
||||
|
||||
protected override void PackUnderlyingValueTo(MsgPack.Packer packer, Sex enumValue) {
|
||||
packer.Pack(((sbyte)(enumValue)));
|
||||
}
|
||||
|
||||
protected override Sex UnpackFromUnderlyingValue(MsgPack.MessagePackObject messagePackObject) {
|
||||
return ((Sex)(messagePackObject.AsSByte()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// このコードはツールによって生成されました。
|
||||
// ランタイム バージョン:4.0.30319.42000
|
||||
//
|
||||
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
|
||||
// コードが再生成されるときに損失したりします。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Sandbox.Shared.GeneratedSerializers {
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("MsgPack.Serialization.CodeDomSerializers.CodeDomSerializerBuilder", "0.9.0.0")]
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public class System_Nullable_1_Sex_Serializer : MsgPack.Serialization.MessagePackSerializer<System.Nullable<Sex>> {
|
||||
|
||||
private MsgPack.Serialization.MessagePackSerializer<Sex> _serializer0;
|
||||
|
||||
public System_Nullable_1_Sex_Serializer(MsgPack.Serialization.SerializationContext context) :
|
||||
base(context) {
|
||||
this._serializer0 = context.GetSerializer<Sex>(MsgPack.Serialization.EnumMessagePackSerializerHelpers.DetermineEnumSerializationMethod(context, typeof(Sex), MsgPack.Serialization.EnumMemberSerializationMethod.Default));
|
||||
}
|
||||
|
||||
protected override void PackToCore(MsgPack.Packer packer, System.Nullable<Sex> objectTree) {
|
||||
this._serializer0.PackTo(packer, objectTree.Value);
|
||||
}
|
||||
|
||||
protected override System.Nullable<Sex> UnpackFromCore(MsgPack.Unpacker unpacker) {
|
||||
return new System.Nullable<Sex>(this._serializer0.UnpackFrom(unpacker));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// このコードはツールによって生成されました。
|
||||
// ランタイム バージョン:4.0.30319.42000
|
||||
//
|
||||
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
|
||||
// コードが再生成されるときに損失したりします。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Sandbox.Shared.GeneratedSerializers {
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("MsgPack.Serialization.CodeDomSerializers.CodeDomSerializerBuilder", "0.9.0.0")]
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public class System_Nullable_1_System_Int32_Serializer : MsgPack.Serialization.MessagePackSerializer<System.Nullable<int>> {
|
||||
|
||||
private MsgPack.Serialization.MessagePackSerializer<int> _serializer0;
|
||||
|
||||
public System_Nullable_1_System_Int32_Serializer(MsgPack.Serialization.SerializationContext context) :
|
||||
base(context) {
|
||||
MsgPack.Serialization.PolymorphismSchema schema0 = default(MsgPack.Serialization.PolymorphismSchema);
|
||||
schema0 = null;
|
||||
this._serializer0 = context.GetSerializer<int>(schema0);
|
||||
}
|
||||
|
||||
protected override void PackToCore(MsgPack.Packer packer, System.Nullable<int> objectTree) {
|
||||
this._serializer0.PackTo(packer, objectTree.Value);
|
||||
}
|
||||
|
||||
protected override System.Nullable<int> UnpackFromCore(MsgPack.Unpacker unpacker) {
|
||||
return new System.Nullable<int>(this._serializer0.UnpackFrom(unpacker));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
using MessagePack.Formatters;
|
||||
using MessagePack.Resolvers;
|
||||
using NUnit.Framework;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using SharedData;
|
||||
using System;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public struct ValueTuple<T1, T2>
|
||||
{
|
||||
public T1 Item1;
|
||||
public T2 Item2;
|
||||
|
||||
public ValueTuple(T1 item1, T2 item2)
|
||||
{
|
||||
Item1 = item1;
|
||||
Item2 = item2;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ValueTuple<T1, T2, T3>
|
||||
{
|
||||
public T1 Item1;
|
||||
public T2 Item2;
|
||||
public T3 Item3;
|
||||
|
||||
public ValueTuple(T1 item1, T2 item2, T3 item3)
|
||||
{
|
||||
Item1 = item1;
|
||||
Item2 = item2;
|
||||
Item3 = item3;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ValueTuple<T1, T2, T3, T4>
|
||||
{
|
||||
public T1 Item1;
|
||||
public T2 Item2;
|
||||
public T3 Item3;
|
||||
public T4 Item4;
|
||||
|
||||
public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4)
|
||||
{
|
||||
Item1 = item1;
|
||||
Item2 = item2;
|
||||
Item3 = item3;
|
||||
Item4 = item4;
|
||||
}
|
||||
}
|
||||
|
||||
public class ValueTupleFormatter<T1, T2> : IMessagePackFormatter<ValueTuple<T1, T2>>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, ValueTuple<T1, T2> value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
|
||||
options.Resolver.GetFormatterWithVerify<T1>().Serialize(ref writer, value.Item1, options);
|
||||
options.Resolver.GetFormatterWithVerify<T2>().Serialize(ref writer, value.Item2, options);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ValueTuple<T1, T2> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("Data is Nil, ValueTuple can not be null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var count = reader.ReadArrayHeader();
|
||||
if (count != 2) throw new InvalidOperationException("Invalid ValueTuple count");
|
||||
|
||||
var item1 = options.Resolver.GetFormatterWithVerify<T1>().Deserialize(ref reader, options);
|
||||
var item2 = options.Resolver.GetFormatterWithVerify<T2>().Deserialize(ref reader, options);
|
||||
|
||||
return new ValueTuple<T1, T2>(item1, item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ValueTupleFormatter<T1, T2, T3> : IMessagePackFormatter<ValueTuple<T1, T2, T3>>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, ValueTuple<T1, T2, T3> value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(3);
|
||||
|
||||
options.Resolver.GetFormatterWithVerify<T1>().Serialize(ref writer, value.Item1, options);
|
||||
options.Resolver.GetFormatterWithVerify<T2>().Serialize(ref writer, value.Item2, options);
|
||||
options.Resolver.GetFormatterWithVerify<T3>().Serialize(ref writer, value.Item3, options);
|
||||
}
|
||||
|
||||
public ValueTuple<T1, T2, T3> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("Data is Nil, ValueTuple can not be null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var count = reader.ReadArrayHeader();
|
||||
if (count != 3) throw new InvalidOperationException("Invalid ValueTuple count");
|
||||
|
||||
var item1 = options.Resolver.GetFormatterWithVerify<T1>().Deserialize(ref reader, options);
|
||||
var item2 = options.Resolver.GetFormatterWithVerify<T2>().Deserialize(ref reader, options);
|
||||
var item3 = options.Resolver.GetFormatterWithVerify<T3>().Deserialize(ref reader, options);
|
||||
|
||||
return new ValueTuple<T1, T2, T3>(item1, item2, item3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ValueTupleFormatter<T1, T2, T3, T4> : IMessagePackFormatter<ValueTuple<T1, T2, T3, T4>>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, ValueTuple<T1, T2, T3, T4> value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(4);
|
||||
|
||||
options.Resolver.GetFormatterWithVerify<T1>().Serialize(ref writer, value.Item1, options);
|
||||
options.Resolver.GetFormatterWithVerify<T2>().Serialize(ref writer, value.Item2, options);
|
||||
options.Resolver.GetFormatterWithVerify<T3>().Serialize(ref writer, value.Item3, options);
|
||||
options.Resolver.GetFormatterWithVerify<T4>().Serialize(ref writer, value.Item4, options);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ValueTuple<T1, T2, T3, T4> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.IsNil)
|
||||
{
|
||||
throw new InvalidOperationException("Data is Nil, ValueTuple can not be null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var count = reader.ReadArrayHeader();
|
||||
if (count != 4) throw new InvalidOperationException("Invalid ValueTuple count");
|
||||
|
||||
var item1 = options.Resolver.GetFormatterWithVerify<T1>().Deserialize(ref reader, options);
|
||||
var item2 = options.Resolver.GetFormatterWithVerify<T2>().Deserialize(ref reader, options);
|
||||
var item3 = options.Resolver.GetFormatterWithVerify<T3>().Deserialize(ref reader, options);
|
||||
var item4 = options.Resolver.GetFormatterWithVerify<T4>().Deserialize(ref reader, options);
|
||||
|
||||
return new ValueTuple<T1, T2, T3, T4>(item1, item2, item3, item4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IntTupleRegistered : IFormatterResolver
|
||||
{
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
if (typeof(T) == typeof(ValueTuple<int, int>))
|
||||
{
|
||||
return (IMessagePackFormatter<T>)(object)new ValueTupleFormatter<int, int>();
|
||||
}
|
||||
if (typeof(T) == typeof(ValueTuple<int, int, int>))
|
||||
{
|
||||
return (IMessagePackFormatter<T>)(object)new ValueTupleFormatter<int, int, int>();
|
||||
}
|
||||
if (typeof(T) == typeof(ValueTuple<int, int, int, int>))
|
||||
{
|
||||
return (IMessagePackFormatter<T>)(object)new ValueTupleFormatter<int, int, int, int>();
|
||||
}
|
||||
return StandardResolver.Instance.GetFormatter<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiDimensionalArrayTest
|
||||
{
|
||||
T Convert<T>(T value)
|
||||
{
|
||||
var options = MessagePackSerializerOptions.Standard.WithResolver(new IntTupleRegistered());
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, options), options);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MDArrayTest()
|
||||
{
|
||||
var dataI = 100;
|
||||
var dataJ = 100;
|
||||
var dataK = 10;
|
||||
var dataL = 5;
|
||||
|
||||
var two = new ValueTuple<int, int>[dataI, dataJ];
|
||||
var three = new ValueTuple<int, int, int>[dataI, dataJ, dataK];
|
||||
var four = new ValueTuple<int, int, int, int>[dataI, dataJ, dataK, dataL];
|
||||
|
||||
for (int i = 0; i < dataI; i++)
|
||||
{
|
||||
for (int j = 0; j < dataJ; j++)
|
||||
{
|
||||
two[i, j] = new ValueTuple<int, int>(i, j);
|
||||
for (int k = 0; k < dataK; k++)
|
||||
{
|
||||
three[i, j, k] = new ValueTuple<int, int, int>(i, j, k);
|
||||
for (int l = 0; l < dataL; l++)
|
||||
{
|
||||
four[i, j, k, l] = new ValueTuple<int, int, int, int>(i, j, k, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cTwo = Convert(two);
|
||||
var cThree = Convert(three);
|
||||
var cFour = Convert(four);
|
||||
|
||||
cTwo.Length.Is(two.Length);
|
||||
cThree.Length.Is(three.Length);
|
||||
cFour.Length.Is(four.Length);
|
||||
|
||||
for (int i = 0; i < dataI; i++)
|
||||
{
|
||||
for (int j = 0; j < dataJ; j++)
|
||||
{
|
||||
cTwo[i, j].Is(two[i, j]);
|
||||
for (int k = 0; k < dataK; k++)
|
||||
{
|
||||
cThree[i, j, k].Is(three[i, j, k]);
|
||||
for (int l = 0; l < dataL; l++)
|
||||
{
|
||||
cFour[i, j, k, l].Is(four[i, j, k, l]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,266 +0,0 @@
|
|||
using RuntimeUnitTestToolkit;
|
||||
using System.Linq;
|
||||
using SharedData;
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class ObjectResolverTest
|
||||
{
|
||||
T Convert<T>(T value)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Standard()
|
||||
{
|
||||
try
|
||||
{
|
||||
var o = new SimpleIntKeyData()
|
||||
{
|
||||
Prop1 = 100,
|
||||
Prop2 = ByteEnum.C,
|
||||
Prop3 = "abcde",
|
||||
Prop4 = new SimpleStringKeyData
|
||||
{
|
||||
Prop1 = 99999,
|
||||
Prop2 = ByteEnum.E,
|
||||
Prop3 = 3
|
||||
},
|
||||
Prop5 = new SimpleStructIntKeyData
|
||||
{
|
||||
X = 100,
|
||||
Y = 300,
|
||||
BytesSpecial = new byte[] { 9, 99, 122 }
|
||||
},
|
||||
Prop6 = new SimpleStructStringKeyData
|
||||
{
|
||||
X = 9999,
|
||||
Y = new[] { 1, 10, 100 }
|
||||
},
|
||||
BytesSpecial = new byte[] { 1, 4, 6 }
|
||||
};
|
||||
|
||||
MessagePackSerializer.Serialize(o);
|
||||
//var c = Convert(o);
|
||||
|
||||
//c.Prop1.Is(o.Prop1);
|
||||
//c.Prop2.Is(o.Prop2);
|
||||
//c.Prop3.Is(o.Prop3);
|
||||
//c.Prop4.Prop1.Is(o.Prop4.Prop1);
|
||||
//c.Prop4.Prop2.Is(o.Prop4.Prop2);
|
||||
//c.Prop4.Prop3.Is(o.Prop4.Prop3);
|
||||
//c.Prop5.X.Is(o.Prop5.X);
|
||||
//c.Prop5.Y.Is(o.Prop5.Y);
|
||||
//c.Prop5.BytesSpecial.SequenceEqual(o.Prop5.BytesSpecial).IsTrue();
|
||||
//c.Prop6.X.Is(o.Prop6.X);
|
||||
//c.Prop6.Y.SequenceEqual(o.Prop6.Y).IsTrue();
|
||||
//c.BytesSpecial.SequenceEqual(o.BytesSpecial).IsTrue();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Null()
|
||||
{
|
||||
SimpleIntKeyData n = null;
|
||||
var bytes = MessagePackSerializer.Serialize(n);
|
||||
new MessagePackReader(bytes).IsNil.IsTrue();
|
||||
bytes.Length.Is(1);
|
||||
|
||||
MessagePackSerializer.Deserialize<SimpleIntKeyData>(bytes).IsNull();
|
||||
|
||||
// deserialize from nil
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
MessagePackSerializer.Deserialize<SimpleStructIntKeyData>(bytes);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithConstructor()
|
||||
{
|
||||
var o = new Vector2(100.4f, 4321.1f);
|
||||
var o2 = Convert(o);
|
||||
o.X.Is(o2.X);
|
||||
o.Y.Is(o2.Y);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Nullable()
|
||||
{
|
||||
Vector2? o = new Vector2(100.4f, 4321.1f);
|
||||
var o2 = Convert(o);
|
||||
o.Value.X.Is(o2.Value.X);
|
||||
o.Value.Y.Is(o2.Value.Y);
|
||||
o = null;
|
||||
Convert(o).IsNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Versioning()
|
||||
{
|
||||
var v1 = new Version1
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
MyProperty2 = 200,
|
||||
MyProperty3 = 300
|
||||
};
|
||||
|
||||
var v2 = new Version2
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
MyProperty2 = 200,
|
||||
MyProperty3 = 300,
|
||||
MyProperty5 = 500,
|
||||
};
|
||||
|
||||
var v0 = new Version0
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
};
|
||||
|
||||
var v1Bytes = MessagePackSerializer.Serialize(v1);
|
||||
var v2Bytes = MessagePackSerializer.Serialize(v2);
|
||||
var v0Bytes = MessagePackSerializer.Serialize(v0);
|
||||
|
||||
var a = MessagePackSerializer.Deserialize<Version1>(v1Bytes);
|
||||
a.MyProperty1.Is(100);
|
||||
a.MyProperty2.Is(200);
|
||||
a.MyProperty3.Is(300);
|
||||
|
||||
var b = MessagePackSerializer.Deserialize<Version2>(v2Bytes);
|
||||
b.MyProperty1.Is(100);
|
||||
b.MyProperty2.Is(200);
|
||||
b.MyProperty3.Is(300);
|
||||
b.MyProperty5.Is(500);
|
||||
|
||||
var c = MessagePackSerializer.Deserialize<Version0>(v0Bytes);
|
||||
c.MyProperty1.Is(100);
|
||||
|
||||
// smaller than schema
|
||||
var v2_ = MessagePackSerializer.Deserialize<Version2>(v1Bytes);
|
||||
v2_.MyProperty1.Is(v1.MyProperty1);
|
||||
v2_.MyProperty2.Is(v1.MyProperty2);
|
||||
v2_.MyProperty3.Is(v1.MyProperty3);
|
||||
v2_.MyProperty5.Is(0);
|
||||
|
||||
// larger than schema
|
||||
|
||||
var v0_ = MessagePackSerializer.Deserialize<Version0>(v1Bytes);
|
||||
v0_.MyProperty1.Is(v1.MyProperty1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Versioning2()
|
||||
{
|
||||
var v1 = new HolderV1
|
||||
{
|
||||
MyProperty1 = new Version1
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
MyProperty2 = 200,
|
||||
MyProperty3 = 300
|
||||
},
|
||||
After = 9999
|
||||
};
|
||||
|
||||
var v2 = new HolderV2
|
||||
{
|
||||
MyProperty1 = new Version2
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
MyProperty2 = 200,
|
||||
MyProperty3 = 300,
|
||||
MyProperty5 = 500
|
||||
},
|
||||
After = 99999999
|
||||
};
|
||||
|
||||
var v0 = new HolderV0
|
||||
{
|
||||
MyProperty1 = new Version0
|
||||
{
|
||||
MyProperty1 = 100,
|
||||
},
|
||||
After = 1999
|
||||
};
|
||||
|
||||
var v1Bytes = MessagePackSerializer.Serialize(v1);
|
||||
var v2Bytes = MessagePackSerializer.Serialize(v2);
|
||||
var v0Bytes = MessagePackSerializer.Serialize(v0);
|
||||
|
||||
// smaller than schema
|
||||
var v2_ = MessagePackSerializer.Deserialize<HolderV2>(v1Bytes);
|
||||
v2_.MyProperty1.MyProperty1.Is(v1.MyProperty1.MyProperty1);
|
||||
v2_.MyProperty1.MyProperty2.Is(v1.MyProperty1.MyProperty2);
|
||||
v2_.MyProperty1.MyProperty3.Is(v1.MyProperty1.MyProperty3);
|
||||
v2_.MyProperty1.MyProperty5.Is(0);
|
||||
v2_.After.Is(9999);
|
||||
|
||||
// larger than schema
|
||||
var v1Json = MessagePackSerializer.ConvertToJson(v1Bytes);
|
||||
var v0_ = MessagePackSerializer.Deserialize<HolderV0>(v1Bytes);
|
||||
v0_.MyProperty1.MyProperty1.Is(v1.MyProperty1.MyProperty1);
|
||||
v0_.After.Is(9999);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializationCallbackTes()
|
||||
{
|
||||
{
|
||||
var before = false;
|
||||
|
||||
var c1 = new Callback2(0, () => before = true, () => { });
|
||||
var d = MessagePackSerializer.Serialize(c1);
|
||||
before.IsTrue();
|
||||
Callback2.CalledAfter = false;
|
||||
MessagePackSerializer.Deserialize<Callback2>(d);
|
||||
Callback2.CalledAfter.IsTrue();
|
||||
}
|
||||
{
|
||||
var c1 = new Callback1_2(0);
|
||||
var d = MessagePackSerializer.Serialize(c1);
|
||||
c1.CalledBefore.IsTrue();
|
||||
MessagePackSerializer.Deserialize<Callback1_2>(d).CalledAfter.IsTrue();
|
||||
}
|
||||
{
|
||||
var before = false;
|
||||
|
||||
var c1 = new Callback2_2(0, () => before = true, () => { });
|
||||
var d = MessagePackSerializer.Serialize(c1);
|
||||
before.IsTrue();
|
||||
|
||||
Callback2.CalledAfter = false;
|
||||
MessagePackSerializer.Deserialize<Callback2_2>(d);
|
||||
Callback2_2.CalledAfter.IsTrue();
|
||||
}
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void GenericClassTest()
|
||||
//{
|
||||
// var t = new GenericClass<int, string> { MyProperty0 = 100, MyProperty1 = "aaa" };
|
||||
// var v = Convert(t);
|
||||
// v.MyProperty0.Is(100);
|
||||
// v.MyProperty1.Is("aaa");
|
||||
//}
|
||||
|
||||
//[Test]
|
||||
//public void GenericStructTest()
|
||||
//{
|
||||
// var t = new GenericStruct<int, string> { MyProperty0 = 100, MyProperty1 = "aaa" };
|
||||
// var v = Convert(t);
|
||||
// v.MyProperty0.Is(100);
|
||||
// v.MyProperty1.Is("aaa");
|
||||
//}
|
||||
}
|
||||
}
|
|
@ -1,534 +0,0 @@
|
|||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using MessagePack.Resolvers;
|
||||
using MsgPack.Serialization;
|
||||
using NUnit.Framework;
|
||||
using Sandbox.Shared;
|
||||
using Sandbox.Shared.GeneratedSerializers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Sandbox.Shared
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
[MessagePackObject]
|
||||
public class Person : IEquatable<Person>
|
||||
{
|
||||
[Key(0)]
|
||||
[DataMember(Order = 0)]
|
||||
public int Age { get; set; }
|
||||
[Key(1)]
|
||||
[DataMember(Order = 1)]
|
||||
public string FirstName { get; set; }
|
||||
[Key(2)]
|
||||
[DataMember(Order = 2)]
|
||||
public string LastName { get; set; }
|
||||
[Key(3)]
|
||||
[DataMember(Order = 3)]
|
||||
public Sex Sex { get; set; }
|
||||
|
||||
public bool Equals(Person other)
|
||||
{
|
||||
return Age == other.Age && FirstName == other.FirstName && LastName == other.LastName && Sex == other.Sex;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Sex : sbyte
|
||||
{
|
||||
Unknown, Male, Female,
|
||||
}
|
||||
}
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
// for JsonUtility:)
|
||||
[Serializable]
|
||||
public class PersonLike
|
||||
{
|
||||
public int Age;
|
||||
public string FirstName;
|
||||
public string LastName;
|
||||
public Sex2 Sex;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PersonLikeVector
|
||||
{
|
||||
public PersonLike[] List;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Vector3ArrayWrapper
|
||||
{
|
||||
public Vector3[] List;
|
||||
}
|
||||
|
||||
|
||||
public enum Sex2 : int
|
||||
{
|
||||
Unknown = 0,
|
||||
Male = 1,
|
||||
Female = 2
|
||||
}
|
||||
|
||||
public class MsgPackUnsafeDefaultResolver : IFormatterResolver
|
||||
{
|
||||
public static readonly IFormatterResolver Instance;
|
||||
|
||||
public static readonly MessagePackSerializerOptions Options;
|
||||
|
||||
public static readonly MessagePackSerializerOptions LZ4Options;
|
||||
|
||||
static MsgPackUnsafeDefaultResolver()
|
||||
{
|
||||
Instance = new MsgPackUnsafeDefaultResolver();
|
||||
Options = MessagePackSerializer.DefaultOptions.WithResolver(Instance);
|
||||
LZ4Options = Options.WithLZ4Compression();
|
||||
}
|
||||
|
||||
MsgPackUnsafeDefaultResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.formatter;
|
||||
}
|
||||
|
||||
static class FormatterCache<T>
|
||||
{
|
||||
public static readonly IMessagePackFormatter<T> formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
#if ENABLE_UNSAFE_MSGPACK
|
||||
formatter = Unity.Extension.UnityBlitResolver.Instance.GetFormatter<T>();
|
||||
#endif
|
||||
if (formatter == null)
|
||||
{
|
||||
formatter = MessagePackSerializer.DefaultOptions.Resolver.GetFormatter<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TempVector3Formatter : global::MessagePack.Formatters.IMessagePackFormatter<Vector3>
|
||||
{
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, Vector3 value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(3);
|
||||
writer.Write(value.x);
|
||||
writer.Write(value.y);
|
||||
writer.Write(value.z);
|
||||
}
|
||||
|
||||
public Vector3 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
var length = reader.ReadArrayHeader();
|
||||
|
||||
var __MyProperty1__ = default(float);
|
||||
var __MyProperty2__ = default(float);
|
||||
var __MyProperty3__ = default(float);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var key = i;
|
||||
switch (key)
|
||||
{
|
||||
case 0:
|
||||
__MyProperty1__ = reader.ReadSingle();
|
||||
break;
|
||||
case 1:
|
||||
__MyProperty2__ = reader.ReadSingle();
|
||||
break;
|
||||
case 2:
|
||||
__MyProperty3__ = reader.ReadSingle();
|
||||
break;
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector3(__MyProperty1__, __MyProperty2__, __MyProperty3__);
|
||||
}
|
||||
}
|
||||
|
||||
public class PerformanceTest
|
||||
{
|
||||
const int Iteration = 500; // 500 iteration.
|
||||
|
||||
Person p;
|
||||
Person[] l;
|
||||
PersonLike p2;
|
||||
PersonLikeVector l2;
|
||||
|
||||
Vector3 v3;
|
||||
Vector3[] v3Array;
|
||||
Vector3ArrayWrapper v3Wrapper;
|
||||
|
||||
byte[] msgPackCSharpFormatterSingleBytes;
|
||||
byte[] msgPackCSharpArrayBytes;
|
||||
byte[] msgPackCSharpLZ4FormatterSingleBytes;
|
||||
byte[] msgPackCSharpLZ4ArrayBytes;
|
||||
byte[] msgpackSingleBytes;
|
||||
byte[] msgpackArrayBytes;
|
||||
byte[] jsonSingleBytes;
|
||||
byte[] jsonArrayBytes;
|
||||
|
||||
byte[] msgPackCSharpv3Bytes;
|
||||
byte[] msgPackCSharpv3ArrayBytes;
|
||||
byte[] msgpackv3Bytes;
|
||||
byte[] msgpackv3ArrayBytes;
|
||||
byte[] jsonv3Bytes;
|
||||
byte[] jsonv3ArrayBytes;
|
||||
|
||||
SerializationContext msgPackContext;
|
||||
|
||||
// Test Initialize:)
|
||||
public PerformanceTest()
|
||||
{
|
||||
// MsgPack Prepare
|
||||
MsgPack.Serialization.MessagePackSerializer.PrepareType<Sex>();
|
||||
this.msgPackContext = new MsgPack.Serialization.SerializationContext();
|
||||
this.msgPackContext.ResolveSerializer += SerializationContext_ResolveSerializer;
|
||||
|
||||
this.p = new Person
|
||||
{
|
||||
Age = 99999,
|
||||
FirstName = "Windows",
|
||||
LastName = "Server",
|
||||
Sex = Sex.Male,
|
||||
};
|
||||
this.p2 = new PersonLike
|
||||
{
|
||||
|
||||
Age = 99999,
|
||||
FirstName = "Windows",
|
||||
LastName = "Server",
|
||||
Sex = Sex2.Male
|
||||
};
|
||||
|
||||
this.l = Enumerable.Range(1000, 1000).Select(x => new Person { Age = x, FirstName = "Windows", LastName = "Server", Sex = Sex.Female }).ToArray();
|
||||
this.l2 = new PersonLikeVector { List = Enumerable.Range(1000, 1000).Select(x => new PersonLike { Age = x, FirstName = "Windows", LastName = "Server", Sex = Sex2.Female }).ToArray() };
|
||||
|
||||
msgPackCSharpFormatterSingleBytes = MessagePackSerializer.Serialize(p, MsgPackUnsafeDefaultResolver.Options);
|
||||
msgPackCSharpArrayBytes = MessagePackSerializer.Serialize(l, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
msgPackCSharpLZ4FormatterSingleBytes = MessagePackSerializer.Serialize(p, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
msgPackCSharpLZ4ArrayBytes = MessagePackSerializer.Serialize(l, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
|
||||
var serializer1 = this.msgPackContext.GetSerializer<Person>();
|
||||
msgpackSingleBytes = serializer1.PackSingleObject(p);
|
||||
var serializer2 = this.msgPackContext.GetSerializer<IList<Person>>();
|
||||
msgpackArrayBytes = serializer2.PackSingleObject(l);
|
||||
|
||||
jsonSingleBytes = Encoding.UTF8.GetBytes(JsonUtility.ToJson(p2));
|
||||
jsonArrayBytes = Encoding.UTF8.GetBytes(JsonUtility.ToJson(l2));
|
||||
|
||||
// vector
|
||||
|
||||
MsgPack.Serialization.MessagePackSerializer.PrepareType<Vector3>();
|
||||
MsgPack.Serialization.MessagePackSerializer.PrepareType<Vector3[]>();
|
||||
|
||||
v3 = new Vector3 { x = 12345.12345f, y = 3994.35226f, z = 325125.52426f };
|
||||
v3Array = Enumerable.Range(1, 100).Select(_ => new Vector3 { x = 12345.12345f, y = 3994.35226f, z = 325125.52426f }).ToArray();
|
||||
v3Wrapper = new Vector3ArrayWrapper { List = v3Array };
|
||||
|
||||
msgPackCSharpv3Bytes = MessagePackSerializer.Serialize(v3, MsgPackUnsafeDefaultResolver.Options);
|
||||
msgPackCSharpv3ArrayBytes = MessagePackSerializer.Serialize(v3Array, MsgPackUnsafeDefaultResolver.Options);
|
||||
var serializer3 = this.msgPackContext.GetSerializer<Vector3>();
|
||||
msgpackv3Bytes = serializer3.PackSingleObject(v3);
|
||||
var serializer4 = this.msgPackContext.GetSerializer<Vector3[]>();
|
||||
msgpackv3ArrayBytes = serializer4.PackSingleObject(v3Array);
|
||||
|
||||
jsonv3Bytes = Encoding.UTF8.GetBytes(JsonUtility.ToJson(v3));
|
||||
jsonv3ArrayBytes = Encoding.UTF8.GetBytes(JsonUtility.ToJson(v3Wrapper));
|
||||
}
|
||||
|
||||
private void SerializationContext_ResolveSerializer(object sender, ResolveSerializerEventArgs e)
|
||||
{
|
||||
if (e.TargetType == typeof(Person)) { e.SetSerializer(new PersonSerializer(e.Context)); return; }
|
||||
if (e.TargetType == typeof(Sex)) { e.SetSerializer(new SexSerializer(e.Context)); return; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpSerializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(p, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpSerializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(l, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpDeserializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Person>(msgPackCSharpFormatterSingleBytes, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpDeserializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Person[]>(msgPackCSharpArrayBytes, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void LZ4MessagePackCSharpSerializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(p, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LZ4MessagePackCSharpSerializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(l, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LZ4MessagePackCSharpDeserializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Person>(msgPackCSharpLZ4FormatterSingleBytes, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LZ4MessagePackCSharpDeserializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Person[]>(msgPackCSharpLZ4ArrayBytes, MsgPackUnsafeDefaultResolver.LZ4Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackSerializeSingle()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Person>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.PackSingleObject(p);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackSerializeArray()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Person[]>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.PackSingleObject(l);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackDeserializeSingle()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Person>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.UnpackSingleObject(msgpackSingleBytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackDeserializeArray()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Person[]>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.UnpackSingleObject(msgpackArrayBytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilitySerializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = JsonUtility.ToJson(p2);
|
||||
Encoding.UTF8.GetBytes(str); // testing with binary...
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilitySerializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = JsonUtility.ToJson(l2);
|
||||
Encoding.UTF8.GetBytes(str); // testing with binary...
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilityDeserializeSingle()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = Encoding.UTF8.GetString(jsonSingleBytes);
|
||||
JsonUtility.FromJson<PersonLike>(str);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilityDeserializeArray()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = Encoding.UTF8.GetString(jsonArrayBytes);
|
||||
JsonUtility.FromJson<PersonLikeVector>(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// more...
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpSerializeVector3()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(v3, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpSerializeVector3Array()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Serialize(v3Array, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpDeserializeVector3()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Vector3>(msgPackCSharpv3Bytes, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessagePackCSharpDeserializeVector3Array()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
MessagePackSerializer.Deserialize<Vector3[]>(msgPackCSharpv3ArrayBytes, MsgPackUnsafeDefaultResolver.Options);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackSerializeVector3()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Vector3>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.PackSingleObject(v3);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackSerializeVector3Array()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Vector3[]>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.PackSingleObject(v3Array);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackDeserializeVector3()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Vector3>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.UnpackSingleObject(msgpackv3Bytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackDeserializeVector3Array()
|
||||
{
|
||||
var serializer = this.msgPackContext.GetSerializer<Vector3[]>();
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
serializer.UnpackSingleObject(msgpackv3ArrayBytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilitySerializeVector3()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = JsonUtility.ToJson(v3);
|
||||
Encoding.UTF8.GetBytes(str); // testing with binary...
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilitySerializeVector3Array()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = JsonUtility.ToJson(v3Wrapper);
|
||||
var bs = Encoding.UTF8.GetBytes(str); // testing with binary...
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilityDeserializeVector3()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = Encoding.UTF8.GetString(jsonv3Bytes);
|
||||
JsonUtility.FromJson<Vector3>(str);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonUtilityDeserializeVector3Array()
|
||||
{
|
||||
for (int i = 0; i < Iteration; i++)
|
||||
{
|
||||
var str = Encoding.UTF8.GetString(jsonv3ArrayBytes);
|
||||
JsonUtility.FromJson<Vector3[]>(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@ namespace MessagePack.Tests
|
|||
{
|
||||
public class ByteArrayComparerTest
|
||||
{
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
[Fact]
|
||||
public void Compare()
|
||||
{
|
||||
|
@ -33,5 +35,8 @@ namespace MessagePack.Tests
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace MessagePack.Tests
|
|||
public class DynamicObjectResolverInterfaceTest
|
||||
{
|
||||
[Fact]
|
||||
private void TestConstructorWithParentInterface()
|
||||
public void TestConstructorWithParentInterface()
|
||||
{
|
||||
var myClass = new ConstructorEnumerableTest(new[] { "0", "2", "3" });
|
||||
var serialized = MessagePackSerializer.Serialize(myClass);
|
|
@ -228,13 +228,21 @@ namespace MessagePack.Tests
|
|||
[Fact]
|
||||
public void DecimalLang()
|
||||
{
|
||||
var estonian = new CultureInfo("et-EE");
|
||||
CultureInfo.CurrentCulture = estonian;
|
||||
var current = CultureInfo.CurrentCulture;
|
||||
try
|
||||
{
|
||||
var estonian = new CultureInfo("et-EE");
|
||||
CultureInfo.CurrentCulture = estonian;
|
||||
|
||||
var b = MessagePackSerializer.Serialize(12345.6789M);
|
||||
var d = MessagePackSerializer.Deserialize<decimal>(b);
|
||||
var b = MessagePackSerializer.Serialize(12345.6789M);
|
||||
var d = MessagePackSerializer.Deserialize<decimal>(b);
|
||||
|
||||
d.Is(12345.6789M);
|
||||
d.Is(12345.6789M);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = current;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
|
@ -30,14 +30,14 @@ namespace MessagePack.Tests
|
|||
new object[] { Tuple.Create(1, 2, 3, 4, 5, 6, 7, 8) },
|
||||
};
|
||||
|
||||
[Theory(Skip = "AppVeyor Testing")]
|
||||
[Theory()]
|
||||
[MemberData(nameof(TupleTestData))]
|
||||
public void TupleTest<T>(T data)
|
||||
{
|
||||
this.Convert(data).IsStructuralEqual(data);
|
||||
}
|
||||
|
||||
public static object[] ValueTupleTestData = new object[]
|
||||
public static object[][] ValueTupleTestData = new object[][]
|
||||
{
|
||||
new object[] { ValueTuple.Create(1), null },
|
||||
new object[] { ValueTuple.Create(1, 2), null },
|
||||
|
@ -49,8 +49,8 @@ namespace MessagePack.Tests
|
|||
new object[] { ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, 8), null },
|
||||
};
|
||||
|
||||
[Theory(Skip = "AppVeyor Testing")]
|
||||
[MemberData(nameof(TupleTestData))]
|
||||
[Theory()]
|
||||
[MemberData(nameof(ValueTupleTestData))]
|
||||
public void TupleTest2<T>(T data, T? @null)
|
||||
where T : struct
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ namespace MessagePack.Tests
|
|||
new object[] { new KeyValuePair<int, int>(3, 4), new KeyValuePair<int, int>(5, 6) },
|
||||
};
|
||||
|
||||
[Theory(Skip = "AppVeyor Testing")]
|
||||
[Theory()]
|
||||
[MemberData(nameof(KeyValuePairData))]
|
||||
public void KeyValuePairTest<T>(T t, T? t2)
|
||||
where T : struct
|
||||
|
@ -79,12 +79,11 @@ namespace MessagePack.Tests
|
|||
new object[] { new ArraySegment<byte>(new byte[0], 0, 0), null, new byte[0] },
|
||||
};
|
||||
|
||||
[Theory(Skip = "AppVeyor Testing")]
|
||||
[Theory()]
|
||||
[MemberData(nameof(ByteArraySegementData))]
|
||||
public void ByteArraySegmentTest(ArraySegment<byte> t, ArraySegment<byte>? t2, byte[] reference)
|
||||
{
|
||||
MessagePackSerializer.Serialize(t).Is(MessagePackSerializer.Serialize(reference));
|
||||
this.Convert(t).Array.Is(reference);
|
||||
new MessagePackReader(MessagePackSerializer.Serialize(t2)).IsNil.IsTrue();
|
||||
}
|
||||
}
|
|
@ -76,8 +76,8 @@ namespace MessagePack.Tests
|
|||
|
||||
[Theory]
|
||||
[InlineData(byte.MinValue, 1)]
|
||||
[InlineData(111, 1)]
|
||||
[InlineData(136, 2)]
|
||||
[InlineData((byte)111, 1)]
|
||||
[InlineData((byte)136, 2)]
|
||||
[InlineData(byte.MaxValue, 2)]
|
||||
public void ByteTest(byte target, int length)
|
||||
{
|
||||
|
@ -132,15 +132,15 @@ namespace MessagePack.Tests
|
|||
|
||||
[Theory]
|
||||
[InlineData(sbyte.MinValue, 2)]
|
||||
[InlineData(-100, 2)]
|
||||
[InlineData(-33, 2)]
|
||||
[InlineData(-32, 1)]
|
||||
[InlineData(-31, 1)]
|
||||
[InlineData(-30, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
[InlineData(0, 1)]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(126, 1)]
|
||||
[InlineData((sbyte)-100, 2)]
|
||||
[InlineData((sbyte)-33, 2)]
|
||||
[InlineData((sbyte)-32, 1)]
|
||||
[InlineData((sbyte)-31, 1)]
|
||||
[InlineData((sbyte)-30, 1)]
|
||||
[InlineData((sbyte)-1, 1)]
|
||||
[InlineData((sbyte)0, 1)]
|
||||
[InlineData((sbyte)1, 1)]
|
||||
[InlineData((sbyte)126, 1)]
|
||||
[InlineData(sbyte.MaxValue, 1)]
|
||||
public void SByteTest(sbyte target, int length)
|
||||
{
|
||||
|
@ -224,19 +224,19 @@ namespace MessagePack.Tests
|
|||
|
||||
[Theory]
|
||||
[InlineData(short.MinValue, 3)]
|
||||
[InlineData(-30000, 3)]
|
||||
[InlineData((short)-30000, 3)]
|
||||
[InlineData((short)sbyte.MinValue, 2)]
|
||||
[InlineData(-100, 2)]
|
||||
[InlineData(-33, 2)]
|
||||
[InlineData(-32, 1)]
|
||||
[InlineData(-31, 1)]
|
||||
[InlineData(-30, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
[InlineData(0, 1)]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(126, 1)]
|
||||
[InlineData((short)-100, 2)]
|
||||
[InlineData((short)-33, 2)]
|
||||
[InlineData((short)-32, 1)]
|
||||
[InlineData((short)-31, 1)]
|
||||
[InlineData((short)-30, 1)]
|
||||
[InlineData((short)-1, 1)]
|
||||
[InlineData((short)0, 1)]
|
||||
[InlineData((short)1, 1)]
|
||||
[InlineData((short)126, 1)]
|
||||
[InlineData((short)sbyte.MaxValue, 1)]
|
||||
[InlineData(20000, 3)]
|
||||
[InlineData((short)20000, 3)]
|
||||
[InlineData(short.MaxValue, 3)]
|
||||
public void Int16Test(short target, int length)
|
||||
{
|
||||
|
@ -315,30 +315,30 @@ namespace MessagePack.Tests
|
|||
|
||||
[Theory]
|
||||
[InlineData(long.MinValue, 9)]
|
||||
[InlineData(-3372036854775807, 9)]
|
||||
[InlineData(int.MinValue, 5)]
|
||||
[InlineData(-50000, 5)]
|
||||
[InlineData(short.MinValue, 3)]
|
||||
[InlineData(-30000, 3)]
|
||||
[InlineData((short)sbyte.MinValue, 2)]
|
||||
[InlineData(-100, 2)]
|
||||
[InlineData(-33, 2)]
|
||||
[InlineData(-32, 1)]
|
||||
[InlineData(-31, 1)]
|
||||
[InlineData(-30, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
[InlineData(0, 1)]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(126, 1)]
|
||||
[InlineData(sbyte.MaxValue, 1)]
|
||||
[InlineData(byte.MaxValue, 2)]
|
||||
[InlineData(20000, 3)]
|
||||
[InlineData(short.MaxValue, 3)]
|
||||
[InlineData(50000, 3)]
|
||||
[InlineData(int.MaxValue, 5)]
|
||||
[InlineData(uint.MaxValue, 5)]
|
||||
[InlineData(3372036854775807, 9)]
|
||||
[InlineData(long.MaxValue, 9)]
|
||||
[InlineData((long)-3372036854775807, 9)]
|
||||
[InlineData((long)int.MinValue, 5)]
|
||||
[InlineData((long)-50000, 5)]
|
||||
[InlineData((long)short.MinValue, 3)]
|
||||
[InlineData((long)-30000, 3)]
|
||||
[InlineData((long)(short)sbyte.MinValue, 2)]
|
||||
[InlineData((long)-100, 2)]
|
||||
[InlineData((long)-33, 2)]
|
||||
[InlineData((long)-32, 1)]
|
||||
[InlineData((long)-31, 1)]
|
||||
[InlineData((long)-30, 1)]
|
||||
[InlineData((long)-1, 1)]
|
||||
[InlineData((long)0, 1)]
|
||||
[InlineData((long)1, 1)]
|
||||
[InlineData((long)126, 1)]
|
||||
[InlineData((long)sbyte.MaxValue, 1)]
|
||||
[InlineData((long)byte.MaxValue, 2)]
|
||||
[InlineData((long)20000, 3)]
|
||||
[InlineData((long)short.MaxValue, 3)]
|
||||
[InlineData((long)50000, 3)]
|
||||
[InlineData((long)int.MaxValue, 5)]
|
||||
[InlineData((long)uint.MaxValue, 5)]
|
||||
[InlineData((long)3372036854775807, 9)]
|
||||
[InlineData((long)long.MaxValue, 9)]
|
||||
public void Int64Test(long target, int length)
|
||||
{
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
@ -389,8 +389,10 @@ namespace MessagePack.Tests
|
|||
[InlineData(20000, 3)]
|
||||
[InlineData(ushort.MaxValue, 3)]
|
||||
[InlineData(80000, 5)]
|
||||
public void MapHeaderTest(uint target, int length)
|
||||
public void MapHeaderTest(object _target, int length)
|
||||
{
|
||||
var target = Convert.ToUInt32(_target);
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
||||
|
@ -431,8 +433,10 @@ namespace MessagePack.Tests
|
|||
[InlineData(20000, 3)]
|
||||
[InlineData(ushort.MaxValue, 3)]
|
||||
[InlineData(80000, 5)]
|
||||
public void ArrayHeaderTest(uint target, int length)
|
||||
public void ArrayHeaderTest(object _target, int length)
|
||||
{
|
||||
var target = Convert.ToUInt32(_target); // hack for work in Unity NUnit.
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
||||
|
@ -469,8 +473,10 @@ namespace MessagePack.Tests
|
|||
[InlineData(short.MaxValue, 3)]
|
||||
[InlineData(50000, 3)]
|
||||
[InlineData(ushort.MaxValue, 3)]
|
||||
public void UInt16Test(ushort target, int length)
|
||||
public void UInt16Test(object _target, int length)
|
||||
{
|
||||
var target = Convert.ToUInt16(_target);
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
||||
|
@ -501,8 +507,10 @@ namespace MessagePack.Tests
|
|||
[InlineData(int.MaxValue, 5)]
|
||||
[InlineData(3294967295, 5)]
|
||||
[InlineData(uint.MaxValue, 5)]
|
||||
public void UInt32Test(uint target, int length)
|
||||
public void UInt32Test(object _target, int length)
|
||||
{
|
||||
var target = Convert.ToUInt32(_target);
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
||||
|
@ -537,8 +545,10 @@ namespace MessagePack.Tests
|
|||
[InlineData(long.MaxValue, 9)]
|
||||
[InlineData(12446744073709551615, 9)]
|
||||
[InlineData(ulong.MaxValue, 9)]
|
||||
public void UInt64Test(ulong target, int length)
|
||||
public void UInt64Test(object _target, int length)
|
||||
{
|
||||
var target = Convert.ToUInt64(_target);
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
||||
|
@ -691,8 +701,10 @@ namespace MessagePack.Tests
|
|||
|
||||
[Theory]
|
||||
[MemberData(nameof(ExtTestData))]
|
||||
public void ExtTest(sbyte typeCode, byte[] target)
|
||||
public void ExtTest(object _typeCode, byte[] target)
|
||||
{
|
||||
var typeCode = Convert.ToSByte(_typeCode); // hack for work in Unity NUnit.
|
||||
|
||||
(MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();
|
||||
|
||||
var sequence = new Sequence<byte>();
|
|
@ -15,13 +15,24 @@ namespace MessagePack.Tests
|
|||
private const sbyte ByteNegativeValue = -3;
|
||||
private const byte BytePositiveValue = 3;
|
||||
private static readonly ReadOnlySequence<byte> StringEncodedAsFixStr = Encode((ref MessagePackWriter w) => w.Write("hi"));
|
||||
|
||||
private readonly ITestOutputHelper logger;
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
public MessagePackReaderTests(ITestOutputHelper logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
#else
|
||||
public MessagePackReaderTests()
|
||||
{
|
||||
this.logger = new NullTestOutputHelper();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void ReadSingle_ReadIntegersOfVariousLengthsAndMagnitudes()
|
||||
{
|
|
@ -39,6 +39,10 @@ namespace MessagePack.Tests
|
|||
new[] { data1.Prop3, data2.Prop3, data3.Prop3, data4.Prop3 }.Distinct().Is(data.Prop3);
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
// Unity's NUnit currently no supported Task test.
|
||||
|
||||
[Fact]
|
||||
public async Task NonGeneric_Async()
|
||||
{
|
||||
|
@ -53,6 +57,8 @@ namespace MessagePack.Tests
|
|||
Assert.Equal(data, data2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void StreamAPI()
|
||||
{
|
|
@ -152,3 +152,4 @@ namespace MessagePack.Tests
|
|||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,10 +36,12 @@ namespace MessagePack.Tests
|
|||
bin3Writer.WriteRaw(bin1);
|
||||
bin3Writer.Flush();
|
||||
|
||||
MessagePack.Internal.ByteArrayComparer.Equals(bin1, bin2).IsTrue();
|
||||
MessagePack.Internal.ByteArrayComparer.Equals(bin1, CodeGenHelpers.GetSpanFromSequence(bin3)).IsTrue();
|
||||
new ReadOnlySpan<byte>(bin1).SequenceEqual(bin2).IsTrue();
|
||||
new ReadOnlySpan<byte>(bin1).SequenceEqual(CodeGenHelpers.GetSpanFromSequence(bin3)).IsTrue();
|
||||
}
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
[Fact]
|
||||
public void WriteRaw()
|
||||
{
|
||||
|
@ -67,5 +69,7 @@ namespace MessagePack.Tests
|
|||
MessagePack.Internal.ByteArrayComparer.Equals(src, CodeGenHelpers.GetSpanFromSequence(dst.AsReadOnlySequence)).IsTrue();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,373 @@
|
|||
// ChainingAssertion for Unity
|
||||
// https://github.com/neuecc/ChainingAssertion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
// namespace Xunit
|
||||
//{
|
||||
public static partial class AssertExtensions
|
||||
{
|
||||
/// <summary>Assert.AreEqual.</summary>
|
||||
public static void Is<T>(this T actual, T expected, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.AreEqual(expected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsTrue(predicate(value))</summary>
|
||||
public static void Is<T>(this T value, Func<T, bool> predicate, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.IsTrue(predicate(value), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void Is<T>(this IEnumerable<T> actual, params T[] expected)
|
||||
{
|
||||
IsCollection(actual, expected.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, params T[] expected)
|
||||
{
|
||||
IsCollection(actual, expected.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, string message = "")
|
||||
{
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray(), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, IEqualityComparer<T> comparer, string message = "")
|
||||
{
|
||||
IsCollection(actual, expected, comparer.Equals, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreEqual</summary>
|
||||
public static void IsCollection<T>(this IEnumerable<T> actual, IEnumerable<T> expected, Func<T, T, bool> equalityComparison, string message = "")
|
||||
{
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray(), new ComparisonComparer<T>(equalityComparison), message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreNotEqual</summary>
|
||||
public static void IsNot<T>(this T actual, T notExpected, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.AreNotEqual(notExpected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, params T[] notExpected)
|
||||
{
|
||||
IsNotCollection(actual, notExpected.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, string message = "")
|
||||
{
|
||||
CollectionAssert.AreNotEqual(notExpected.ToArray(), actual.ToArray(), message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, IEqualityComparer<T> comparer, string message = "")
|
||||
{
|
||||
IsNotCollection(actual, notExpected, comparer.Equals, message);
|
||||
}
|
||||
|
||||
/// <summary>CollectionAssert.AreNotEqual</summary>
|
||||
public static void IsNotCollection<T>(this IEnumerable<T> actual, IEnumerable<T> notExpected, Func<T, T, bool> equalityComparison, string message = "")
|
||||
{
|
||||
CollectionAssert.AreNotEqual(notExpected.ToArray(), actual.ToArray(), new ComparisonComparer<T>(equalityComparison), message);
|
||||
}
|
||||
|
||||
/// <summary>Asset Collefction is empty?</summary>
|
||||
public static void IsEmpty<T>(this IEnumerable<T> source)
|
||||
{
|
||||
source.Any().IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNull</summary>
|
||||
public static void IsNull<T>(this T value, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.IsNull(value, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNotNull</summary>
|
||||
public static void IsNotNull<T>(this T value, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.IsNotNull(value, message);
|
||||
}
|
||||
|
||||
/// <summary>Is(true)</summary>
|
||||
public static void IsTrue(this bool value, string message = "")
|
||||
{
|
||||
value.Is(true, message);
|
||||
}
|
||||
|
||||
/// <summary>Is(false)</summary>
|
||||
public static void IsFalse(this bool value, string message = "")
|
||||
{
|
||||
value.Is(false, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreSame</summary>
|
||||
public static void IsSameReferenceAs<T>(this T actual, T expected, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.AreSame(expected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.AreNotSame</summary>
|
||||
public static void IsNotSameReferenceAs<T>(this T actual, T notExpected, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.AreNotSame(notExpected, actual, message);
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsInstanceOf</summary>
|
||||
public static TExpected IsInstanceOf<TExpected>(this object value, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.IsInstanceOf<TExpected>(value, message);
|
||||
return (TExpected)value;
|
||||
}
|
||||
|
||||
/// <summary>Assert.IsNotInstanceOf</summary>
|
||||
public static void IsNotInstanceOf<TWrong>(this object value, string message = "")
|
||||
{
|
||||
NUnit.Framework.Assert.IsNotInstanceOf<TWrong>(value, message);
|
||||
}
|
||||
|
||||
/// <summary>EqualityComparison to IComparer Converter for CollectionAssert</summary>
|
||||
private class ComparisonComparer<T> : IComparer
|
||||
{
|
||||
readonly Func<T, T, bool> comparison;
|
||||
|
||||
public ComparisonComparer(Func<T, T, bool> comparison)
|
||||
{
|
||||
this.comparison = comparison;
|
||||
}
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
return (this.comparison != null)
|
||||
? this.comparison((T)x, (T)y) ? 0 : -1
|
||||
: object.Equals(x, y) ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
#region StructuralEqual
|
||||
|
||||
/// <summary>Assert by deep recursive value equality compare.</summary>
|
||||
public static void IsStructuralEqual(this object actual, object expected, string message = "")
|
||||
{
|
||||
message = string.IsNullOrEmpty(message) ? string.Empty : ", " + message;
|
||||
if (object.ReferenceEquals(actual, expected))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (actual == null)
|
||||
{
|
||||
throw new NUnit.Framework.AssertionException("actual is null" + message);
|
||||
}
|
||||
|
||||
if (expected == null)
|
||||
{
|
||||
throw new NUnit.Framework.AssertionException("actual is not null" + message);
|
||||
}
|
||||
|
||||
if (actual.GetType() != expected.GetType())
|
||||
{
|
||||
var msg = string.Format(
|
||||
"expected type is {0} but actual type is {1}{2}",
|
||||
expected.GetType().Name,
|
||||
actual.GetType().Name,
|
||||
message);
|
||||
throw new NUnit.Framework.AssertionException(msg);
|
||||
}
|
||||
|
||||
EqualInfo r = StructuralEqual(actual, expected, new[] { actual.GetType().Name }); // root type
|
||||
if (!r.IsEquals)
|
||||
{
|
||||
var msg = string.Format(
|
||||
"is not structural equal, failed at {0}, actual = {1} expected = {2}{3}",
|
||||
string.Join(".", r.Names),
|
||||
r.Left,
|
||||
r.Right,
|
||||
message);
|
||||
throw new NUnit.Framework.AssertionException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Assert by deep recursive value equality compare.</summary>
|
||||
public static void IsNotStructuralEqual(this object actual, object expected, string message = "")
|
||||
{
|
||||
message = string.IsNullOrEmpty(message) ? string.Empty : ", " + message;
|
||||
if (object.ReferenceEquals(actual, expected))
|
||||
{
|
||||
throw new NUnit.Framework.AssertionException("actual is same reference" + message);
|
||||
}
|
||||
|
||||
if (actual == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (expected == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (actual.GetType() != expected.GetType())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EqualInfo r = StructuralEqual(actual, expected, new[] { actual.GetType().Name }); // root type
|
||||
if (r.IsEquals)
|
||||
{
|
||||
throw new NUnit.Framework.AssertionException("is structural equal" + message);
|
||||
}
|
||||
}
|
||||
|
||||
private static EqualInfo SequenceEqual(IEnumerable leftEnumerable, IEnumerable rightEnumarable, IEnumerable<string> names)
|
||||
{
|
||||
IEnumerator le = leftEnumerable.GetEnumerator();
|
||||
using (le as IDisposable)
|
||||
{
|
||||
IEnumerator re = rightEnumarable.GetEnumerator();
|
||||
|
||||
using (re as IDisposable)
|
||||
{
|
||||
var index = 0;
|
||||
while (true)
|
||||
{
|
||||
object lValue = null;
|
||||
object rValue = null;
|
||||
var lMove = le.MoveNext();
|
||||
var rMove = re.MoveNext();
|
||||
if (lMove)
|
||||
{
|
||||
lValue = le.Current;
|
||||
}
|
||||
|
||||
if (rMove)
|
||||
{
|
||||
rValue = re.Current;
|
||||
}
|
||||
|
||||
if (lMove && rMove)
|
||||
{
|
||||
EqualInfo result = StructuralEqual(lValue, rValue, names.Concat(new[] { "[" + index + "]" }));
|
||||
if (!result.IsEquals)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if ((lMove == true && rMove == false) || (lMove == false && rMove == true))
|
||||
{
|
||||
return new EqualInfo { IsEquals = false, Left = lValue, Right = rValue, Names = names.Concat(new[] { "[" + index + "]" }) };
|
||||
}
|
||||
|
||||
if (lMove == false && rMove == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new EqualInfo { IsEquals = true, Left = leftEnumerable, Right = rightEnumarable, Names = names };
|
||||
}
|
||||
|
||||
private static EqualInfo StructuralEqual(object left, object right, IEnumerable<string> names)
|
||||
{
|
||||
// type and basic checks
|
||||
if (object.ReferenceEquals(left, right))
|
||||
{
|
||||
return new EqualInfo { IsEquals = true, Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
if (left == null || right == null)
|
||||
{
|
||||
return new EqualInfo { IsEquals = false, Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
Type lType = left.GetType();
|
||||
Type rType = right.GetType();
|
||||
if (lType != rType)
|
||||
{
|
||||
return new EqualInfo { IsEquals = false, Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
Type type = left.GetType();
|
||||
|
||||
// not object(int, string, etc...)
|
||||
if (Type.GetTypeCode(type) != TypeCode.Object)
|
||||
{
|
||||
return new EqualInfo { IsEquals = left.Equals(right), Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
// is sequence
|
||||
if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(type))
|
||||
{
|
||||
return SequenceEqual((IEnumerable)left, (IEnumerable)right, names);
|
||||
}
|
||||
|
||||
// IEquatable<T>
|
||||
Type equatable = typeof(IEquatable<>).MakeGenericType(type);
|
||||
if (equatable.GetTypeInfo().IsAssignableFrom(type))
|
||||
{
|
||||
var result = (bool)equatable.GetTypeInfo().GetMethod("Equals").Invoke(left, new[] { right });
|
||||
return new EqualInfo { IsEquals = result, Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
// is object
|
||||
FieldInfo[] fields = left.GetType().GetTypeInfo().GetFields(BindingFlags.Instance | BindingFlags.Public);
|
||||
IEnumerable<PropertyInfo> properties = left.GetType().GetTypeInfo().GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Where(x => x.GetGetMethod(false) != null && x.GetIndexParameters().Length == 0);
|
||||
IEnumerable<MemberInfo> members = fields.Cast<MemberInfo>().Concat(properties);
|
||||
|
||||
foreach (var mi in fields.Cast<MemberInfo>().Concat(properties))
|
||||
{
|
||||
IEnumerable<string> concatNames = names.Concat(new[] { (string)mi.Name });
|
||||
|
||||
object lv = null;
|
||||
object rv = null;
|
||||
if (mi is PropertyInfo pi)
|
||||
{
|
||||
lv = pi.GetValue(left);
|
||||
rv = pi.GetValue(right);
|
||||
}
|
||||
else if (mi is FieldInfo fi)
|
||||
{
|
||||
lv = fi.GetValue(left);
|
||||
rv = fi.GetValue(right);
|
||||
}
|
||||
|
||||
EqualInfo result = StructuralEqual(lv, rv, concatNames);
|
||||
if (!result.IsEquals)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return new EqualInfo { IsEquals = true, Left = left, Right = right, Names = names };
|
||||
}
|
||||
|
||||
private class EqualInfo
|
||||
{
|
||||
public object Left;
|
||||
public object Right;
|
||||
public bool IsEquals;
|
||||
public IEnumerable<string> Names;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
//}
|
|
@ -0,0 +1,129 @@
|
|||
// Xunit to NUnit bridge.
|
||||
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Xunit
|
||||
{
|
||||
public class FactAttribute : NUnit.Framework.TestAttribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class TheoryAttribute : FactAttribute
|
||||
{
|
||||
public string Skip { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class InlineDataAttribute : NUnit.Framework.TestCaseAttribute
|
||||
{
|
||||
public InlineDataAttribute(params Object[] data)
|
||||
: base(data)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class MemberDataAttribute : NUnit.Framework.TestCaseSourceAttribute
|
||||
{
|
||||
public MemberDataAttribute(string memberName)
|
||||
: base(memberName)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class Assert
|
||||
{
|
||||
public static void Throws<T>(Action action) where T : Exception
|
||||
{
|
||||
NUnit.Framework.Assert.Throws<T>(new TestDelegate(action));
|
||||
}
|
||||
|
||||
public static void Throws<T>(Func<object> action) where T : Exception
|
||||
{
|
||||
NUnit.Framework.Assert.Throws<T>(() => action());
|
||||
}
|
||||
|
||||
public static void True(bool value)
|
||||
{
|
||||
NUnit.Framework.Assert.IsTrue(value);
|
||||
}
|
||||
|
||||
public static void False(bool value)
|
||||
{
|
||||
NUnit.Framework.Assert.IsFalse(value);
|
||||
}
|
||||
|
||||
public static void Null(object expected)
|
||||
{
|
||||
NUnit.Framework.Assert.IsNull(expected);
|
||||
}
|
||||
|
||||
public static T IsType<T>(object o)
|
||||
{
|
||||
NUnit.Framework.Assert.AreEqual(typeof(T), o.GetType());
|
||||
return (T)o;
|
||||
}
|
||||
|
||||
public static void Equal<T>(T expected, T actual)
|
||||
{
|
||||
NUnit.Framework.Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
public static void NotEqual<T>(T expected, T actual)
|
||||
{
|
||||
NUnit.Framework.Assert.AreNotEqual(expected, actual);
|
||||
}
|
||||
|
||||
public static void NotEmpty<T>(ICollection<T> source)
|
||||
{
|
||||
NUnit.Framework.Assert.IsTrue(source.Count != 0);
|
||||
}
|
||||
|
||||
public static void NotNull<T>(T value) where T : class
|
||||
{
|
||||
NUnit.Framework.Assert.IsNotNull(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AssertFailedException : NUnit.Framework.AssertionException
|
||||
{
|
||||
public AssertFailedException()
|
||||
: base("")
|
||||
{
|
||||
}
|
||||
|
||||
public AssertFailedException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public AssertFailedException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Xunit.Abstractions
|
||||
{
|
||||
public interface ITestOutputHelper
|
||||
{
|
||||
void WriteLine(String message);
|
||||
void WriteLine(String format, params Object[] args);
|
||||
}
|
||||
|
||||
public class NullTestOutputHelper : ITestOutputHelper
|
||||
{
|
||||
public void WriteLine(string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
using UnityEngine;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using System.Collections;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using MessagePack.Resolvers;
|
||||
using MessagePack.Internal;
|
||||
using MessagePack.Formatters;
|
||||
using SharedData;
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
[MessagePackObject]
|
||||
[System.Serializable]
|
||||
public class TestObject
|
||||
{
|
||||
[MessagePackObject]
|
||||
[System.Serializable]
|
||||
public class PrimitiveObject
|
||||
{
|
||||
[Key(0)]
|
||||
public int v_int;
|
||||
|
||||
[Key(1)]
|
||||
public string v_str;
|
||||
|
||||
[Key(2)]
|
||||
public float v_float;
|
||||
|
||||
[Key(3)]
|
||||
public bool v_bool;
|
||||
public PrimitiveObject(int vi, string vs, float vf, bool vb)
|
||||
{
|
||||
v_int = vi; v_str = vs; v_float = vf; v_bool = vb;
|
||||
}
|
||||
}
|
||||
|
||||
[Key(0)]
|
||||
public PrimitiveObject[] objectArray;
|
||||
|
||||
[Key(1)]
|
||||
public List<PrimitiveObject> objectList;
|
||||
|
||||
[Key(2)]
|
||||
public Dictionary<string, PrimitiveObject> objectMap;
|
||||
|
||||
public void CreateArray(int num)
|
||||
{
|
||||
objectArray = new PrimitiveObject[num];
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
objectArray[i] = new PrimitiveObject(i, i.ToString(), (float)i, i % 2 == 0 ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateList(int num)
|
||||
{
|
||||
objectList = new List<PrimitiveObject>(num);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
objectList.Add(new PrimitiveObject(i, i.ToString(), (float)i, i % 2 == 0 ? true : false));
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateMap(int num)
|
||||
{
|
||||
objectMap = new Dictionary<string, PrimitiveObject>(num);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
objectMap.Add(i.ToString(), new PrimitiveObject(i, i.ToString(), (float)i, i % 2 == 0 ? true : false));
|
||||
}
|
||||
}
|
||||
// I only tested with array
|
||||
public static TestObject TestBuild()
|
||||
{
|
||||
TestObject to = new TestObject();
|
||||
//to.CreateArray(1000000);
|
||||
to.CreateArray(1);
|
||||
|
||||
return to;
|
||||
}
|
||||
}
|
||||
|
||||
public class NonSerializableObject
|
||||
{
|
||||
public int v_int;
|
||||
|
||||
public string v_str;
|
||||
|
||||
public float v_float;
|
||||
|
||||
public bool v_bool;
|
||||
public NonSerializableObject(int vi, string vs, float vf, bool vb)
|
||||
{
|
||||
v_int = vi; v_str = vs; v_float = vf; v_bool = vb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class Wrap
|
||||
{
|
||||
public List<MyKeyValuePair> Value;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MyKeyValuePair
|
||||
{
|
||||
public string Key;
|
||||
public int Value;
|
||||
}
|
||||
|
||||
public class SimpleTest
|
||||
{
|
||||
public void TestJsonSerialize()
|
||||
{
|
||||
var json = JsonUtility.ToJson(new List<MyKeyValuePair> { new MyKeyValuePair { Key = "foo", Value = 10 } });
|
||||
UnityEngine.Debug.Log(json); // 空
|
||||
|
||||
// ルートはオブジェクトにする入れる。
|
||||
var json2 = JsonUtility.ToJson(new Wrap { Value = new List<MyKeyValuePair> { new MyKeyValuePair { Key = "foo", Value = 10 } } });
|
||||
UnityEngine.Debug.Log(json2); // OK.
|
||||
|
||||
|
||||
//try
|
||||
//{
|
||||
|
||||
// var so = new NonSerializableObject(1, "hoge", 1.342f, true);
|
||||
|
||||
//var bin = MessagePackSerializer.Serialize(so);
|
||||
|
||||
//var s = MessagePackSerializer.ToJson(bin);
|
||||
|
||||
//UnityEngine.Debug.Log(s);
|
||||
|
||||
//TestObject to = TestObject.TestBuild();
|
||||
|
||||
//Stopwatch sw = new Stopwatch();
|
||||
//sw.Start();
|
||||
//string junity = JsonUtility.ToJson(to);
|
||||
//sw.Stop();
|
||||
//UnityEngine.Debug.LogFormat("*[Object To JsonString] - Unity : {0}ms.", sw.ElapsedMilliseconds);
|
||||
|
||||
//Stopwatch sw1 = new Stopwatch();
|
||||
//sw1.Start();
|
||||
//string jmsgPack = MessagePack.MessagePackSerializer.ToJson<TestObject>(to);
|
||||
//sw1.Stop();
|
||||
//UnityEngine.Debug.LogFormat("*[Object To JsonString] - MsgPack : {0}ms.", sw1.ElapsedMilliseconds);
|
||||
|
||||
//Stopwatch sw3 = new Stopwatch();
|
||||
//sw3.Start();
|
||||
//TestObject toUnity = JsonUtility.FromJson<TestObject>(junity);
|
||||
//sw3.Stop();
|
||||
//UnityEngine.Debug.LogFormat("*[JsonString To Object] - Unity : {0}ms.", sw3.ElapsedMilliseconds);
|
||||
|
||||
//Stopwatch sw4 = new Stopwatch();
|
||||
//sw4.Start();
|
||||
//TestObject toMsgPack = MessagePack.MessagePackSerializer.Deserialize<TestObject>(MessagePack.MessagePackSerializer.FromJson(jmsgPack));
|
||||
//sw4.Stop();
|
||||
//UnityEngine.Debug.LogFormat("*[JsonString To Object] - MsgPack : {0}ms.", sw4.ElapsedMilliseconds);
|
||||
|
||||
|
||||
|
||||
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// UnityEngine.Debug.LogException(ex);
|
||||
// throw;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class DynamicTestCheck
|
||||
{
|
||||
[Key(0)]
|
||||
public int A { get; set; }
|
||||
[Key(1)]
|
||||
public string B { get; set; }
|
||||
}
|
||||
}
|
|
@ -9,9 +9,10 @@
|
|||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
using NUnit.Framework;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using SharedData;
|
||||
using System;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class UnionTest
|
||||
{
|
||||
[Test]
|
||||
public void Union()
|
||||
{
|
||||
{
|
||||
var data = new MySubUnion1 { One = 23 };
|
||||
var data2 = new MySubUnion1 { One = 23 };
|
||||
|
||||
var unionData1 = MessagePackSerializer.Serialize<IUnionChecker>(data, MsgPackUnsafeDefaultResolver.Options);
|
||||
var unionData2 = MessagePackSerializer.Serialize<IUnionChecker2>(data2, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
var reData1 = MessagePackSerializer.Deserialize<IUnionChecker>(unionData1, MsgPackUnsafeDefaultResolver.Options);
|
||||
var reData2 = MessagePackSerializer.Deserialize<IUnionChecker>(unionData1, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
reData1.IsInstanceOf<IUnionChecker>();
|
||||
reData2.IsInstanceOf<IUnionChecker2>();
|
||||
|
||||
var null1 = MessagePackSerializer.Serialize<IUnionChecker>(null, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
var null2 = MessagePackSerializer.Serialize<IUnionChecker2>(null, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
MessagePackSerializer.Deserialize<IUnionChecker>(null1, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
MessagePackSerializer.Deserialize<IUnionChecker2>(null1, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
|
||||
var hoge = MessagePackSerializer.Serialize<IIVersioningUnion>(new VersioningUnion { FV = 0 }, MsgPackUnsafeDefaultResolver.Options);
|
||||
MessagePackSerializer.Deserialize<IUnionChecker>(hoge, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
}
|
||||
|
||||
{
|
||||
var data = new MySubUnion2 { Two = 23 };
|
||||
var data2 = new MySubUnion2 { Two = 23 };
|
||||
|
||||
var unionData1 = MessagePackSerializer.Serialize<IUnionChecker>(data, MsgPackUnsafeDefaultResolver.Options);
|
||||
var unionData2 = MessagePackSerializer.Serialize<IUnionChecker2>(data2, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
var reData1 = MessagePackSerializer.Deserialize<IUnionChecker>(unionData1, MsgPackUnsafeDefaultResolver.Options);
|
||||
var reData2 = MessagePackSerializer.Deserialize<IUnionChecker>(unionData1, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
reData1.IsInstanceOf<IUnionChecker>();
|
||||
reData2.IsInstanceOf<IUnionChecker2>();
|
||||
|
||||
var null1 = MessagePackSerializer.Serialize<IUnionChecker>(null, MsgPackUnsafeDefaultResolver.Options);
|
||||
var null2 = MessagePackSerializer.Serialize<IUnionChecker2>(null, MsgPackUnsafeDefaultResolver.Options);
|
||||
|
||||
MessagePackSerializer.Deserialize<IUnionChecker>(null1, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
MessagePackSerializer.Deserialize<IUnionChecker2>(null1, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
|
||||
var hoge = MessagePackSerializer.Serialize<IIVersioningUnion>(new VersioningUnion { FV = 0 }, MsgPackUnsafeDefaultResolver.Options);
|
||||
MessagePackSerializer.Deserialize<IUnionChecker>(hoge, MsgPackUnsafeDefaultResolver.Options).IsNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
#if ENABLE_UNSAFE_MSGPACK
|
||||
|
||||
using MessagePack.Formatters;
|
||||
using MessagePack.Resolvers;
|
||||
using MessagePack.Unity.Extension;
|
||||
using RuntimeUnitTestToolkit;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MessagePack.UnityClient.Tests
|
||||
{
|
||||
public class WithUnityBlitResolver : IFormatterResolver
|
||||
{
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return (UnityBlitWithPrimitiveArrayResolver.Instance.GetFormatter<T>()
|
||||
?? StandardResolver.Instance.GetFormatter<T>());
|
||||
}
|
||||
}
|
||||
|
||||
public class UnityBlitTest
|
||||
{
|
||||
T Convert<T>(T value)
|
||||
{
|
||||
var resolver = new WithUnityBlitResolver();
|
||||
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, resolver), resolver);
|
||||
}
|
||||
|
||||
|
||||
public void Blit()
|
||||
{
|
||||
var o = Enumerable.Range(1, 123).Select(x => new Vector3(x, x, x)).ToArray();
|
||||
var o2 = Convert(o);
|
||||
for (int i = 0; i < o.Length; i++)
|
||||
{
|
||||
o[i].x.Is(o2[i].x);
|
||||
o[i].y.Is(o2[i].y);
|
||||
o[i].z.Is(o2[i].z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -545,7 +545,7 @@ PlayerSettings:
|
|||
scriptingDefineSymbols: {}
|
||||
platformArchitecture: {}
|
||||
scriptingBackend:
|
||||
Standalone: 1
|
||||
Standalone: 0
|
||||
il2cppCompilerConfiguration: {}
|
||||
managedStrippingLevel: {}
|
||||
incrementalIl2cppBuild: {}
|
||||
|
@ -555,7 +555,7 @@ PlayerSettings:
|
|||
gcIncremental: 0
|
||||
gcWBarrierValidation: 0
|
||||
apiCompatibilityLevelPerPlatform:
|
||||
Standalone: 6
|
||||
Standalone: 3
|
||||
m_RenderingPath: 1
|
||||
m_MobileRenderingPath: 1
|
||||
metroPackageName: Template_3D
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MessagePack.Tests\MessagePackBinaryTest.cs" />
|
||||
<Compile Include="..\MessagePack.Tests\MessagePackReaderTests.cs" />
|
||||
<Compile Include="..\MessagePack.Tests\MessagePackReaderTests.ReadInt.cs" />
|
||||
<Compile Include="..\MessagePack.Tests\MessagePackReaderTests.ReadString.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\Tests\ShareTests\MessagePackBinaryTest.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\Tests\ShareTests\MessagePackReaderTests.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\Tests\ShareTests\MessagePackReaderTests.ReadInt.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\Tests\ShareTests\MessagePackReaderTests.ReadString.cs" />
|
||||
<Compile Include="..\MessagePack.Tests\Utils\ChainingAssertion.Xunit.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
<CodeAnalysisRuleSet>MessagePack.Tests.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\ByteArrayComparer.cs" Link="ByteArrayComparer.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\FarmHash.cs" Link="FarmHash.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\ILGeneratorExtensions.cs" Link="ILGeneratorExtensions.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\StringEncoding.cs" Link="StringEncoding.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\ByteArrayComparer.cs" Link="Link\ByteArrayComparer.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\FarmHash.cs" Link="Link\FarmHash.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\Internal\ILGeneratorExtensions.cs" Link="Link\ILGeneratorExtensions.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\MessagePack\StringEncoding.cs" Link="Link\StringEncoding.cs" />
|
||||
<Compile Include="..\..\src\MessagePack.UnityClient\Assets\Scripts\Tests\ShareTests\**\*.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\sandbox\SharedData\SharedData.csproj" />
|
||||
|
@ -50,4 +51,7 @@
|
|||
<DependentUpon>MessagePackReaderTests.ReadInt.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Link\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,309 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MessagePack.Resolvers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable SA1509 // Opening braces should not be preceded by blank line
|
||||
|
||||
namespace MessagePack.Tests
|
||||
{
|
||||
public class TypelessContractlessStandardResolverTest
|
||||
{
|
||||
public class Address
|
||||
{
|
||||
public string Street { get; set; }
|
||||
}
|
||||
|
||||
public class Person
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public object[] /*Address*/ Addresses { get; set; }
|
||||
}
|
||||
|
||||
public class ForTypelessObj
|
||||
{
|
||||
public object Obj { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnonymousTypeTest()
|
||||
{
|
||||
var p = new Person
|
||||
{
|
||||
Name = "John",
|
||||
Addresses = new[]
|
||||
{
|
||||
new { Street = "St." },
|
||||
new { Street = "Ave." },
|
||||
},
|
||||
};
|
||||
|
||||
var result = MessagePackSerializer.Serialize(p, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""Name"":""John"",""Addresses"":[{""Street"":""St.""},{""Street"":""Ave.""}]}");
|
||||
|
||||
Person p2 = MessagePackSerializer.Deserialize<Person>(result, TypelessContractlessStandardResolver.Options);
|
||||
p2.Name.Is("John");
|
||||
var addresses = p2.Addresses as IList;
|
||||
var d1 = addresses[0] as IDictionary;
|
||||
var d2 = addresses[1] as IDictionary;
|
||||
(d1["Street"] as string).Is("St.");
|
||||
(d2["Street"] as string).Is("Ave.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StrongTypeTest()
|
||||
{
|
||||
var p = new Person
|
||||
{
|
||||
Name = "John",
|
||||
Addresses = new object[]
|
||||
{
|
||||
new Address { Street = "St." },
|
||||
new Address { Street = "Ave." },
|
||||
},
|
||||
};
|
||||
|
||||
var result = MessagePackSerializer.Serialize(p, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
Person p2 = MessagePackSerializer.Deserialize<Person>(result, TypelessContractlessStandardResolver.Options);
|
||||
p.IsStructuralEqual(p2);
|
||||
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""Name"":""John"",""Addresses"":[{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""St.""},{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""Ave.""}]}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ObjectRuntimeTypeTest()
|
||||
{
|
||||
var p = new Person
|
||||
{
|
||||
Name = "John",
|
||||
Addresses = new object[]
|
||||
{
|
||||
new object(),
|
||||
new Address { Street = "Ave." },
|
||||
},
|
||||
};
|
||||
|
||||
var result = MessagePackSerializer.Serialize(p, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
Person p2 = MessagePackSerializer.Deserialize<Person>(result, TypelessContractlessStandardResolver.Options);
|
||||
p.IsStructuralEqual(p2);
|
||||
|
||||
#if NETFRAMEWORK
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""Name"":""John"",""Addresses"":[{""$type"":""""System.Object, mscorlib""},{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""Ave.""}]}");
|
||||
#else
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""Name"":""John"",""Addresses"":[{""$type"":""""System.Object, System.Private.CoreLib""},{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""Ave.""}]}");
|
||||
#endif
|
||||
}
|
||||
|
||||
public class A
|
||||
{
|
||||
public int Id;
|
||||
}
|
||||
|
||||
public class B
|
||||
{
|
||||
public A Nested;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypelessContractlessTest()
|
||||
{
|
||||
object obj = new B() { Nested = new A() { Id = 1 } };
|
||||
var result = MessagePackSerializer.Serialize(obj, TypelessContractlessStandardResolver.Options);
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+B, MessagePack.Tests"",""Nested"":{""Id"":1}}");
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class AC
|
||||
{
|
||||
[Key(0)] public int Id;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class BC
|
||||
{
|
||||
[Key(0)] public AC Nested; [Key(1)] public string Name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypelessAttributedTest()
|
||||
{
|
||||
object obj = new BC() { Nested = new AC() { Id = 1 }, Name = "Zed" };
|
||||
var result = MessagePackSerializer.Serialize(obj, TypelessContractlessStandardResolver.Options);
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"[""MessagePack.Tests.TypelessContractlessStandardResolverTest+BC, MessagePack.Tests"",[1],""Zed""]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PreservingTimezoneInTypelessCollectionsTest()
|
||||
{
|
||||
var arr = new Dictionary<object, object>()
|
||||
{
|
||||
{ (byte)1, "a" },
|
||||
{ (byte)2, new object[] { "level2", new object[] { "level3", new Person() { Name = "Peter", Addresses = new object[] { new Address() { Street = "St." }, new DateTime(2017, 6, 26, 14, 58, 0) } } } } },
|
||||
};
|
||||
var result = MessagePackSerializer.Serialize(arr, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
Dictionary<object, object> deser = MessagePackSerializer.Deserialize<Dictionary<object, object>>(result, TypelessContractlessStandardResolver.Options);
|
||||
deser.IsStructuralEqual(arr);
|
||||
|
||||
#if NETFRAMEWORK
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""1"":""a"",""2"":[""System.Object[], mscorlib"",""level2"",[""System.Object[], mscorlib"",""level3"",{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Person, MessagePack.Tests"",""Name"":""Peter"",""Addresses"":[{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""St.""},{""$type"":""System.DateTime, mscorlib"",636340858800000000}]}]]}");
|
||||
#else
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"{""1"":""a"",""2"":[""System.Object[], System.Private.CoreLib"",""level2"",[""System.Object[], System.Private.CoreLib"",""level3"",{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Person, MessagePack.Tests"",""Name"":""Peter"",""Addresses"":[{""$type"":""MessagePack.Tests.TypelessContractlessStandardResolverTest+Address, MessagePack.Tests"",""Street"":""St.""},{""$type"":""System.DateTime, System.Private.CoreLib"",636340858800000000}]}]]}");
|
||||
#endif
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PreservingCollectionTypeTest()
|
||||
{
|
||||
var arr = new object[] { (byte)1, new object[] { (byte)2, new LinkedList<object>(new object[] { "a", (byte)42 }) } };
|
||||
var result = MessagePackSerializer.Serialize(arr, TypelessContractlessStandardResolver.Options);
|
||||
var deser = MessagePackSerializer.Deserialize<object[]>(result, TypelessContractlessStandardResolver.Options);
|
||||
deser.IsStructuralEqual(arr);
|
||||
|
||||
#if NETFRAMEWORK
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"[1,[""System.Object[], mscorlib"",2,[""System.Collections.Generic.LinkedList`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"",""a"",42]]]");
|
||||
#else
|
||||
MessagePackSerializer.ConvertToJson(result, TypelessContractlessStandardResolver.Options).Is(@"[1,[""System.Object[], System.Private.CoreLib"",2,[""System.Collections.Generic.LinkedList`1[[System.Object, System.Private.CoreLib]], System.Collections"",""a"",42]]]");
|
||||
#endif
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData((sbyte)0)]
|
||||
[InlineData((short)0)]
|
||||
[InlineData((int)0)]
|
||||
[InlineData((long)0)]
|
||||
[InlineData((byte)0)]
|
||||
[InlineData((ushort)0)]
|
||||
[InlineData((uint)0)]
|
||||
[InlineData((ulong)0)]
|
||||
[InlineData((char)'a')]
|
||||
public void TypelessPrimitive<T>(T p)
|
||||
{
|
||||
var v = new ForTypelessObj() { Obj = p };
|
||||
|
||||
var bin = MessagePackSerializer.Typeless.Serialize(v);
|
||||
var o = (ForTypelessObj)MessagePackSerializer.Typeless.Deserialize(bin);
|
||||
|
||||
o.Obj.GetType().Is(typeof(T));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypelessPrimitive2()
|
||||
{
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
var v = new ForTypelessObj() { Obj = now };
|
||||
|
||||
var bin = MessagePackSerializer.Typeless.Serialize(v);
|
||||
var o = (ForTypelessObj)MessagePackSerializer.Typeless.Deserialize(bin);
|
||||
|
||||
o.Obj.GetType().Is(typeof(DateTime));
|
||||
((DateTime)o.Obj).Is(now);
|
||||
}
|
||||
|
||||
{
|
||||
DateTimeOffset now = DateTimeOffset.Now;
|
||||
var v = new ForTypelessObj() { Obj = now };
|
||||
|
||||
var bin = MessagePackSerializer.Typeless.Serialize(v);
|
||||
var o = (ForTypelessObj)MessagePackSerializer.Typeless.Deserialize(bin);
|
||||
|
||||
o.Obj.GetType().Is(typeof(DateTimeOffset));
|
||||
((DateTimeOffset)o.Obj).Is(now);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypelessEnum()
|
||||
{
|
||||
var e = MessagePackSerializer.Typeless.Serialize(GlobalMyEnum.Apple);
|
||||
var b = MessagePackSerializer.Typeless.Deserialize(e);
|
||||
b.GetType().Is(typeof(GlobalMyEnum));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MyTestMethod()
|
||||
{
|
||||
var sampleMessage = new InternalSampleMessageType
|
||||
{
|
||||
DateProp = new DateTime(2016, 10, 8, 1, 2, 3, DateTimeKind.Utc),
|
||||
GuidProp = Guid.NewGuid(),
|
||||
IntProp = 123,
|
||||
StringProp = "Hello World",
|
||||
};
|
||||
|
||||
{
|
||||
var serializedMessage = MessagePackSerializer.Typeless.Serialize(sampleMessage);
|
||||
var r2 = (InternalSampleMessageType)MessagePackSerializer.Typeless.Deserialize(serializedMessage);
|
||||
r2.DateProp.Is(sampleMessage.DateProp);
|
||||
r2.GuidProp.Is(sampleMessage.GuidProp);
|
||||
r2.IntProp.Is(sampleMessage.IntProp);
|
||||
r2.StringProp.Is(sampleMessage.StringProp);
|
||||
}
|
||||
|
||||
{
|
||||
var serializedMessage = MessagePackSerializer.Typeless.Serialize(sampleMessage, MessagePackSerializer.Typeless.DefaultOptions.WithLZ4Compression());
|
||||
var r2 = (InternalSampleMessageType)MessagePackSerializer.Typeless.Deserialize(serializedMessage, MessagePackSerializer.Typeless.DefaultOptions.WithLZ4Compression());
|
||||
r2.DateProp.Is(sampleMessage.DateProp);
|
||||
r2.GuidProp.Is(sampleMessage.GuidProp);
|
||||
r2.IntProp.Is(sampleMessage.IntProp);
|
||||
r2.StringProp.Is(sampleMessage.StringProp);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveArrayType()
|
||||
{
|
||||
{
|
||||
string[] array = new[] { "test1", "test2" };
|
||||
byte[] bytes = MessagePackSerializer.Typeless.Serialize(array);
|
||||
object obj = MessagePackSerializer.Typeless.Deserialize(bytes);
|
||||
|
||||
var obj2 = obj as string[];
|
||||
obj2.Is("test1", "test2");
|
||||
}
|
||||
|
||||
{
|
||||
var objRaw = new SomeClass
|
||||
{
|
||||
Obj = new string[] { "asd", "asd" },
|
||||
};
|
||||
|
||||
var objSer = MessagePackSerializer.Serialize(objRaw, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
SomeClass objDes = MessagePackSerializer.Deserialize<SomeClass>(objSer, TypelessContractlessStandardResolver.Options);
|
||||
|
||||
var expectedTrue = objDes.Obj is string[];
|
||||
expectedTrue.IsTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SomeClass
|
||||
{
|
||||
public object Obj { get; set; }
|
||||
}
|
||||
|
||||
internal class InternalSampleMessageType
|
||||
{
|
||||
public string StringProp { get; set; }
|
||||
|
||||
public int IntProp { get; set; }
|
||||
|
||||
public Guid GuidProp { get; set; }
|
||||
|
||||
public DateTime DateProp { get; set; }
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче