diff --git a/Nino.unitypackage b/Nino.unitypackage
new file mode 100644
index 0000000..9875b7f
Binary files /dev/null and b/Nino.unitypackage differ
diff --git a/Nino_Unity/Assets/Nino/Editor/SerializationHelper.cs b/Nino_Unity/Assets/Nino/Editor/SerializationHelper.cs
deleted file mode 100644
index 84d97e5..0000000
--- a/Nino_Unity/Assets/Nino/Editor/SerializationHelper.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-#if UNITY_2017_1_OR_NEWER
-using System.IO;
-using System.Linq;
-using UnityEditor;
-using System.Reflection;
-using Nino.Serialization;
-
-namespace Nino.Editor
-{
- public static class SerializationHelper
- {
- ///
- /// External DLL, such as ILRuntime/huatuo hot update dll
- /// 外部dll,例如ILRuntime和huatuo的热更dll
- ///
- private static readonly string[] ExternalDLLPath = new string[]
- {
-#if ILRuntime
- "Assets/Nino/Test/Editor/Serialization/Test11.bytes"
-#endif
- };
-
- ///
- /// Export path, you can change this to export it anywhere under Assets directory
- /// If you want to export outside of Assets, you can use ../
- /// 导出目录,你可以修改这个路径,代码会生成到Assets目录下你指定的这个路径内
- /// 如果需要导出到Assets外部,可以在路径内写入../
- ///
- private const string ExportPath = "Nino/Generated";
-
- [MenuItem("Nino/Generator/Serialization Code")]
- public static void GenerateSerializationCode()
- {
- var assemblies = System.AppDomain.CurrentDomain.GetAssemblies().ToList();
- assemblies.AddRange(ExternalDLLPath.Select(s => Assembly.Load(File.ReadAllBytes(s))));
- // ReSharper disable RedundantArgumentDefaultValue
- CodeGenerator.GenerateSerializationCodeForAllTypePossible(ExportPath, assemblies.ToArray());
- AssetDatabase.Refresh();
- // ReSharper restore RedundantArgumentDefaultValue
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_BuildTestDataCodeGen_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_BuildTestDataCodeGen_Serialize.cs
deleted file mode 100644
index e7acec1..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_BuildTestDataCodeGen_Serialize.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class BuildTestDataCodeGen
- {
- public static BuildTestDataCodeGen.SerializationHelper NinoSerializationHelper = new BuildTestDataCodeGen.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(BuildTestDataCodeGen value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(ref value.a, sizeof(System.Byte),ref value.b, sizeof(System.SByte),ref value.c, sizeof(System.Int16),ref value.d, sizeof(System.UInt16),ref value.e, sizeof(System.Int32),ref value.f, sizeof(System.UInt32),ref value.g, sizeof(System.Int64),ref value.h, sizeof(System.UInt64));
- writer.Write(ref value.i, sizeof(System.Single),ref value.j, sizeof(System.Double),ref value.k, sizeof(System.Decimal),ref value.l, sizeof(System.Boolean),ref value.m, sizeof(System.Char));
- writer.Write(value.n);
- writer.Write(value.o);
- writer.Write(value.p);
- writer.Write(value.q);
- writer.Write(value.r);
- writer.Write(value.s);
- writer.Write(value.t);
- writer.Write(value.u);
- writer.Write(value.v);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override BuildTestDataCodeGen Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- BuildTestDataCodeGen value = new BuildTestDataCodeGen();
- reader.Read(ref value.a, sizeof(System.Byte),ref value.b, sizeof(System.SByte),ref value.c, sizeof(System.Int16),ref value.d, sizeof(System.UInt16),ref value.e, sizeof(System.Int32),ref value.f, sizeof(System.UInt32),ref value.g, sizeof(System.Int64),ref value.h, sizeof(System.UInt64));
- reader.Read(ref value.i, sizeof(System.Single),ref value.j, sizeof(System.Double),ref value.k, sizeof(System.Decimal),ref value.l, sizeof(System.Boolean),ref value.m, sizeof(System.Char));
- value.n = reader.ReadString();
- value.o = reader.ReadList();
- value.p = reader.ReadList();
- value.q = reader.ReadArray();
- value.r = reader.ReadArray();
- value.s = reader.ReadDictionary();
- value.t = reader.ReadDictionary();
- value.u = reader.ReadDictionary();
- value.v = reader.ReadDictionary();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(BuildTestDataCodeGen value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.a);
- ret += Nino.Serialization.Serializer.GetSize(value.b);
- ret += Nino.Serialization.Serializer.GetSize(value.c);
- ret += Nino.Serialization.Serializer.GetSize(value.d);
- ret += Nino.Serialization.Serializer.GetSize(value.e);
- ret += Nino.Serialization.Serializer.GetSize(value.f);
- ret += Nino.Serialization.Serializer.GetSize(value.g);
- ret += Nino.Serialization.Serializer.GetSize(value.h);
- ret += Nino.Serialization.Serializer.GetSize(value.i);
- ret += Nino.Serialization.Serializer.GetSize(value.j);
- ret += Nino.Serialization.Serializer.GetSize(value.k);
- ret += Nino.Serialization.Serializer.GetSize(value.l);
- ret += Nino.Serialization.Serializer.GetSize(value.m);
- ret += Nino.Serialization.Serializer.GetSize(value.n);
- ret += Nino.Serialization.Serializer.GetSize(value.o);
- ret += Nino.Serialization.Serializer.GetSize(value.p);
- ret += Nino.Serialization.Serializer.GetSize(value.q);
- ret += Nino.Serialization.Serializer.GetSize(value.r);
- ret += Nino.Serialization.Serializer.GetSize(value.s);
- ret += Nino.Serialization.Serializer.GetSize(value.t);
- ret += Nino.Serialization.Serializer.GetSize(value.u);
- ret += Nino.Serialization.Serializer.GetSize(value.v);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_CollectionTest_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_CollectionTest_Serialize.cs
deleted file mode 100644
index 960f649..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_CollectionTest_Serialize.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class CollectionTest
- {
- public static CollectionTest.SerializationHelper NinoSerializationHelper = new CollectionTest.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(CollectionTest value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(value.a);
- writer.Write(value.b);
- writer.Write(value.c);
- writer.Write(value.d);
- writer.Write(value.e);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override CollectionTest Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- CollectionTest value = new CollectionTest();
- value.a = reader.ReadList();
- value.b = reader.ReadList();
- value.c = reader.ReadDictionary();
- value.d = reader.ReadDictionary();
- value.e = reader.ReadDictionary();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(CollectionTest value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.a);
- ret += Nino.Serialization.Serializer.GetSize(value.b);
- ret += Nino.Serialization.Serializer.GetSize(value.c);
- ret += Nino.Serialization.Serializer.GetSize(value.d);
- ret += Nino.Serialization.Serializer.GetSize(value.e);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_ComplexData_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_ComplexData_Serialize.cs
deleted file mode 100644
index 83ed16f..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_ComplexData_Serialize.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class ComplexData
- {
- public static ComplexData.SerializationHelper NinoSerializationHelper = new ComplexData.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(ComplexData value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(value.a);
- writer.Write(value.b);
- writer.Write(value.c);
- writer.Write(value.d);
- writer.Write(value.e);
- writer.Write(value.f);
- writer.Write(value.g);
- writer.Write(value.h);
- writer.Write(value.i);
- writer.Write(value.j);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override ComplexData Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- ComplexData value = new ComplexData();
- value.a = reader.ReadArray();
- value.b = reader.ReadList();
- value.c = reader.ReadArray>();
- value.d = reader.ReadDictionary>();
- value.e = reader.ReadArray>>();
- value.f = reader.ReadArray();
- value.g = reader.ReadList();
- value.h = reader.ReadArray();
- value.i = reader.ReadArray>();
- value.j = reader.ReadArray>();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(ComplexData value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.a);
- ret += Nino.Serialization.Serializer.GetSize(value.b);
- ret += Nino.Serialization.Serializer.GetSize(value.c);
- ret += Nino.Serialization.Serializer.GetSize(value.d);
- ret += Nino.Serialization.Serializer.GetSize(value.e);
- ret += Nino.Serialization.Serializer.GetSize(value.f);
- ret += Nino.Serialization.Serializer.GetSize(value.g);
- ret += Nino.Serialization.Serializer.GetSize(value.h);
- ret += Nino.Serialization.Serializer.GetSize(value.i);
- ret += Nino.Serialization.Serializer.GetSize(value.j);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_CustomTypeTest_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_CustomTypeTest_Serialize.cs
deleted file mode 100644
index 861a096..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_CustomTypeTest_Serialize.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class CustomTypeTest
- {
- public static CustomTypeTest.SerializationHelper NinoSerializationHelper = new CustomTypeTest.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(CustomTypeTest value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(ref value.v3, sizeof(UnityEngine.Vector3),ref value.dt, sizeof(System.DateTime));
- writer.Write(value.ni);
- writer.Write(value.qs);
- writer.Write(ref value.m, sizeof(UnityEngine.Matrix4x4));
- writer.Write(value.dict);
- writer.Write(value.dict2);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override CustomTypeTest Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- CustomTypeTest value = new CustomTypeTest();
- reader.Read(ref value.v3, sizeof(UnityEngine.Vector3),ref value.dt, sizeof(System.DateTime));
- value.ni = reader.ReadNullable();
- value.qs = reader.ReadList();
- reader.Read(ref value.m, sizeof(UnityEngine.Matrix4x4));
- value.dict = reader.ReadDictionary();
- value.dict2 = reader.ReadDictionary();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(CustomTypeTest value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.v3);
- ret += Nino.Serialization.Serializer.GetSize(value.dt);
- ret += Nino.Serialization.Serializer.GetSize(value.ni);
- ret += Nino.Serialization.Serializer.GetSize(value.qs);
- ret += Nino.Serialization.Serializer.GetSize(value.m);
- ret += Nino.Serialization.Serializer.GetSize(value.dict);
- ret += Nino.Serialization.Serializer.GetSize(value.dict2);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_Data_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_Data_Serialize.cs
deleted file mode 100644
index 082a81a..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_Data_Serialize.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial struct Data
- {
- public static Data.SerializationHelper NinoSerializationHelper = new Data.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
- int ret = 1;
- ret += sizeof(System.Int32);
- ret += sizeof(System.Int16);
- ret += sizeof(System.Int64);
- ret += sizeof(System.Single);
- ret += sizeof(System.Decimal);
- ret += sizeof(System.Double);
- ret += sizeof(System.Boolean);
- ret += sizeof(Nino.Test.TestEnum);
- Nino.Serialization.Serializer.SetFixedSize(ret);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(Data value, ref Nino.Serialization.Writer writer)
- {
-
- writer.Write(true);
- writer.Write(ref value.x, sizeof(System.Int32),ref value.y, sizeof(System.Int16),ref value.z, sizeof(System.Int64),ref value.f, sizeof(System.Single),ref value.d, sizeof(System.Decimal),ref value.db, sizeof(System.Double),ref value.bo, sizeof(System.Boolean),ref value.en, sizeof(Nino.Test.TestEnum));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override Data Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return default;
- Data value = new Data();
- reader.Read(ref value.x, sizeof(System.Int32),ref value.y, sizeof(System.Int16),ref value.z, sizeof(System.Int64),ref value.f, sizeof(System.Single),ref value.d, sizeof(System.Decimal),ref value.db, sizeof(System.Double),ref value.bo, sizeof(System.Boolean),ref value.en, sizeof(Nino.Test.TestEnum));
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(Data value)
- {
-
- return Nino.Serialization.Serializer.GetFixedSize();
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_IncludeAllClassCodeGen_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_IncludeAllClassCodeGen_Serialize.cs
deleted file mode 100644
index a35fa86..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_IncludeAllClassCodeGen_Serialize.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class IncludeAllClassCodeGen
- {
- public static IncludeAllClassCodeGen.SerializationHelper NinoSerializationHelper = new IncludeAllClassCodeGen.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
- int ret = 1;
- ret += sizeof(System.Int32);
- ret += sizeof(System.Int64);
- ret += sizeof(System.Single);
- ret += sizeof(System.Double);
- Nino.Serialization.Serializer.SetFixedSize(ret);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(IncludeAllClassCodeGen value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(ref value.a, sizeof(System.Int32),ref value.b, sizeof(System.Int64),ref value.c, sizeof(System.Single),ref value.d, sizeof(System.Double));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override IncludeAllClassCodeGen Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- IncludeAllClassCodeGen value = new IncludeAllClassCodeGen();
- reader.Read(ref value.a, sizeof(System.Int32),ref value.b, sizeof(System.Int64),ref value.c, sizeof(System.Single),ref value.d, sizeof(System.Double));
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(IncludeAllClassCodeGen value)
- {
- if(value == null)
- {
- return 1;
- }
- return Nino.Serialization.Serializer.GetFixedSize();
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData2_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData2_Serialize.cs
deleted file mode 100644
index 1f48182..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData2_Serialize.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class NestedData2
- {
- public static NestedData2.SerializationHelper NinoSerializationHelper = new NestedData2.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(NestedData2 value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(value.name);
- writer.Write(value.ps);
- writer.Write(value.vs);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override NestedData2 Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- NestedData2 value = new NestedData2();
- value.name = reader.ReadString();
- value.ps = reader.ReadArray();
- value.vs = reader.ReadList();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(NestedData2 value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.name);
- ret += Nino.Serialization.Serializer.GetSize(value.ps);
- ret += Nino.Serialization.Serializer.GetSize(value.vs);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData_Serialize.cs
deleted file mode 100644
index e6688da..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NestedData_Serialize.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class NestedData
- {
- public static NestedData.SerializationHelper NinoSerializationHelper = new NestedData.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(NestedData value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(value.name);
- writer.Write(value.ps);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override NestedData Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- NestedData value = new NestedData();
- value.name = reader.ReadString();
- value.ps = reader.ReadArray();
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(NestedData value)
- {
- if(value == null)
- {
- return 1;
- }
- int ret = 1;
- ret += Nino.Serialization.Serializer.GetSize(value.name);
- ret += Nino.Serialization.Serializer.GetSize(value.ps);
- return ret;
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NotIncludeAllClass_Serialize.cs b/Nino_Unity/Assets/Nino/Generated/Nino_Test_NotIncludeAllClass_Serialize.cs
deleted file mode 100644
index 94dff11..0000000
--- a/Nino_Unity/Assets/Nino/Generated/Nino_Test_NotIncludeAllClass_Serialize.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-namespace Nino.Test
-{
- public partial class NotIncludeAllClass
- {
- public static NotIncludeAllClass.SerializationHelper NinoSerializationHelper = new NotIncludeAllClass.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
- int ret = 1;
- ret += sizeof(System.Int32);
- ret += sizeof(System.Int64);
- ret += sizeof(System.Single);
- ret += sizeof(System.Double);
- Nino.Serialization.Serializer.SetFixedSize(ret);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize(NotIncludeAllClass value, ref Nino.Serialization.Writer writer)
- {
- if(value == null)
- {
- writer.Write(false);
- return;
- }
- writer.Write(true);
- writer.Write(ref value.a, sizeof(System.Int32),ref value.b, sizeof(System.Int64),ref value.c, sizeof(System.Single),ref value.d, sizeof(System.Double));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override NotIncludeAllClass Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- return null;
- NotIncludeAllClass value = new NotIncludeAllClass();
- reader.Read(ref value.a, sizeof(System.Int32),ref value.b, sizeof(System.Int64),ref value.c, sizeof(System.Single),ref value.d, sizeof(System.Double));
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize(NotIncludeAllClass value)
- {
- if(value == null)
- {
- return 1;
- }
- return Nino.Serialization.Serializer.GetFixedSize();
- }
- #endregion
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Attributes/CodeGenIgnoreAttribute.cs b/Nino_Unity/Assets/Nino/Serialization/Attributes/CodeGenIgnoreAttribute.cs
deleted file mode 100644
index ce79d46..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Attributes/CodeGenIgnoreAttribute.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace Nino.Serialization
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
- public class CodeGenIgnoreAttribute : Attribute
- {
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoIgnoreAttribute.cs b/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoIgnoreAttribute.cs
deleted file mode 100644
index e59454b..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoIgnoreAttribute.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace Nino.Serialization
-{
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
- public class NinoIgnoreAttribute : Attribute
- {
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoMemberAttribute.cs b/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoMemberAttribute.cs
deleted file mode 100644
index c756f58..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoMemberAttribute.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-
-namespace Nino.Serialization
-{
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
- public class NinoMemberAttribute : Attribute
- {
- public readonly ushort Index;
-
- ///
- /// Indicate a member that can be serialized and deserialized
- /// 标明该成员可以被序列化或反序列化
- ///
- /// index while serializing or deserializing | 序列化或反序列化时的顺序
- public NinoMemberAttribute(ushort index)
- {
- this.Index = index;
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoSerializeAttribute.cs b/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoSerializeAttribute.cs
deleted file mode 100644
index 609cd02..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Attributes/NinoSerializeAttribute.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-
-namespace Nino.Serialization
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
- public class NinoSerializeAttribute : Attribute
- {
- public readonly bool IncludeAll;
-
- ///
- /// A struct or class to be serialized and deserialized
- /// 一个结构体或一个类型的会被序列化以及反序列化
- /// include all fields and properties
- ///
- public NinoSerializeAttribute(bool includeAll = true)
- {
- IncludeAll = includeAll;
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/CodeGenerator.cs b/Nino_Unity/Assets/Nino/Serialization/CodeGenerator.cs
deleted file mode 100644
index 0e1102f..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/CodeGenerator.cs
+++ /dev/null
@@ -1,696 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using Nino.Shared.Mgr;
-using Nino.Shared.Util;
-using System.Reflection;
-
-namespace Nino.Serialization
-{
- ///
- /// Nino code generator
- /// TODO support nullable, hashset, queue, stack
- ///
- public static class CodeGenerator
- {
- ///
- /// Generate serialization code file at Assets/ouputPath
- /// editor only method
- ///
- ///
- ///
- public static void GenerateSerializationCodeForAllTypePossible(string outputPath = "Nino/Generated",
- Assembly[] assemblies = null)
- {
- //find all types
- var types = (assemblies ?? AppDomain.CurrentDomain.GetAssemblies()).SelectMany(a => a.GetTypes()).ToList()
- .FindAll(t =>
- {
- //find NinoSerializeAttribute
- NinoSerializeAttribute[] ns =
- (NinoSerializeAttribute[])t.GetCustomAttributes(typeof(NinoSerializeAttribute), true);
- if (ns.Length == 0) return false;
- return true;
- }).ToList();
- //iterate
- foreach (var type in types)
- {
- //gen
- GenerateSerializationCode(type, outputPath);
- }
- }
-
- ///
- /// Get a valid nino serialize class
- ///
- ///
- ///
- ///
- private static bool GetValidNinoClass(Type type, bool log = true)
- {
- //nested
- if (type.IsNested)
- {
- if (log)
- Logger.E("Code Gen", $"Can not generate code for type: {type} due to it is a nested class");
- return false;
- }
-
- //generic
- if (type.IsGenericType)
- {
- if (log)
- Logger.E("Code Gen", $"Can not generate code for type: {type} due to it is a generic class");
- return false;
- }
-
- //find NinoSerializeAttribute
- NinoSerializeAttribute[] ns =
- (NinoSerializeAttribute[])type.GetCustomAttributes(typeof(NinoSerializeAttribute), true);
- if (ns.Length == 0) return false;
-
- CodeGenIgnoreAttribute[] ci =
- (CodeGenIgnoreAttribute[])type.GetCustomAttributes(typeof(CodeGenIgnoreAttribute), true);
- if (ci.Length != 0) return false;
- return true;
- }
-
- ///
- /// Generate serialization code file at Assets/ouputPath
- /// editor only method
- ///
- ///
- ///
- // ReSharper disable CognitiveComplexity
- public static void GenerateSerializationCode(Type type, string outputPath = "Nino/Generated")
- // ReSharper restore CognitiveComplexity
- {
- //nino class only
- if (!GetValidNinoClass(type)) return;
-
- //code template
- string template =
- @"/* this is generated by nino */
-using System.Runtime.CompilerServices;
-
-{namespace}
-{start}
- public partial struct {type}
- {
- public static {type}.SerializationHelper NinoSerializationHelper = new {type}.SerializationHelper();
- public unsafe class SerializationHelper: Nino.Serialization.NinoWrapperBase<{type}>
- {
- #region NINO_CODEGEN
- public SerializationHelper()
- {
-{ctor}
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override void Serialize({type} value, ref Nino.Serialization.Writer writer)
- {
- {nullCheck}
- writer.Write(true);
-{members}
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override {type} Deserialize(Nino.Serialization.Reader reader)
- {
- if(!reader.ReadBool())
- {returnNull}
- {createObj}
-{fields}
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetSize({type} value)
- {
- {sizeNull}
-{size}
- }
- #endregion
- }
- }
-{end}";
- if (type.IsClass)
- {
- template = template.Replace("struct", "class");
- template = template.Replace("{nullCheck}", @"if(value == null)
- {
- writer.Write(false);
- return;
- }");
- template = template.Replace("{returnNull}", "return null;");
- template = template.Replace("{sizeNull}", @"if(value == null)
- {
- return 1;
- }");
-
-#if UNITY_2017_1_OR_NEWER
- //see if type inherits MonoBehaviour
- if (type.IsSubclassOf(typeof(UnityEngine.MonoBehaviour)))
- {
- template = template.Replace("{createObj}", "{type} value = new UnityEngine.GameObject(\"{type}\").AddComponent<{type}>();");
- }
- else
-#endif
- {
- template = template.Replace("{createObj}", "{type} value = new {type}();");
- }
- }
- else
- {
- template = template.Replace("{nullCheck}", @"");
- template = template.Replace("{returnNull}", "return default;");
- template = template.Replace("{sizeNull}", @"");
- }
-
- //replace namespace
- if (!string.IsNullOrEmpty(type.Namespace))
- {
- template = template.Replace("{namespace}", $"namespace {type.Namespace}");
- template = template.Replace("{start}", "{");
- template = template.Replace("{end}", "}");
- }
- else
- {
- template = template.Replace("{namespace}", string.Empty);
- template = template.Replace("{start}", string.Empty);
- template = template.Replace("{end}", string.Empty);
- }
-
- //class full name
- var classFullName =
- $"{type.GetFriendlyName()}";
- //replace full name
- template = template.Replace("{type}", classFullName);
-
- //find members
- TypeModel.TryGetModel(type, out var model);
- //invalid model
- if (model != null)
- {
- if (!model.Valid)
- {
- throw new InvalidOperationException("invalid model");
- }
- }
-
- //generate model
- if (model == null)
- {
- model = TypeModel.CreateModel(type);
- }
-
- var members = model.Members;
-
- #region serialize
-
- //build params
- StringBuilder sb = new StringBuilder();
- List unmanagedMembers = new List();
- for (int i = 0; i < members.Count; i++)
- {
- var info = members[i];
- var member = info.Member;
- var mt = info.Type;
-
- //try optimize
- if (TypeModel.IsUnmanaged(mt) && member is FieldInfo)
- {
- unmanagedMembers.Clear();
- unmanagedMembers.Add(info);
- for (int j = i + 1; j < members.Count; j++)
- {
- var info2 = members[j];
- var member2 = info2.Member;
- var mt2 = info2.Type;
- if (TypeModel.IsUnmanaged(mt2) && member2 is FieldInfo)
- {
- unmanagedMembers.Add(info2);
- }
- else
- {
- break;
- }
- }
-
- i += unmanagedMembers.Count - 1;
- //batch write with batch size 8
- while (unmanagedMembers.Count > 0)
- {
- if (unmanagedMembers.Count <= 8)
- {
- sb.Append(
- $" writer.Write({string.Join(",", unmanagedMembers.Select(x => $"ref value.{x.Member.Name}, sizeof({BeautifulLongTypeName(x.Type)})"))});\n");
- unmanagedMembers.Clear();
- }
- else
- {
- sb.Append(
- $" writer.Write({string.Join(",", unmanagedMembers.Take(8).Select(x => $"ref value.{x.Member.Name}, sizeof({BeautifulLongTypeName(x.Type)})"))});\n");
- unmanagedMembers.RemoveRange(0, 8);
- }
- }
-
- continue;
- }
-
- //enum
- if (mt.IsEnum)
- {
- sb.Append(
- $" writer.WriteEnum<{BeautifulLongTypeName(mt)}>(value.{member.Name});\n");
- }
- //array/list
- else if (mt.IsArray || (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.ListDefType))
- {
- sb.Append($" writer.Write(value.{member.Name});\n");
- }
- //dict
- else if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.DictDefType)
- {
- sb.Append($" writer.Write(value.{member.Name});\n");
- }
- //nullable
- else if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.NullableDefType)
- {
- sb.Append($" writer.Write(value.{member.Name});\n");
- }
- //basic type
- else
- {
- sb.Append(
- $" {GetSerializeBasicTypeStatement(mt, $"value.{member.Name}", member is PropertyInfo)};\n");
- }
- }
-
- if (members.Count > 0)
- {
- //remove \n at the end
- sb.Remove(sb.Length - 1, 1);
- }
-
- //replace template members
- template = template.Replace("{members}", sb.ToString());
-
- #endregion
-
- #region deserialize
-
- sb.Clear();
- for (int i = 0; i < members.Count; i++)
- {
- var info = members[i];
- var member = info.Member;
- var mt = info.Type;
-
- //try optimize
- if (TypeModel.IsUnmanaged(mt) && member is FieldInfo)
- {
- unmanagedMembers.Clear();
- unmanagedMembers.Add(info);
- for (int j = i + 1; j < members.Count; j++)
- {
- var info2 = members[j];
- var member2 = info2.Member;
- var mt2 = info2.Type;
- if (TypeModel.IsUnmanaged(mt2) && member2 is FieldInfo)
- {
- unmanagedMembers.Add(info2);
- }
- else
- {
- break;
- }
- }
-
- i += unmanagedMembers.Count - 1;
- //batch write with batch size 8
- while (unmanagedMembers.Count > 0)
- {
- if (unmanagedMembers.Count <= 8)
- {
- sb.Append(
- $" reader.Read({string.Join(",", unmanagedMembers.Select(x => $"ref value.{x.Member.Name}, sizeof({BeautifulLongTypeName(x.Type)})"))});\n");
- unmanagedMembers.Clear();
- }
- else
- {
- sb.Append(
- $" reader.Read({string.Join(",", unmanagedMembers.Take(8).Select(x => $"ref value.{x.Member.Name}, sizeof({BeautifulLongTypeName(x.Type)})"))});\n");
- unmanagedMembers.RemoveRange(0, 8);
- }
- }
-
- continue;
- }
-
- //enum
- if (mt.IsEnum)
- {
- if (member is PropertyInfo)
- {
- sb.Append(
- $" value.{member.Name} = reader.ReadEnum<{BeautifulLongTypeName(mt)}>();\n");
- }
- else
- {
- sb.Append(
- $" reader.ReadEnum<{BeautifulLongTypeName(mt)}>(ref value.{member.Name});\n");
- }
- }
- //array/list
- else if (mt.IsArray || (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.ListDefType))
- {
- Type elemType = mt.IsGenericType ? mt.GenericTypeArguments[0] : mt.GetElementType();
-
- //create field
- if (mt.IsArray)
- {
- //multidimensional array
- if (mt.GetArrayRank() > 1)
- {
- throw new NotSupportedException(
- "can not serialize multidimensional array, use jagged array instead");
- }
-
- sb.Append(
- $" value.{member.Name} = reader.ReadArray<{BeautifulLongTypeName(elemType)}>();\n");
- }
- else
- {
- sb.Append(
- $" value.{member.Name} = reader.ReadList<{BeautifulLongTypeName(elemType)}>();\n");
- }
- }
- //dict
- else if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.DictDefType)
- {
- var args = mt.GetGenericArguments();
- Type keyType = args[0];
- Type valueType = args[1];
-
- sb.Append(
- $" value.{member.Name} = reader.ReadDictionary<{BeautifulLongTypeName(keyType)},{BeautifulLongTypeName(valueType)}>();\n");
- }
- //nullable
- else if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.NullableDefType)
- {
- var args = mt.GetGenericArguments();
- Type keyType = args[0];
-
- sb.Append(
- $" value.{member.Name} = reader.ReadNullable<{BeautifulLongTypeName(keyType)}>();\n");
- }
- //not enum -> basic type
- else
- {
- string val = GetDeserializeBasicTypeStatement(mt, member is PropertyInfo,
- $"value.{member.Name}");
- sb.Append($" {val}\n");
- }
- }
-
- sb.Append(" return value;\n");
- //remove comma at the end
- sb.Remove(sb.Length - 1, 1);
-
- //replace template fields
- template = template.Replace("{fields}", sb.ToString());
-
- #endregion
-
- #region getsize
-
- sb.Clear();
- if (TypeModel.IsFixedSizeType(type))
- {
- sb.Append(
- $" return Nino.Serialization.Serializer.GetFixedSize<{BeautifulLongTypeName(type)}>();");
- }
- else
- {
- sb.Append(" int ret = 1;\n");
- foreach (var info in members)
- {
- var member = info.Member;
- var size = Serializer.GetFixedSize(info.Type);
- sb.Append(
- size != -1
- ? $" ret += {size}; // size for {member.Name}\n"
- : $" ret += Nino.Serialization.Serializer.GetSize(value.{member.Name});\n");
- }
-
- sb.Append(" return ret;");
- }
-
- //replace template fields
- template = template.Replace("{size}", sb.ToString());
-
- #endregion
-
- #region ctor
-
- sb.Clear();
- if (TypeModel.IsFixedSizeType(type))
- {
- sb.Append(" int ret = 1;\n");
- foreach (var info in members)
- {
- var mt = info.Type;
- sb.Append(
- $" ret += sizeof({BeautifulLongTypeName(mt)});\n");
- }
-
- sb.Append(
- $" Nino.Serialization.Serializer.SetFixedSize<{BeautifulLongTypeName(type)}>(ret);");
- }
-
- //replace template fields
- template = template.Replace("{ctor}", sb.ToString());
-
- #endregion
-
- //save path
- var output = Path.Combine(ConstMgr.AssetPath, outputPath);
- if (!Directory.Exists(output))
- {
- Directory.CreateDirectory(output);
- }
-
- //save file path
- output = Path.Combine(output,
- $"{type.Namespace}{(!string.IsNullOrEmpty(type.Namespace) ? "." : "")}{type.GetFriendlyName()}"
- .Replace(".", "_").Replace(",", "_")
- .Replace("<", "_").Replace(">", "_") +
- "_Serialize.cs");
- if (File.Exists(output))
- {
- File.Delete(output);
- }
-
- //save
- File.WriteAllText(output, template);
-
-#if UNITY_2017_1_OR_NEWER
- Logger.D("Code Gen", $"saved {output}");
-#else
- Logger.D("Code Gen", $"saved {output}, please move this file to your project");
-#endif
- }
-
- // ReSharper disable CognitiveComplexity
- private static string GetDeserializeBasicTypeStatement(Type mt, bool isProperty, string val = "",
- string space = " ")
- // ReSharper restore CognitiveComplexity
- {
- switch (Type.GetTypeCode(mt))
- {
- case TypeCode.Int32:
- case TypeCode.UInt32:
- case TypeCode.Int64:
- case TypeCode.UInt64:
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Int16:
- case TypeCode.UInt16:
- case TypeCode.Boolean:
- case TypeCode.Double:
- case TypeCode.Single:
- case TypeCode.Decimal:
- case TypeCode.Char:
- case TypeCode.DateTime:
- return isProperty
- ? $"{val} = reader.Read<{BeautifulLongTypeName(mt)}>(sizeof({BeautifulLongTypeName(mt)}));"
- : $"reader.Read<{BeautifulLongTypeName(mt)}>(ref {val}, sizeof({BeautifulLongTypeName(mt)}));";
- case TypeCode.String:
- return $"{val} = reader.ReadString();";
- default:
- if (GetValidNinoClass(mt, false))
- {
- return $"{val} = {BeautifulLongTypeName(mt)}.NinoSerializationHelper.Deserialize(reader);";
- }
-
- //enum
- if (mt.IsEnum)
- {
- return isProperty
- ? $"{val} = reader.ReadEnum<{BeautifulLongTypeName(mt)}>();"
- : $"reader.ReadEnum<{BeautifulLongTypeName(mt)}>(ref {val});";
- }
-
- if (mt.IsArray ||
- (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.ListDefType))
- {
- Type elemType = mt.IsGenericType ? mt.GenericTypeArguments[0] : mt.GetElementType();
- StringBuilder builder = new StringBuilder();
- if (mt.IsArray)
- {
- //multidimensional array
- if (mt.GetArrayRank() > 1)
- {
- throw new NotSupportedException(
- "can not serialize multidimensional array, use jagged array instead");
- }
-
- builder.Append(
- $"{val} = reader.ReadArray<{BeautifulLongTypeName(elemType)}>();\n");
- }
- else
- {
- builder.Append(
- $"{val} = reader.ReadList<{BeautifulLongTypeName(elemType)}>();\n");
- }
-
- return builder.ToString();
- }
-
- if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.DictDefType)
- {
- StringBuilder builder = new StringBuilder();
- var args = mt.GetGenericArguments();
- Type keyType = args[0];
- Type valueType = args[1];
- //create field
- builder.Append(space).Append(
- $"{BeautifulLongTypeName(mt)} {val} = reader.ReadDictionary<{BeautifulLongTypeName(keyType)},{BeautifulLongTypeName(valueType)}>();\n");
- return builder.ToString();
- }
-
- return $"{val} = reader.ReadCommonVal<{BeautifulLongTypeName(mt)}>();";
- }
- }
-
- // ReSharper disable CognitiveComplexity
- private static string GetSerializeBasicTypeStatement(Type mt, string val, bool isProperty, int indent = 0,
- string space = " ")
- // ReSharper restore CognitiveComplexity
- {
- switch (Type.GetTypeCode(mt))
- {
- case TypeCode.Int32:
- case TypeCode.UInt32:
- case TypeCode.Int64:
- case TypeCode.UInt64:
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Int16:
- case TypeCode.UInt16:
- case TypeCode.Boolean:
- case TypeCode.Double:
- case TypeCode.Single:
- case TypeCode.Decimal:
- case TypeCode.Char:
- case TypeCode.DateTime:
- return isProperty
- ? $"writer.Write({val})"
- : $"writer.Write(ref {val}, sizeof({BeautifulLongTypeName(mt)}))";
- case TypeCode.String:
- return $"writer.Write({val})";
- default:
- if (GetValidNinoClass(mt, false))
- {
- return $"{BeautifulLongTypeName(mt)}.NinoSerializationHelper.Serialize({val}, ref writer)";
- }
-
- if (mt.IsArray || (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.ListDefType))
- {
- StringBuilder builder = new StringBuilder();
- Type elemType = mt.IsGenericType ? mt.GenericTypeArguments[0] : mt.GetElementType();
- if (elemType == null)
- {
- throw new InvalidOperationException("Invalid array type");
- }
-
- builder.Append(space).Append(Repeat(" ", indent))
- .Append($"writer.Write({val});\n");
- return builder.ToString();
- }
-
- if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.DictDefType)
- {
- StringBuilder builder = new StringBuilder();
- builder.Append(space).Append(Repeat(" ", indent))
- .Append($"writer.Write({val});\n");
- return builder.ToString();
- }
-
- if (mt.IsGenericType && mt.GetGenericTypeDefinition() == ConstMgr.NullableDefType)
- {
- StringBuilder builder = new StringBuilder();
- builder.Append(space).Append(Repeat(" ", indent))
- .Append($"writer.Write({val});\n");
- return builder.ToString();
- }
-
- return $"writer.WriteCommonVal<{BeautifulLongTypeName(mt)}>({val})";
- }
- }
-
- private static string Repeat(string value, int count)
- {
- if (count < 1) return string.Empty;
- return new StringBuilder(value.Length * count).Insert(0, value, count).ToString();
- }
-
- private static string BeautifulLongTypeName(this Type mt)
- {
- return $"{mt.Namespace}{(!string.IsNullOrEmpty(mt.Namespace) ? "." : "")}{mt.GetFriendlyName()}";
- }
-
- ///
- /// 获取类型名字
- ///
- ///
- ///
- private static string GetFriendlyName(this Type type)
- {
- string friendlyName = type.Name;
- if (type.IsGenericType)
- {
- int iBacktick = friendlyName.IndexOf('`');
- if (iBacktick > 0)
- {
- friendlyName = friendlyName.Remove(iBacktick);
- }
-
- friendlyName += "<";
- Type[] typeParameters = type.GetGenericArguments();
- for (int i = 0; i < typeParameters.Length; ++i)
- {
- string typeParamName =
- $"{typeParameters[i].Namespace}{(!string.IsNullOrEmpty(typeParameters[i].Namespace) ? "." : "")}{GetFriendlyName(typeParameters[i])}";
- friendlyName += (i == 0 ? typeParamName : "," + typeParamName);
- }
-
- friendlyName += ">";
- }
-
- return friendlyName;
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Deserializer.Generic.cs b/Nino_Unity/Assets/Nino/Serialization/Deserializer.Generic.cs
deleted file mode 100644
index 7de3e7e..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Deserializer.Generic.cs
+++ /dev/null
@@ -1,335 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Nino.Shared.IO;
-
-namespace Nino.Serialization
-{
- public static partial class Deserializer
- {
- #region Array
-
- ///
- /// Deserialize an array NinoSerialize object
- ///
- ///
- ///
- ///
- public static T[] DeserializeArray(byte[] data)
- => DeserializeArray(new Span(data));
-
- ///
- /// Deserialize an array NinoSerialize object
- ///
- ///
- ///
- ///
- public static T[] DeserializeArray(ArraySegment data)
- => DeserializeArray(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize an array of NinoSerialize object
- ///
- ///
- ///
- ///
- public static T[] DeserializeArray(Span data)
- {
- var type = typeof(T[]);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true, out T[] ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadArray();
- }
-
- #endregion
-
- #region Nullable
-
- ///
- /// Deserialize a nullable of NinoSerialize struct
- ///
- ///
- ///
- ///
- public static T? DeserializeNullable(byte[] data)
- where T : struct
- => DeserializeNullable(new Span(data));
-
- ///
- /// Deserialize a nullable of NinoSerialize struct
- ///
- ///
- ///
- ///
- public static T? DeserializeNullable(ArraySegment data)
- where T : struct
- => DeserializeNullable(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a nullable of NinoSerialize struct
- ///
- ///
- ///
- ///
- public static T? DeserializeNullable(Span data)
- where T : struct
- {
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- //attempt to deserialize using generic method
- return reader.ReadNullable();
- }
-
- #endregion
-
- #region List
-
- ///
- /// Deserialize a list of NinoSerialize object
- ///
- ///
- ///
- ///
- public static List DeserializeList(byte[] data)
- => DeserializeList(new Span(data));
-
- ///
- /// Deserialize a list of NinoSerialize object
- ///
- ///
- ///
- ///
- public static List DeserializeList(ArraySegment data)
- => DeserializeList(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a list of NinoSerialize object
- ///
- ///
- ///
- ///
- public static List DeserializeList(Span data)
- {
- var type = typeof(List);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true, out List ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadList();
- }
-
- #endregion
-
- #region HashSet
-
- ///
- /// Deserialize a HashSet of NinoSerialize object
- ///
- ///
- ///
- ///
- public static HashSet DeserializeHashSet(byte[] data)
- => DeserializeHashSet(new Span(data));
-
- ///
- /// Deserialize a HashSet of NinoSerialize object
- ///
- ///
- ///
- ///
- public static HashSet DeserializeHashSet(ArraySegment data)
- => DeserializeHashSet(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a HashSet of NinoSerialize object
- ///
- ///
- ///
- ///
- public static HashSet DeserializeHashSet(Span data)
- {
- var type = typeof(HashSet);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true, out HashSet ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadHashSet();
- }
-
- #endregion
-
- #region Queue
-
- ///
- /// Deserialize a Queue of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Queue DeserializeQueue(byte[] data)
- => DeserializeQueue(new Span(data));
-
- ///
- /// Deserialize a Queue of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Queue DeserializeQueue(ArraySegment data)
- => DeserializeQueue(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a Queue of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Queue DeserializeQueue(Span data)
- {
- var type = typeof(Queue);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true, out Queue ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadQueue();
- }
-
- #endregion
-
- #region Stack
-
- ///
- /// Deserialize a Stack of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Stack DeserializeStack(byte[] data)
- => DeserializeStack(new Span(data));
-
- ///
- /// Deserialize a Stack of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Stack DeserializeStack(ArraySegment data)
- => DeserializeStack(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a Stack of NinoSerialize object
- ///
- ///
- ///
- ///
- public static Stack DeserializeStack(Span data)
- {
- var type = typeof(Stack);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true, out Stack ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadStack();
- }
-
- #endregion
-
- #region Dictionary
-
- ///
- /// Deserialize a Dictionary of NinoSerialize object
- ///
- ///
- ///
- ///
- ///
- public static Dictionary DeserializeDictionary(byte[] data)
- => DeserializeDictionary(new Span(data));
-
- ///
- /// Deserialize a Dictionary of NinoSerialize object
- ///
- ///
- ///
- ///
- ///
- public static Dictionary DeserializeDictionary(ArraySegment data)
- => DeserializeDictionary(new Span(data.Array, data.Offset, data.Count));
-
- ///
- /// Deserialize a Dictionary of NinoSerialize object
- ///
- ///
- ///
- ///
- ///
- public static Dictionary DeserializeDictionary(Span data)
- {
- var type = typeof(Dictionary);
- var reader = ObjectPool.Request();
- reader.Init(data, data.Length);
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, true,
- out Dictionary ret))
- {
- return ret;
- }
-
- //attempt to deserialize using generic method
- return reader.ReadDictionary();
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Deserializer.cs b/Nino_Unity/Assets/Nino/Serialization/Deserializer.cs
deleted file mode 100644
index 2881141..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Deserializer.cs
+++ /dev/null
@@ -1,565 +0,0 @@
-using System;
-using Nino.Shared.IO;
-using Nino.Shared.Mgr;
-using System.Reflection;
-using System.Collections;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace Nino.Serialization
-{
- public static partial class Deserializer
- {
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static T Deserialize(byte[] data)
- => Deserialize(new Span(data), null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static T Deserialize(ArraySegment data)
- => Deserialize(new Span(data.Array, data.Offset, data.Count), null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static T Deserialize(Span data)
- => Deserialize(data, null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static object Deserialize(Type type, byte[] data)
- => Deserialize(type, null, new Span(data), null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static object Deserialize(Type type, ArraySegment data)
- => Deserialize(type, null, new Span(data.Array, data.Offset, data.Count), null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- public static object Deserialize(Type type, Span data)
- => Deserialize(type, null, data, null);
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- ///
- ///
- internal static T Deserialize(Span data, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose = true)
- {
- Type type = typeof(T);
-
- if (reader == null)
- {
- reader = ObjectPool.Request();
- reader.Init(data, data.Length);
- }
-
- /*
- * NO GC DESERIALIZATION ATTEMPT
- */
- //basic type
- if (TryDeserializeWrapperType(type, reader, false, returnDispose, out T ret))
- {
- return ret;
- }
-
- //enum
- if (TryDeserializeEnum(type, reader, returnDispose, out var e))
- {
- return e;
- }
-
- //code generated type
- if (TryDeserializeCodeGenType(type, reader, false, returnDispose, out ret))
- {
- return ret;
- }
-
- //unmanaged type
- if (TryDeserializeUnmanagedType(type, reader, returnDispose, out var un))
- {
- return un;
- }
-
- /*
- * GC DESERIALIZATION WHILE T IS STRUCT
- */
- var result = Deserialize(type, null, data, reader, returnDispose);
- if (result != null) return (T)result;
- ObjectPool.Return(reader);
- return default;
- }
-
- ///
- /// Deserialize a NinoSerialize object
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- internal static object Deserialize(Type type, object val, Span data, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose = true)
- {
- if (reader == null)
- {
- reader = ObjectPool.Request();
- reader.Init(data, data.Length);
- }
-
- //array
- if (TryDeserializeArray(type, reader, returnDispose, out var arr))
- {
- return arr;
- }
-
- //list, dict
- if (type.IsGenericType)
- {
- var genericDefType = type.GetGenericTypeDefinition();
- if (TryDeserializeList(type, genericDefType, reader, returnDispose, out var lst))
- {
- return lst;
- }
-
- if (TryDeserializeDict(type, genericDefType, reader, returnDispose, out var dict))
- {
- return dict;
- }
- }
-
- //basic type
- if (TryDeserializeWrapperType(type, reader, true, returnDispose, out object basicObj))
- {
- return basicObj;
- }
-
- //enum
- if (TryDeserializeEnum(type, reader, returnDispose, out var e))
- {
- return e;
- }
-
- //code generated type
- if (TryDeserializeCodeGenType(type, reader, true, returnDispose, out object codeGenRet))
- {
- return codeGenRet;
- }
-
- //unmanaged type
- if (TryDeserializeUnmanagedType(type, reader, returnDispose, out var un))
- {
- return un;
- }
-
- /*
- * CUSTOM STRUCT/CLASS SERIALIZATION
- */
- if (ReadNullCheck(reader, returnDispose, out var nullCheck))
- {
- return nullCheck;
- }
-
- //create type
- if (val == null || val == ConstMgr.Null)
- {
-#if UNITY_2017_1_OR_NEWER
- //see if type inherits MonoBehaviour
- if (type.IsSubclassOf(typeof(UnityEngine.MonoBehaviour)))
- {
- val = new UnityEngine.GameObject(type.AssemblyQualifiedName).AddComponent(type);
- }
- else
-#endif
- {
- val = Activator.CreateInstance(type);
- }
- }
-
- //Get Attribute that indicates a class/struct to be serialized
- TypeModel.TryGetModel(type, out var model);
-
- //invalid model
- if (model != null && !model.Valid)
- {
- return val;
- }
-
- //generate model
- if (model == null)
- {
- model = TypeModel.CreateModel(type);
- }
-
- //start Deserialize
- foreach (var info in model.Members)
- {
- //if end, skip
- if (reader.EndOfReader)
- {
- break;
- }
-
- type = info.Type;
-
- //read basic values
- SetMember(info.Member, val, Deserialize(type, ConstMgr.Null, Span.Empty, reader, false));
- }
-
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return val;
- }
-
- ///
- /// Try deserialize wrapper type
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeWrapperType(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool boxed, [MarshalAs(UnmanagedType.U1)] bool returnDispose,
- out T ret)
- {
- if (WrapperManifest.TryGetWrapper(type, out var wrapper))
- {
- if (boxed)
- {
- var obj = wrapper.Deserialize(reader);
- ret = obj != null ? (T)obj : default;
- }
- else
- {
- ret = ((NinoWrapperBase)wrapper).Deserialize(reader);
- }
-
- if (returnDispose)
- ObjectPool.Return(reader);
- return true;
- }
-
- ret = default;
- return false;
- }
-
- ///
- /// Try deserialize code generated type (first time only)
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeCodeGenType(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool boxed, [MarshalAs(UnmanagedType.U1)] bool returnDispose,
- out T ret)
- {
- if (TypeModel.TryGetWrapper(type, out var wrapper))
- {
- //add wrapper
- WrapperManifest.AddWrapper(type, wrapper);
- //start Deserialize
- if (boxed)
- {
- var obj = wrapper.Deserialize(reader);
- ret = obj != null ? (T)obj : default;
- }
- else
- {
- ret = ((NinoWrapperBase)wrapper).Deserialize(reader);
- }
-
- if (returnDispose)
- ObjectPool.Return(reader);
- return true;
- }
-
- ret = default;
- return false;
- }
-
- ///
- /// Try deserialize array
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeArray(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out Array ret)
- {
- if (type.IsArray)
- {
- ret = reader.ReadArray(type);
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- ret = null;
- return false;
- }
-
- ///
- /// Try deserialize list
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeList(Type type, Type genericDefType, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out IList ret)
- {
- if (genericDefType == ConstMgr.ListDefType)
- {
- ret = reader.ReadList(type);
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- ret = null;
- return false;
- }
-
- ///
- /// Try deserialize dictionary
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeDict(Type type, Type genericDefType, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out IDictionary ret)
- {
- if (genericDefType == ConstMgr.DictDefType)
- {
- ret = reader.ReadDictionary(type);
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- ret = null;
- return false;
- }
-
- ///
- /// Try deserialize enum
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeEnum(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out T obj)
- {
- obj = default;
- if (TypeModel.IsEnum(type))
- {
- reader.ReadEnum(ref obj);
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- return false;
- }
-
- ///
- /// Try deserialize enum
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeEnum(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out object obj)
- {
- if (TypeModel.IsEnum(type))
- {
- var underlyingType = Enum.GetUnderlyingType(type);
- var ret = reader.ReadEnum(underlyingType);
- obj = Enum.ToObject(type, ret);
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- obj = null;
- return false;
- }
-
- ///
- /// Try deserialize enum
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeUnmanagedType(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out T obj)
- {
- obj = default;
- if (TypeModel.IsUnmanaged(type))
- {
- reader.ReadAsUnmanaged(ref obj, Marshal.SizeOf(type));
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- return false;
- }
-
- ///
- /// Try deserialize enum
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryDeserializeUnmanagedType(Type type, Reader reader,
- [MarshalAs(UnmanagedType.U1)] bool returnDispose, out object obj)
- {
- obj = default;
- if (TypeModel.IsUnmanaged(type))
- {
- reader.ReadAsUnmanaged(ref obj, Marshal.SizeOf(type));
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- return false;
- }
-
- ///
- /// Check for null
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ReadNullCheck(Reader reader, [MarshalAs(UnmanagedType.U1)] bool returnDispose,
- out object obj)
- {
- obj = null;
- if (!reader.ReadBool()) // if null -> readBool will give false
- {
- if (returnDispose)
- {
- ObjectPool.Return(reader);
- }
-
- return true;
- }
-
- return false;
- }
-
- ///
- /// Set value from MemberInfo
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void SetMember(MemberInfo info, object instance, object val)
- {
- switch (info)
- {
- case FieldInfo fo:
- fo.SetValue(instance, val);
- break;
- case PropertyInfo po:
- po.SetValue(instance, val);
- break;
- default:
- return;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Enums/CompressOption.cs b/Nino_Unity/Assets/Nino/Serialization/Enums/CompressOption.cs
deleted file mode 100644
index 61ec116..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Enums/CompressOption.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace Nino.Serialization
-{
- ///
- /// Compress option
- /// 压缩类型
- ///
- public enum CompressOption : byte
- {
- ///
- /// zlib (gzip/deflate) compression (high compression ratio but low performance)
- /// zlib (gzip/deflate) 压缩模式 (高压缩率低性能)
- ///
- Zlib = 0,
-
- ///
- /// lz4 compression (average compression ration but high performance)
- /// lz4 压缩模式 (平均压缩率高性能)
- ///
- Lz4 = 1,
-
- ///
- /// no compression (very high performance but huge size)
- /// 无压缩 (高性能但体积很大)
- ///
- NoCompression = 2
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Interfaces/INinoWrapper.cs b/Nino_Unity/Assets/Nino/Serialization/Interfaces/INinoWrapper.cs
deleted file mode 100644
index e88bc93..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Interfaces/INinoWrapper.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Nino.Serialization
-{
- public interface INinoWrapper
- {
- void Serialize(T val, ref Writer writer);
- T Deserialize(Reader reader);
- int GetSize(T val);
- }
-
- public interface INinoWrapper
- {
- void Serialize(object val, ref Writer writer);
- object Deserialize(Reader reader);
- int GetSize(object val);
- }
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Nino.Serialization.asmdef b/Nino_Unity/Assets/Nino/Serialization/Nino.Serialization.asmdef
deleted file mode 100644
index 492dba4..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Nino.Serialization.asmdef
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "Nino.Serialization",
- "references": [
- "Nino.Shared",
- "ILRuntime"
- ],
- "includePlatforms": [],
- "excludePlatforms": [],
- "allowUnsafeCode": true,
- "overrideReferences": false,
- "precompiledReferences": [],
- "autoReferenced": true,
- "defineConstraints": [],
- "versionDefines": [],
- "noEngineReferences": true
-}
\ No newline at end of file
diff --git a/Nino_Unity/Assets/Nino/Serialization/Reader.Generic.cs b/Nino_Unity/Assets/Nino/Serialization/Reader.Generic.cs
deleted file mode 100644
index 03f8fac..0000000
--- a/Nino_Unity/Assets/Nino/Serialization/Reader.Generic.cs
+++ /dev/null
@@ -1,469 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace Nino.Serialization
-{
- ///
- /// Generic methods for reader (ILRuntime hotupdate requests wont access here)
- ///
- public unsafe partial class Reader
- {
- ///
- /// Read primitive value from binary writer, DO NOT USE THIS FOR CUSTOM EXPORTER
- /// Compress and write enum
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T ReadCommonVal() =>
- Deserializer.Deserialize(buffer.AsSpan(position, _length - position), this, false);
-
- ///
- /// Compress and write enum
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T ReadEnum()
- {
- T val = default;
- ReadEnum(ref val);
- return val;
- }
-
- ///
- /// Compress and write enum
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void ReadEnum(ref T val)
- {
- if (EndOfReader) return;
-
- switch (TypeModel.GetTypeCode(typeof(T)))
- {
- case TypeCode.Byte:
- Unsafe.As(ref val) = ReadByte();
- return;
- case TypeCode.SByte:
- Unsafe.As(ref val) = ReadSByte();
- return;
- case TypeCode.Int16:
- Unsafe.As(ref val) = ReadInt16();
- return;
- case TypeCode.UInt16:
- Unsafe.As(ref val) = ReadUInt16();
- return;
- case TypeCode.Int32:
- Unsafe.As(ref val) = ReadInt32();
- return;
- case TypeCode.UInt32:
- Unsafe.As(ref val) = ReadUInt32();
- return;
- case TypeCode.Int64:
- Unsafe.As(ref val) = ReadInt64();
- return;
- case TypeCode.UInt64:
- Unsafe.As(ref val) = ReadUInt64();
- return;
- }
- }
-
- ///
- /// Read unmanaged type
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T Read(int len) where T : unmanaged
- {
- if (EndOfReader)
- {
- return default;
- }
-
- var ret = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T)));
- position += len;
- return ret;
- }
-
- ///
- /// Read unmanaged type
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- // ReSharper disable UnusedMember.Local
- internal void ReadAsUnmanaged(ref T val, int len)
- // ReSharper restore UnusedMember.Local
- {
- if (EndOfReader)
- {
- return;
- }
-
- Span span = buffer.AsSpan(position, len);
- var first = span[0];
- val = Unsafe.ReadUnaligned(ref first);
- position += len;
- }
-
- ///
- /// Read unmanaged type
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- // ReSharper disable UnusedMember.Local
- public void Read(ref T val, int len) where T : unmanaged
- // ReSharper restore UnusedMember.Local
- {
- if (EndOfReader)
- {
- return;
- }
-
- val = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T)));
- position += len;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2) where T1 : unmanaged where T2 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3, int len3)
- where T1 : unmanaged where T2 : unmanaged where T3 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3, int len3,
- ref T4 val4, int len4) where T1 : unmanaged where T2 : unmanaged where T3 : unmanaged where T4 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- val4 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T4)));
- position += len4;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3, int len3,
- ref T4 val4, int len4, ref T5 val5, int len5) where T1 : unmanaged
- where T2 : unmanaged
- where T3 : unmanaged
- where T4 : unmanaged
- where T5 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- val4 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T4)));
- position += len4;
- val5 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T5)));
- position += len5;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3, int len3,
- ref T4 val4, int len4, ref T5 val5, int len5, ref T6 val6, int len6) where T1 : unmanaged
- where T2 : unmanaged
- where T3 : unmanaged
- where T4 : unmanaged
- where T5 : unmanaged
- where T6 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- val4 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T4)));
- position += len4;
- val5 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T5)));
- position += len5;
- val6 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T6)));
- position += len6;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3,
- int len3, ref T4 val4, int len4, ref T5 val5, int len5, ref T6 val6, int len6, ref T7 val7, int len7)
- where T1 : unmanaged
- where T2 : unmanaged
- where T3 : unmanaged
- where T4 : unmanaged
- where T5 : unmanaged
- where T6 : unmanaged
- where T7 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- val4 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T4)));
- position += len4;
- val5 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T5)));
- position += len5;
- val6 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T6)));
- position += len6;
- val7 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T7)));
- position += len7;
- }
-
- ///
- /// Read unmanaged type
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Read(ref T1 val1, int len1, ref T2 val2, int len2, ref T3 val3,
- int len3, ref T4 val4, int len4, ref T5 val5, int len5, ref T6 val6, int len6, ref T7 val7, int len7,
- ref T8 val8, int len8) where T1 : unmanaged
- where T2 : unmanaged
- where T3 : unmanaged
- where T4 : unmanaged
- where T5 : unmanaged
- where T6 : unmanaged
- where T7 : unmanaged
- where T8 : unmanaged
- {
- if (EndOfReader)
- {
- return;
- }
-
- val1 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T1)));
- position += len1;
- val2 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T2)));
- position += len2;
- val3 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T3)));
- position += len3;
- val4 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T4)));
- position += len4;
- val5 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T5)));
- position += len5;
- val6 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T6)));
- position += len6;
- val7 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T7)));
- position += len7;
- val8 = MemoryMarshal.Read(buffer.AsSpan(position, sizeof(T8)));
- position += len8;
- }
-
- ///
- /// Read nullable
- ///
- ///
- ///
- public T? ReadNullable() where T : struct
- {
- if (!ReadBool())
- {
- return null;
- }
-
- return ReadCommonVal();
- }
-
-
- ///
- /// Read Array
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T[] ReadArray()
- {
- if (EndOfReader) return default;
- //check null
- if (!ReadBool()) return null;
-
- //read len
- int len = ReadLength();
-
- T[] arr = new T[len];
- //read item
- int i = 0;
- while (i < len)
- {
- arr[i++] = ReadCommonVal