Skip to content

Commit

Permalink
release v3.0.0
Browse files Browse the repository at this point in the history
## Nino.Serialization v3.0.0
- [Optimization] Significantly faster serialization/deserialization
- [Optimization] Reduce serialized binary size for string/collection/nullable
- [Feat] Support serialize user-defined string in UTF-8
- [Feat] Officially support cross-project referencing/inheriting \`NinoType\`s
  • Loading branch information
JasonXuDeveloper committed Nov 12, 2024
1 parent be03d49 commit 36b8a4e
Show file tree
Hide file tree
Showing 55 changed files with 1,867 additions and 434 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ jobs:
run: dotnet build --no-restore --configuration Release

# Copy src/Nino/bin/Release/netstandard2.1/Nino.Core.dll and src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll
# to Nino_Unity/Assets/Test/Nino, replace existing files
# to Nino_Unity/Assets/Test/Nino and Nino_Unity/Assets/Test/Editor/Nino, replace existing files
- name: Copy DLLs
run: cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Core.dll ./Nino_Unity/Assets/Test/Nino/Nino.Core.dll && cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll ./Nino_Unity/Assets/Test/Nino/Nino.Generator.dll
run: |
cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Core.dll ./Nino_Unity/Assets/Test/Nino/Nino.Core.dll && cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll ./Nino_Unity/Assets/Test/Nino/Nino.Generator.dll
cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Core.dll ./Nino_Unity/Assets/Test/Editor/Nino/Nino.Core.dll && cp -f ./src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll ./Nino_Unity/Assets/Test/Editor/Nino/Nino.Generator.dll
# Install the packager. We are putting it outside the working directory so we dont include it by mistake
- name: Install Unity Packager
Expand All @@ -145,12 +147,12 @@ jobs:
echo "Creating package ${{env.package_path}}"
dotnet ../tools/UnityPackageExporter.dll ./Nino_Unity ./Nino.unitypackage --assets "Assets/Test/Nino/**.*"
# Commit the changes (only the 2 dlls and the unitypackage)
# Commit the changes (only the 4 dlls and the unitypackage)
- name: Commit Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./Nino.unitypackage ./Nino_Unity/Assets/Test/Nino/Nino.Core.dll ./Nino_Unity/Assets/Test/Nino/Nino.Generator.dll
git add ./Nino.unitypackage ./Nino_Unity/Assets/Test/Nino/Nino.Core.dll ./Nino_Unity/Assets/Test/Nino/Nino.Generator.dll ./Nino_Unity/Assets/Test/Editor/Nino/Nino.Core.dll ./Nino_Unity/Assets/Test/Editor/Nino/Nino.Generator.dll
git commit -m "Bump Unity Package to v$VERSION"
git push origin main
Expand Down
2 changes: 1 addition & 1 deletion Nino_Unity/Assets/Test/BuildTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using MongoDB.Bson.Serialization;
using UnityEngine.SceneManagement;
using System.Runtime.Serialization.Formatters.Binary;
using Test_Nino;
using Test.NinoGen;
using Debug = UnityEngine.Debug;

namespace Nino.Test
Expand Down
2 changes: 1 addition & 1 deletion Nino_Unity/Assets/Test/BuildTest2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using MongoDB.Bson.Serialization;
using UnityEngine.SceneManagement;
using System.Runtime.Serialization.Formatters.Binary;
using Test_Nino;
using Test.NinoGen;
using Debug = UnityEngine.Debug;


Expand Down
321 changes: 321 additions & 0 deletions Nino_Unity/Assets/Test/Editor/Data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
using System;
using ProtoBuf;
using System.Linq;
using UnityEngine;
using MessagePack;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Options;
using Nino.Core;

namespace Nino.Test
{
[NinoType()]
public class CollectionTest
{
[NinoMember(0)] public List<int> a = new List<int>();
[NinoMember(1)] public List<string> b = new List<string>();
[NinoMember(2)] public Dictionary<int, bool> c = new Dictionary<int, bool>();
[NinoMember(3)] public Dictionary<string, bool> d = new Dictionary<string, bool>();
[NinoMember(4)] public Dictionary<byte, string> e = new Dictionary<byte, string>();
}

[NinoType]
public class ComplexData
{
[NinoMember(0)]
public int[][] a;
[NinoMember(1)]
public List<int[]> b;
[NinoMember(2)]
public List<int>[] c;
[NinoMember(3)]
public Dictionary<string,Dictionary<string, int>> d;
[NinoMember(4)]
public Dictionary<string,Dictionary<string, int[][]>>[] e;
[NinoMember(5)]
public Data[][] f;
[NinoMember(6)]
public List<Data[]> g;
[NinoMember(7)]
public Data[][][] h;
[NinoMember(8)]
public List<Data>[] i;
[NinoMember(9)]
public List<Data[]>[] j;
public override string ToString()
{
return $"{string.Join(",", a.SelectMany(x => x).ToArray())},\n" +
$"{string.Join(",", b.SelectMany(x => x).ToArray())},\n" +
$"{string.Join(",", c.SelectMany(x => x).ToArray())},\n" +
$"{GetDictString(d)},\n" +
$"{string.Join(",\n", e.Select(GetDictString).ToArray())}\n" +
$"{string.Join(",\n", f.SelectMany(x => x).Select(x => x))}\n" +
$"{string.Join(",\n", g.SelectMany(x => x).Select(x => x))}\n" +
$"{string.Join(",\n", h.SelectMany(x => x).SelectMany(x => x).Select(x => x))}\n" +
$"{string.Join(",\n", i.SelectMany(x => x).Select(x => x))}\n" +
$"{string.Join(",\n", j.SelectMany(x => x).Select(x => x).SelectMany(x => x).Select(x => x))}\n";
}

private string GetDictString<K,V>(Dictionary<K,Dictionary<K,V>> ddd)
{
return $"{string.Join(",", ddd.Keys.ToList())},\n" +
$" {string.Join(",", ddd.Values.ToList().SelectMany(k=>k.Keys))},\n" +
$" {string.Join(",", ddd.Values.ToList().SelectMany(k=>k.Values))}";
}
}

[Serializable]
[ProtoContract]
[NinoType]
[MessagePackObject]
public struct Data
{
[ProtoMember(1)] [NinoMember(1)] [BsonElement] [Key(1)]
public int x;

[ProtoMember(2)] [NinoMember(2)] [BsonElement] [Key(2)]
public short y;

[ProtoMember(3)] [NinoMember(3)] [BsonElement] [Key(3)]
public long z;

[ProtoMember(4)] [NinoMember(4)] [BsonElement] [Key(4)]
public float f;

[ProtoMember(5)] [NinoMember(5)] [BsonElement] [Key(5)]
public decimal d;

[ProtoMember(6)] [NinoMember(6)] [BsonElement] [Key(6)]
public double db;

[ProtoMember(7)] [NinoMember(7)] [BsonElement] [Key(7)]
public bool bo;

[ProtoMember(8)] [NinoMember(8)] [BsonElement] [Key(8)]
public TestEnum en;

public override string ToString()
{
return $"{x},{y},{z},{f},{d},{db},{bo},{en}";
}
}

[Serializable]
[ProtoContract]
public enum TestEnum : byte
{
A = 1,
B = 2
}

[Serializable]
[ProtoContract]
[NinoType]
[MessagePackObject]
public class NestedData
{
[ProtoMember(1)] [NinoMember(1)] [BsonElement] [Key(1)]
public string name;

[ProtoMember(2)] [NinoMember(2)] [BsonElement] [Key(2)]
public Data[] ps;

public override string ToString()
{
return $"{name},{ps[0]}";
}
}

[Serializable]
[ProtoContract]
[NinoType]
public class NestedData2
{
[ProtoMember(1)] [NinoMember(1)] public string name;

[ProtoMember(2)] [NinoMember(2)] public Data[] ps;

[ProtoMember(3)] [NinoMember(3)] public List<int> vs;

public override string ToString()
{
return $"{name},{string.Join(",", vs)},{ps[0]}";
}
}

[NinoType(false)]
public class PrimitiveTypeTest
{
[NinoMember(1)] public Vector3 v3;

[NinoMember(2)] private DateTime dt = DateTime.Now;

[NinoMember(3)] public int? ni { get; set; }

[NinoMember(4)] public List<Quaternion> qs;

[NinoMember(5)] public Matrix4x4 m;

[NinoMember(6)] public Dictionary<string, int> dict;

[NinoMember(7)] public Dictionary<string, Data> dict2;

public override string ToString()
{
return
$"{v3}, {dt}, {ni}, {String.Join(",", qs)}, {m.ToString()}\n" +
$"dict.keys: {string.Join(",", dict.Keys)},\ndict.values:{string.Join(",", dict.Values)}\n" +
$"dict2.keys: {string.Join(",", dict2.Keys)},\ndict2.values:{string.Join(",", dict2.Values)}\n";
}
}

[NinoType]
public class IncludeAllClassCodeGen
{
public int a;
public long b;
public float c;
public double d;

public override string ToString()
{
return $"{a}, {b}, {c}, {d}";
}
}

[Serializable]
[ProtoContract]
[NinoType]
[MessagePackObject]
public class NotIncludeAllClass
{
[ProtoMember(10)] [BsonElement] [Key(0)] [NinoMember(0)]
public int a;

[ProtoMember(1)] [BsonElement] [Key(1)] [NinoMember(1)]
public long b;

[ProtoMember(2)] [BsonElement] [Key(2)] [NinoMember(2)]
public float c;

[ProtoMember(3)] [BsonElement] [Key(3)] [NinoMember(3)]
public double d;

public override string ToString()
{
return $"{a}, {b}, {c}, {d}";
}
}

[Serializable]
[ProtoContract]
[NinoType]
[MessagePackObject]
public class BuildTestDataCodeGen
{
[ProtoMember(100)] [BsonElement] [Key(0)] [NinoMember(0)]
public byte a;

[ProtoMember(1)] [BsonElement] [Key(1)] [NinoMember(1)]
public sbyte b;

[ProtoMember(2)] [BsonElement] [Key(2)] [NinoMember(2)]
public short c;

[ProtoMember(3)] [BsonElement] [Key(3)] [NinoMember(3)]
public ushort d;

[ProtoMember(4)] [BsonElement] [Key(4)] [NinoMember(4)]
public int e;

[ProtoMember(5)] [BsonElement] [Key(5)] [NinoMember(5)]
public uint f;

[ProtoMember(6)] [BsonElement] [Key(6)] [NinoMember(6)]
public long g;

[ProtoMember(7)] [BsonElement] [Key(7)] [NinoMember(7)]
public ulong h;

[ProtoMember(8)] [BsonElement] [Key(8)] [NinoMember(8)]
public float i;

[ProtoMember(9)] [BsonElement] [Key(9)] [NinoMember(9)]
public double j;

[ProtoMember(10)] [BsonElement] [Key(10)] [NinoMember(10)]
public decimal k;

[ProtoMember(11)] [BsonElement] [Key(11)] [NinoMember(11)]
public bool l;

[ProtoMember(12)] [BsonElement] [Key(12)] [NinoMember(12)]
public char m;

[ProtoMember(13)] [BsonElement] [Key(13)] [NinoMember(13)]
public string n;

[ProtoMember(14)] [BsonElement] [Key(14)] [NinoMember(14)]
public List<int> o = new List<int>();

[ProtoMember(15)] [BsonElement] [Key(15)] [NinoMember(15)]
public List<NotIncludeAllClass> p = new List<NotIncludeAllClass>();

[ProtoMember(16)] [BsonElement] [Key(16)] [NinoMember(16)]
public byte[] q = Array.Empty<byte>();

[ProtoMember(17)] [BsonElement] [Key(17)] [NinoMember(17)]
public NotIncludeAllClass[] r = Array.Empty<NotIncludeAllClass>();

[Key(18)]
[NinoMember(18)]
#if !IL2CPP || UNITY_EDITOR
[ProtoMember(18)]
[BsonElement]
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
#endif
public Dictionary<string, NotIncludeAllClass> s = new Dictionary<string, NotIncludeAllClass>();

[Key(19)]
[NinoMember(19)]

#if !IL2CPP || UNITY_EDITOR
[ProtoMember(19)]
[BsonElement]
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
#endif
public Dictionary<NotIncludeAllClass, int> t = new Dictionary<NotIncludeAllClass, int>();

[Key(20)]
[NinoMember(20)]

#if !IL2CPP || UNITY_EDITOR
[ProtoMember(20)]
[BsonElement]
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
#endif
public Dictionary<string, int> u = new Dictionary<string, int>();

[Key(21)]
[NinoMember(21)]

#if !IL2CPP || UNITY_EDITOR
[ProtoMember(21)]
[BsonElement]
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
#endif
public Dictionary<NotIncludeAllClass, NotIncludeAllClass> v =
new Dictionary<NotIncludeAllClass, NotIncludeAllClass>();

public override string ToString()
{
return $"{a},{b},{c},{d},{e},{f},{g},{h},{i},{j},{k},{l},{m},{n},{string.Join("/", o)}," +
$"{string.Join("/", p)},{string.Join("/", q)},{string.Join("/", r.ToList())}," +
$"{string.Join("/", s.Keys.ToList())}-{string.Join("/", s.Values.ToList())}," +
$"{string.Join("/", t.Keys.ToList())}-{string.Join("/", t.Values.ToList())}," +
$"{string.Join("/", u.Keys.ToList())}-{string.Join("/", v.Values.ToList())}," +
$"{string.Join("/", v.Keys.ToList())}-{string.Join("/", v.Values.ToList())}";
}
}
}
3 changes: 3 additions & 0 deletions Nino_Unity/Assets/Test/Editor/Data.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 36b8a4e

Please sign in to comment.