diff --git a/src/Luban.Job.Cfg/Luban.Job.Cfg.csproj b/src/Luban.Job.Cfg/Luban.Job.Cfg.csproj
index c5938b0..5bb10fb 100644
--- a/src/Luban.Job.Cfg/Luban.Job.Cfg.csproj
+++ b/src/Luban.Job.Cfg/Luban.Job.Cfg.csproj
@@ -16,7 +16,8 @@
-
+
+
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs
index 19e4857..139da83 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs
@@ -88,8 +88,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DText type, ByteBuf x)
{
x.WriteString(type.Key);
- var ass = DefAssembly.LocalAssebmly;
- x.WriteString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
+ x.WriteString(type.TextOfCurrentAssembly);
}
public void Accept(DBean type, ByteBuf x)
@@ -180,7 +179,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, ByteBuf x)
{
- x.WriteInt(type.GetUnixTime(DefAssembly.LocalAssebmly.TimeZone));
+ x.WriteInt(type.UnixTimeOfCurrentAssembly);
}
}
}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
index faa8d04..2a16dd3 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
@@ -93,8 +93,7 @@ namespace Luban.Job.Cfg.DataExporters
x.WritePropertyName(DText.KEY_NAME);
x.WriteStringValue(type.Key);
x.WritePropertyName(DText.TEXT_NAME);
- var ass = DefAssembly.LocalAssebmly;
- x.WriteStringValue(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
+ x.WriteStringValue(type.TextOfCurrentAssembly);
x.WriteEndObject();
}
@@ -196,7 +195,7 @@ namespace Luban.Job.Cfg.DataExporters
public virtual void Accept(DDateTime type, Utf8JsonWriter x)
{
- x.WriteNumberValue(type.GetUnixTime(DefAssembly.LocalAssebmly.TimeZone));
+ x.WriteNumberValue(type.UnixTimeOfCurrentAssembly);
}
}
}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs
new file mode 100644
index 0000000..456a565
--- /dev/null
+++ b/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs
@@ -0,0 +1,239 @@
+using Luban.Job.Cfg.Datas;
+using Luban.Job.Cfg.DataSources;
+using Luban.Job.Cfg.DataVisitors;
+using Luban.Job.Cfg.Defs;
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Luban.Job.Cfg.DataExporters
+{
+
+ class MsgPackExportor
+ {
+ public static MsgPackExportor Ins { get; } = new();
+
+
+ public void WriteList(DefTable table, List records, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(records.Count);
+ foreach (var record in records)
+ {
+ Accept(record.Data, ref writer);
+ }
+ }
+
+ public void Apply(DType type, ref MessagePackWriter writer)
+ {
+ switch (type)
+ {
+ case DInt x: Accept(x, ref writer); break;
+ case DString x: Accept(x, ref writer); break;
+ case DFloat x: Accept(x, ref writer); break;
+ case DBean x: Accept(x, ref writer); break;
+ case DBool x: Accept(x, ref writer); break;
+ case DEnum x: Accept(x, ref writer); break;
+ case DList x: Accept(x, ref writer); break;
+ case DArray x: Accept(x, ref writer); break;
+ case DLong x: Accept(x, ref writer); break;
+ case DDateTime x: Accept(x, ref writer); break;
+ case DMap x: Accept(x, ref writer); break;
+ case DText x: Accept(x, ref writer); break;
+ case DVector2 x: Accept(x, ref writer); break;
+ case DVector3 x: Accept(x, ref writer); break;
+ case DVector4 x: Accept(x, ref writer); break;
+ case DByte x: Accept(x, ref writer); break;
+ case DDouble x: Accept(x, ref writer); break;
+ case DFint x: Accept(x, ref writer); break;
+ case DFlong x: Accept(x, ref writer); break;
+ case DFshort x: Accept(x, ref writer); break;
+ case DSet x: Accept(x, ref writer); break;
+ case DShort x: Accept(x, ref writer); break;
+ default: throw new NotSupportedException($"DType:{type.GetType().FullName} not support");
+ }
+ }
+
+ public void Accept(DBool type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DByte type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DShort type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DFshort type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DInt type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DFint type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DLong type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DFlong type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DFloat type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DDouble type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DEnum type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DString type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DText type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(2);
+ writer.Write(type.Key);
+ writer.Write(type.TextOfCurrentAssembly);
+ }
+
+ public void Accept(DBytes type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.Value);
+ }
+
+ public void Accept(DVector2 type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(2);
+ writer.Write(type.Value.X);
+ writer.Write(type.Value.Y);
+ }
+
+ public void Accept(DVector3 type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(3);
+ writer.Write(type.Value.X);
+ writer.Write(type.Value.Y);
+ writer.Write(type.Value.Z);
+ }
+
+ public void Accept(DVector4 type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(4);
+ writer.Write(type.Value.X);
+ writer.Write(type.Value.Y);
+ writer.Write(type.Value.Z);
+ writer.Write(type.Value.W);
+ }
+
+ public void Accept(DDateTime type, ref MessagePackWriter writer)
+ {
+ writer.Write(type.UnixTimeOfCurrentAssembly);
+ }
+
+ public void Accept(DBean type, ref MessagePackWriter writer)
+ {
+ var implType = type.ImplType;
+ var hierarchyFields = implType.HierarchyFields;
+ int exportCount = 0;
+ {
+ if (type.Type.IsAbstractType)
+ {
+ exportCount++;
+ }
+ int idx = 0;
+ foreach (var field in type.Fields)
+ {
+ var defField = (DefField)hierarchyFields[idx++];
+ if (field == null || !defField.NeedExport)
+ {
+ continue;
+ }
+ ++exportCount;
+ }
+ }
+
+ writer.WriteMapHeader(exportCount);
+ if (type.Type.IsAbstractType)
+ {
+ writer.Write(DefBean.TYPE_NAME_KEY);
+ writer.Write(type.ImplType.Name);
+ }
+
+ int index = 0;
+ foreach (var field in type.Fields)
+ {
+ var defField = (DefField)hierarchyFields[index++];
+ if (field == null || !defField.NeedExport)
+ {
+ continue;
+ }
+ writer.Write(defField.Name);
+ Apply(field, ref writer);
+ }
+ }
+
+ public void Accept(DArray type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(type.Datas.Count);
+ foreach (var d in type.Datas)
+ {
+ Apply(d, ref writer);
+ }
+ }
+
+ public void Accept(DList type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(type.Datas.Count);
+ foreach (var d in type.Datas)
+ {
+ Apply(d, ref writer);
+ }
+ }
+
+ public void Accept(DSet type, ref MessagePackWriter writer)
+ {
+ writer.WriteArrayHeader(type.Datas.Count);
+ foreach (var d in type.Datas)
+ {
+ Apply(d, ref writer);
+ }
+ }
+
+ public void Accept(DMap type, ref MessagePackWriter writer)
+ {
+ writer.WriteMapHeader(type.Datas.Count);
+ foreach (var d in type.Datas)
+ {
+ Apply(d.Key, ref writer);
+ Apply(d.Value, ref writer);
+ }
+ }
+ }
+}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs
index 1b884fa..6826867 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs
@@ -87,7 +87,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, CodedOutputStream x)
{
- x.WriteInt32(type.GetUnixTime(DefAssembly.LocalAssebmly.TimeZone));
+ x.WriteInt32(type.UnixTimeOfCurrentAssembly);
}
public void Accept(DString type, CodedOutputStream x)
@@ -104,12 +104,12 @@ namespace Luban.Job.Cfg.DataExporters
{
// 此处与 binary格式不同. binary格式还包含了key
// 意味pb格式是无法支持动态本土化的。
- var ass = DefAssembly.LocalAssebmly;
- x.WriteString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
+ x.WriteString(type.TextOfCurrentAssembly);
}
private MemoryStream AllocMemoryStream()
{
+ // TODO 优化
return new MemoryStream();
}
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToErlangLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToErlangLiteralVisitor.cs
index e930187..70898f6 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToErlangLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToErlangLiteralVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
- var ass = DefAssembly.LocalAssebmly;
- return $"#{{{DText.KEY_NAME}=>\"{type.Key}\",{DText.TEXT_NAME}=>\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
+ return $"#{{{DText.KEY_NAME}=>\"{type.Key}\",{DText.TEXT_NAME}=>\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
}
public override string Accept(DBean type)
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs
index a5c61ee..23b5e7c 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
- var ass = DefAssembly.LocalAssebmly;
- return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
+ return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
}
public override string Accept(DBean type)
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToLiteralVisitorBase.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToLiteralVisitorBase.cs
index e0abaa0..88767e0 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToLiteralVisitorBase.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToLiteralVisitorBase.cs
@@ -92,8 +92,7 @@ namespace Luban.Job.Cfg.DataVisitors
public virtual string Accept(DDateTime type)
{
- var ass = DefAssembly.LocalAssebmly;
- return type.GetUnixTime(ass.TimeZone).ToString();
+ return type.UnixTimeOfCurrentAssembly.ToString();
}
}
}
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
index 47b0dd9..45be349 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
- var ass = DefAssembly.LocalAssebmly;
- return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}=\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
+ return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}=\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
}
public override string Accept(DBean type)
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs
index 7db072d..e332dec 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
- var ass = DefAssembly.LocalAssebmly;
- return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
+ return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
}
public override string Accept(DBean type)
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs
index da74d4f..ed6da09 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
#if !LUBAN_LITE
- var ass = DefAssembly.LocalAssebmly;
- return $"\"{type.Key}#{type.GetText(ass.ExportTextTable, ass.NotConvertTextSet)}\"";
+ return $"\"{type.Key}#{type.TextOfCurrentAssembly}\"";
#else
return $"\"{type.Key}#{type.RawValue}\"";
#endif
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToXmlLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToXmlLiteralVisitor.cs
index ba00de1..648ca00 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToXmlLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToXmlLiteralVisitor.cs
@@ -12,8 +12,7 @@ namespace Luban.Job.Cfg.DataVisitors
public override string Accept(DText type)
{
- var ass = DefAssembly.LocalAssebmly;
- return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}='{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}'}}";
+ return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}='{DataUtil.EscapeString(type.TextOfCurrentAssembly)}'}}";
}
public override string Accept(DBean type)
diff --git a/src/Luban.Job.Cfg/Source/Datas/DDateTime.cs b/src/Luban.Job.Cfg/Source/Datas/DDateTime.cs
index be3050c..ecddf6e 100644
--- a/src/Luban.Job.Cfg/Source/Datas/DDateTime.cs
+++ b/src/Luban.Job.Cfg/Source/Datas/DDateTime.cs
@@ -1,5 +1,6 @@
using Luban.Common.Utils;
using Luban.Job.Cfg.DataVisitors;
+using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.Utils;
using System;
@@ -60,6 +61,8 @@ namespace Luban.Job.Cfg.Datas
}
}
+ public int UnixTimeOfCurrentAssembly => GetUnixTime(DefAssembly.LocalAssebmly.TimeZone);
+
public override void Apply(IDataActionVisitor visitor, T x)
{
visitor.Accept(this, x);
diff --git a/src/Luban.Job.Cfg/Source/Datas/DText.cs b/src/Luban.Job.Cfg/Source/Datas/DText.cs
index 036adb3..f2712c2 100644
--- a/src/Luban.Job.Cfg/Source/Datas/DText.cs
+++ b/src/Luban.Job.Cfg/Source/Datas/DText.cs
@@ -1,4 +1,5 @@
using Luban.Job.Cfg.DataVisitors;
+using Luban.Job.Cfg.Defs;
#if !LUBAN_LITE
using Luban.Job.Cfg.l10n;
#endif
@@ -40,6 +41,15 @@ namespace Luban.Job.Cfg.Datas
}
return _rawValue;
}
+
+ public string TextOfCurrentAssembly
+ {
+ get
+ {
+ var ass = DefAssembly.LocalAssebmly;
+ return GetText(ass.ExportTextTable, ass.NotConvertTextSet);
+ }
+ }
#endif
public override void Apply(IDataActionVisitor visitor, T x)
diff --git a/src/Luban.Job.Cfg/Source/Generate/DataScatterRender.cs b/src/Luban.Job.Cfg/Source/Generate/DataScatterRender.cs
index 97cae29..c43df0d 100644
--- a/src/Luban.Job.Cfg/Source/Generate/DataScatterRender.cs
+++ b/src/Luban.Job.Cfg/Source/Generate/DataScatterRender.cs
@@ -14,6 +14,8 @@ namespace Luban.Job.Cfg.Generate
[Render("data_xml")]
[Render("data_yaml")]
[Render("data_protobuf")]
+ [Render("data_msgpack")]
+ [Render("data_flatbuffers")]
class DataScatterRender : DataRenderBase
{
public override void Render(GenContext ctx)
diff --git a/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs b/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs
index 916a934..19ab4e0 100644
--- a/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs
+++ b/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs
@@ -18,12 +18,6 @@ namespace Luban.Job.Cfg.Utils
return type.Apply(IsSimpleLiteralDataVisitor2.Ins);
}
- public static string ToLocalizedText(DText type)
- {
- var ass = DefAssembly.LocalAssebmly;
- return type.GetText(ass.ExportTextTable, ass.NotConvertTextSet);
- }
-
public static DType GetField(DBean bean, string fieldName)
{
int index = 0;
diff --git a/src/Luban.Job.Cfg/Source/Utils/DataExporterUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataExporterUtil.cs
index 726b9e2..7f35f8d 100644
--- a/src/Luban.Job.Cfg/Source/Utils/DataExporterUtil.cs
+++ b/src/Luban.Job.Cfg/Source/Utils/DataExporterUtil.cs
@@ -9,6 +9,7 @@ using Luban.Job.Cfg.l10n;
using Luban.Job.Cfg.RawDefs;
using Luban.Job.Common.Tpl;
using Luban.Job.Common.Utils;
+using MessagePack;
using Scriban;
using System;
using System.Collections.Generic;
@@ -98,6 +99,14 @@ namespace Luban.Job.Cfg.Utils
ProtobufExportor.Ins.WriteList(table, records, ms);
return DataUtil.StreamToBytes(ms);
}
+ case "data_msgpack":
+ {
+ var ms = new System.Buffers.ArrayBufferWriter();
+ var writer = new MessagePackWriter(ms);
+ MsgPackExportor.Ins.WriteList(table, records, ref writer);
+ writer.Flush();
+ return ms.WrittenSpan.ToArray();
+ }
//case "data_erlang":
//{
// var content = new StringBuilder();
diff --git a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs
index 987eb4f..9820cf8 100644
--- a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs
+++ b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs
@@ -118,6 +118,8 @@ namespace Luban.Job.Common.Utils
{ "erl", "erl" },
{ "xlsx", "xlsx" },
{ "protobuf", "bytes" },
+ { "msgpack", "bytes" },
+ { "flatbuffers", "bytes" },
};
public static string GetOutputFileSuffix(string genType)