【重构】将scriban模板字符串从代码中移到Templates目录
parent
ea9830b1c4
commit
6309108da0
11
README.md
11
README.md
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
## 介绍
|
||||
|
||||
luban是一个通用型对象生成与缓存方案, 在此基础上实现了一个功能**完备强大灵活易用**的**游戏配置解决方案**。
|
||||
luban是[BrightDB](https://github.com/focus-creative-games/BrightDB)的附属项目,一个通用型对象生成与缓存工具, 在此基础上实现了一个功能**完备强大灵活易用**的**游戏配置解决方案**。
|
||||
|
||||
luban基于 **meta定义 + 数据源** 的设计,实现了**完备的类型系统**,增强了excel格式,同时提供json、xml、lua、yaml等丰富的数据源支持。既可以处理常规的简单配置,也能完美处理**AI、技能、副本**等复杂配置,真正实现了统一数据定义、加载、检验、数据导出及代码生成的游戏配置工作流,彻底解决了中大型项目中需要程序员手动处理复杂配置的问题。
|
||||
luban基于 **meta定义 + 数据源** 的设计,实现了**完备的类型系统**,增强了excel格式,同时提供json、xml、lua、yaml等丰富的数据源支持。既可以处理常规的简单配置,也能完美处理**AI、技能、副本**等复杂配置,真正实现了统一数据定义、加载、检验、数据导出及代码生成的游戏配置工作流。比较好解决了中大型项目中策划难以实时检查复杂配置错误而与程序反复迭代编辑的问题,以及复杂的AI、技能等配置数据无法与excel配置统一,需要程序员单独处理的问题。
|
||||
|
||||
**luban功能极为丰富,支持游戏行业几乎所有主流的前后端语言和客户端引擎**。luban目前由专业团队维护,保持活跃的特性更新及功能优化,并有研发人员及时提供开发指导和跟进反馈。
|
||||
**luban功能较为完善,支持游戏行业几乎所有主流的前后端语言和客户端引擎**。luban目前由专业团队维护,保持活跃的特性更新及功能优化,并有研发人员及时提供开发指导和跟进反馈。
|
||||
|
||||
Luban适合有以下需求的开发者:
|
||||
- 希望找一个功能完备经受过上线项目检验的满足**中大型**游戏项目配置需求的游戏配置解决方案
|
||||
|
|
@ -52,7 +52,7 @@ Luban适合有以下需求的开发者:
|
|||
## 特性
|
||||
- 支持excel族、json、xml、lua、yaml 多种数据格式,基本统一了游戏常见的配置数据
|
||||
- **强大完备的类型系统**。**可以优雅表达任意复杂的数据结构**。支持所有常见原生类型、datetime类型、容器类型list,set,map、枚举和结构、**多态结构**以及**可空类型**。
|
||||
- 支持增强的excel格式。可以在excel里比较简洁填写出任意复杂的数据,就算只用excel,也能比较简洁自然地配出技能、AI之类的复杂数据。
|
||||
- 支持增强的excel格式。可以在excel里比较简洁填写出非常复杂的数据(比如顶层字段包含"list,A"类型字段, 而A是结构并且其中又包含"list,B"类型字段,B也是结构并且包含"list,C"这样的字段...)。
|
||||
- 生成代码清晰易读、良好模块化。特地支持运行时原子性热更新配置。
|
||||
- 使用云生成模式。生成极快,MMORPG这样大型项目也能秒内生成。日常增量生成基本在300ms以内。节省迭代时间。支持watch监测模式,数据目录变化立即重新生成。
|
||||
- 灵活的数据源定义。一个表可以来自多个文件或者一个文件内定义多个表或者一个目录下所有文件甚至来自云表格,以及以上的组合
|
||||
|
|
@ -62,8 +62,9 @@ Luban适合有以下需求的开发者:
|
|||
- 强大的数据校验能力。支持内建数据格式检查;支持ref表引用检查(策划不用担心填错id);支持path资源检查(策划不用担心填错资源路径);支持range检查
|
||||
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了
|
||||
- 支持多种常见数据表模式。 one(单例表)、map(常规key-value表)
|
||||
- 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力
|
||||
- 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等)
|
||||
- 统一了自定义编辑器的配置数据。与Unity和UE4的自定义编辑器良好配合,为编辑器生成合适的加载与保存json配置的的c#(Unity)或c++(UE4)代码。保存的json配置能够被luban识别和处理。
|
||||
- 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力
|
||||
- **本地化支持**
|
||||
- 支持时间本地化。datetime类型数据会根据指定的timezone,转换为目标地区该时刻的UTC时间,方便程序使用。
|
||||
- 支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。绝大多数的业务功能不再需要运行根据本地化id去查找文本的内容,简化程序员的工作。
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ namespace Luban.Client.Common.Utils
|
|||
lock (_lock)
|
||||
{
|
||||
_dirty = true;
|
||||
_cacheFileMetas.Add(meta.FullPath, meta);
|
||||
_cacheFileMetas[meta.FullPath] = meta;
|
||||
}
|
||||
s_logger.Debug("[add] meta not find, build it. file:{file} path:{path} md5:{md5} length:{length}", file, meta.FullPath, meta.Md5, meta.FileLength);
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ namespace Luban.Client.Common.Utils
|
|||
lock (_lock)
|
||||
{
|
||||
_dirty = true;
|
||||
_cacheFileMetas.Add(meta.FullPath, meta);
|
||||
_cacheFileMetas[meta.FullPath] = meta;
|
||||
}
|
||||
s_logger.Debug("[add] meta not find, create it. file:{file} path:{path} md5:{md5} length:{length}", outputPath, meta.FullPath, meta.Md5, meta.FileLength);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,79 +28,8 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{x.cpp_namespace_begin}}
|
||||
|
||||
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
class {{name}} : public {{if parent_def_type}} {{parent_def_type.cpp_full_name}} {{else}} bright::CfgBean {{end}}
|
||||
{
|
||||
public:
|
||||
|
||||
static bool deserialize{{name}}(ByteBuf& _buf, ::bright::SharedPtr<{{name}}>& _out);
|
||||
|
||||
{{name}}()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
{{~if !hierarchy_export_fields.empty?~}}
|
||||
{{name}}({{- for field in hierarchy_export_fields }}{{cpp_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
||||
{{~if parent_def_type~}}
|
||||
: {{parent_def_type.cpp_full_name}}({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}})
|
||||
{{~end~}}
|
||||
{
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
this->{{field.cpp_style_name}} = {{field.name}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
virtual ~{{name}}() {}
|
||||
|
||||
bool deserialize(ByteBuf& _buf);
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}} {{field.cpp_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
::bright::HashMap<{{cpp_define_type field.index_field.ctype}}, {{cpp_define_type field.ctype.element_type}}> {{field.cpp_style_name}}_Index;
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.cpp_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
static constexpr int ID = {{x.id}};
|
||||
|
||||
int getTypeId() const { return ID; }
|
||||
{{~end~}}
|
||||
|
||||
virtual void resolve(::bright::HashMap<::bright::String, void*>& _tables);
|
||||
};
|
||||
|
||||
{{x.cpp_namespace_end}}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -108,102 +37,8 @@ class {{name}} : public {{if parent_def_type}} {{parent_def_type.cpp_full_name}}
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{x.cpp_namespace_begin}}
|
||||
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private:
|
||||
::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}> _dataMap;
|
||||
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
|
||||
|
||||
public:
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
for(; n > 0 ; --n)
|
||||
{
|
||||
{{cpp_define_type value_type}} _v;
|
||||
{{cpp_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.push_back(_v);
|
||||
_dataMap[_v->{{x.index_field.cpp_style_name}}] = _v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const ::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}>& getDataMap() const { return _dataMap; }
|
||||
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
|
||||
|
||||
{{value_type.bean.cpp_full_name}}* getRaw({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
|
||||
{{cpp_define_type value_type}} get({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
for(auto v : _dataList)
|
||||
{
|
||||
v->resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private:
|
||||
{{cpp_define_type value_type}} _data;
|
||||
|
||||
public:
|
||||
{{cpp_define_type value_type}} data() const { return _data; }
|
||||
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
if (n != 1) return false;
|
||||
{{cpp_deserialize '_buf' '_data' value_type}}
|
||||
return true;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
_data->resolve(_tables);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}}& {{field.cpp_getter_name}}() const { return _data->{{field.cpp_style_name}}; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
};
|
||||
{{x.cpp_namespace_end}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -211,45 +46,12 @@ class {{name}}
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
class {{name}}
|
||||
{
|
||||
public:
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{table.cpp_full_name}} {{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
bool load(::bright::Function<bool(ByteBuf&, const ::bright::String&)> loader)
|
||||
{
|
||||
::bright::HashMap<::bright::String, void*> __tables__;
|
||||
|
||||
ByteBuf buf;
|
||||
{{~for table in tables~}}
|
||||
if (!loader(buf, ""{{table.output_data_file}}"")) return false;
|
||||
if (!{{table.name}}.load(buf)) return false;
|
||||
__tables__[""{{table.full_name}}""] = &{{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.resolve(__tables__);
|
||||
{{~end~}}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
Tables = tables,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -257,80 +59,7 @@ class {{name}}
|
|||
private static Template t_stubRender;
|
||||
public string RenderStub(string topModule, List<DefTypeBase> types)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
#include <algorithm>
|
||||
#include ""gen_types.h""
|
||||
|
||||
using ByteBuf = bright::serialization::ByteBuf;
|
||||
|
||||
namespace {{x.top_module}}
|
||||
{
|
||||
{{~for type in x.types~}}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize(ByteBuf& _buf)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
if (!{{type.parent_def_type.cpp_full_name}}::deserialize(_buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{cpp_deserialize '_buf' field.cpp_style_name field.ctype}}
|
||||
{{~if field.index_field ~}}
|
||||
for(auto& _v : this->{{field.cpp_style_name}})
|
||||
{
|
||||
{{field.cpp_style_name}}_Index.insert({_v->{{field.index_field.cpp_style_name}}, _v});
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize{{type.name}}(ByteBuf& _buf, ::bright::SharedPtr<{{type.cpp_full_name}}>& _out)
|
||||
{
|
||||
{{~if type.is_abstract_type~}}
|
||||
int id;
|
||||
if (!_buf.readInt(id)) return false;
|
||||
switch (id)
|
||||
{
|
||||
{{~for child in type.hierarchy_not_abstract_children~}}
|
||||
case {{child.cpp_full_name}}::ID: { _out.reset(new {{child.cpp_full_name}}()); if (_out->deserialize(_buf)) { return true; } else { _out.reset(); return false;} }
|
||||
{{~end~}}
|
||||
default: { _out = nullptr; return false;}
|
||||
}
|
||||
{{~else~}}
|
||||
_out.reset(new {{type.cpp_full_name}}());
|
||||
if (_out->deserialize(_buf))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_out.reset();
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
void {{type.cpp_full_name}}::resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
{{type.parent_def_type.name}}::resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cpp_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cpp_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/stub"));
|
||||
return template.RenderCode(new
|
||||
{
|
||||
TopModule = topModule,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -12,120 +13,8 @@ namespace Luban.Job.Cfg.Generate
|
|||
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}})
|
||||
{
|
||||
{{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}})
|
||||
{
|
||||
{{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: return new {{child.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -133,103 +22,8 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.ReadSize();
|
||||
if (n != 1) throw new SerializationException(""table mode=one, but size != 1"");
|
||||
{{cs_deserialize '_buf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -237,53 +31,13 @@ public sealed partial class {{name}}
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, ByteBuf> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader(""{{table.output_data_file}}""));
|
||||
tables.Add(""{{table.full_name}}"", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
Namespace = module,
|
||||
Tables = tables,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -11,113 +12,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(JsonElement _json) {{if parent_def_type}} : base(_json) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_json_deserialize '_json' field.cs_style_name field.name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(JsonElement _json)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_json.GetProperty(""__type__"").GetString())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case ""{{child.name}}"": return new {{child.full_name}}(_json);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_json);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_export_fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -127,102 +22,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JsonElement _json)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
foreach(JsonElement _row in _json.EnumerateArray())
|
||||
{
|
||||
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(JsonElement _json)
|
||||
{
|
||||
int n = _json.GetArrayLength();
|
||||
if (n != 1) throw new SerializationException(""table mode=one, but size != 1"");
|
||||
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -233,45 +33,7 @@ public sealed partial class {{name}}
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Text.Json;
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, JsonElement> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader(""{{table.output_data_file}}""));
|
||||
tables.Add(""{{table.full_name}}"", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -11,114 +12,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(JSONNode _json) {{if parent_def_type}} : base(_json) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_unity_json_deserialize '_json' field.cs_style_name field.name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(JSONNode _json)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
string type = _json[""__type__""];
|
||||
switch (type)
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case ""{{child.name}}"": return new {{child.full_name}}(_json);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_json);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_export_fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -128,154 +22,17 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JSONNode _json)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
foreach(JSONNode _row in _json.Children)
|
||||
{
|
||||
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(JSONNode _json)
|
||||
{
|
||||
if(!_json.IsArray)
|
||||
{
|
||||
throw new SerializationException();
|
||||
}
|
||||
if (_json.Count != 1) throw new SerializationException(""table mode=one, but size != 1"");
|
||||
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
using SimpleJSON;
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, JSONNode> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader(""{{table.output_data_file}}""));
|
||||
tables.Add(""{{table.full_name}}"", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -8,115 +8,13 @@ using System.Linq;
|
|||
|
||||
namespace Luban.Job.Cfg.Generate
|
||||
{
|
||||
class EditorCsRender : CodeRenderBase
|
||||
class EditorCsRender : CsCodeRenderBase
|
||||
{
|
||||
public override string Render(DefConst c)
|
||||
{
|
||||
return RenderUtil.RenderCsConstClass(c);
|
||||
}
|
||||
|
||||
public override string Render(DefEnum e)
|
||||
{
|
||||
return RenderUtil.RenderCsEnumClass(e);
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public {{cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}} {{else}} ISerializable {{if is_abstract_type}}, ITypeId {{end}} {{end}}
|
||||
{
|
||||
public {{name}}() {{if parent_def_type}} : base() {{end}}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{~if field.ctype.need_init~}}
|
||||
{{field.proto_cs_init_field}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(false); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
public {{field.ctype.cs_define_type}} {{field.cs_style_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if !parent_def_type && is_abstract_type~}}
|
||||
public abstract int GetTypeId();
|
||||
{{~end~}}
|
||||
{{~if parent_def_type && !is_abstract_type~}}
|
||||
public const int ID = {{id}};
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
public {{cs_method_modifer}} void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Serialize(_buf);
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_serialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{cs_method_modifer}} void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Deserialize(_buf);
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_deserialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{field.proto_cs_to_string}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/bean"));
|
||||
var result = template.Render(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -126,72 +24,7 @@ public {{cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}}
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}} : Bright.Net.Protocol
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
public {{field.ctype.cs_define_type}} {{field.cs_style_name}};
|
||||
{{~end~}}
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{~if field.ctype.need_init~}}
|
||||
{{field.proto_cs_init_field}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
public const int ID = {{id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_serialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_deserialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~for field in fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{field.proto_cs_to_string}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/table"));
|
||||
var result = template.Render(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -201,25 +34,7 @@ public sealed class {{name}} : Bright.Net.Protocol
|
|||
private static Template t_stubRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<int, Bright.Net.IProtocolFactory> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.IProtocolFactory>
|
||||
{
|
||||
{{~for proto in protos ~}}
|
||||
[{{proto.full_name}}.ID] = () => new {{proto.full_name}}(false),
|
||||
{{~end~}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -14,84 +15,8 @@ namespace Luban.Job.Cfg.Generate
|
|||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
import (
|
||||
""bright/serialization""
|
||||
)
|
||||
|
||||
{{x.go_bin_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.go_full_name}}
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{field.cs_style_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
func ({{go_full_name}}) GetTypeId() int {
|
||||
return {{x.id}}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err error) {
|
||||
var id int32
|
||||
if id, err = _buf.ReadInt() ; err != nil {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: return New{{child.go_full_name}}(_buf)
|
||||
{{~end~}}
|
||||
default: return nil, errors.New(""unknown type id"")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func New{{go_full_name}}_Body(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_field field.ctype (""_v."" + field.go_style_name) '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_field field.ctype (""_v."" + field.go_style_name) '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/bean"));
|
||||
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -101,99 +26,8 @@ func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err
|
|||
{
|
||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||
string package = "cfg";
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
import ""bright/serialization""
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, size)
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.cs_style_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.cs_style_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import ""errors""
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else if size != 1 {
|
||||
return nil, errors.New("" size != 1 "")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/table"));
|
||||
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -203,37 +37,7 @@ func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
|||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
|
||||
package {{package}}
|
||||
|
||||
import ""bright/serialization""
|
||||
|
||||
type ByteBufLoader func(string) (*serialization.ByteBuf, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader ByteBufLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf *serialization.ByteBuf
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader(""{{table.output_data_file}}"") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
@ -241,7 +45,6 @@ func NewTables(loader ByteBufLoader) (*{{name}}, error) {
|
|||
Tables = tables,
|
||||
Package = package,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -14,78 +15,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
{{x.go_json_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.go_full_name}}
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{field.cs_style_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
func ({{go_full_name}}) GetTypeId() int {
|
||||
return {{x.id}}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func New{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err error) {
|
||||
var id string
|
||||
var _ok_ bool
|
||||
if id, _ok_ = _buf[""__type__""].(string) ; !_ok_ {
|
||||
return nil, errors.New(""type id missing"")
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case ""{{child.name}}"": return New{{child.go_full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: return nil, errors.New(""unknown type id"")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func New{{go_full_name}}_Body(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_json_field field.ctype (""_v."" + field.go_style_name) field.name '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~else~}}
|
||||
func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_json_field field.ctype (""_v."" + field.go_style_name) field.name '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/bean"));
|
||||
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
|
|
@ -97,88 +27,7 @@ func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err
|
|||
{
|
||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||
string package = "cfg";
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, len(_buf))
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
for _, _ele_ := range _buf {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_ele_'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.cs_style_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.cs_style_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import ""errors""
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
if len(_buf) != 1 {
|
||||
return nil, errors.New("" size != 1 "")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf[0]'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/table"));
|
||||
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
|
|
@ -190,35 +39,7 @@ func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
|||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
|
||||
package {{package}}
|
||||
|
||||
type JsonLoader func(string) ([]map[string]interface{}, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader JsonLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf []map[string]interface{}
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader(""{{table.output_data_file}}"") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -17,19 +18,8 @@ namespace Luban.Job.Cfg.Generate
|
|||
public override string Render(DefConst c)
|
||||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_constRender ??= Template.Parse(@"
|
||||
|
||||
package {{package}}
|
||||
|
||||
const (
|
||||
{{~for item in x.items ~}}
|
||||
{{x.go_full_name}}_{{item.name}} = {{go_const_value item.ctype item.value}}
|
||||
{{~end~}}
|
||||
)
|
||||
");
|
||||
var template = t_constRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/go/const"));
|
||||
var result = template.RenderCode(c, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -39,20 +29,8 @@ const (
|
|||
public override string Render(DefEnum e)
|
||||
{
|
||||
string package = "cfg";
|
||||
|
||||
var template = t_enumRender ??= Template.Parse(@"
|
||||
|
||||
package {{package}}
|
||||
|
||||
const (
|
||||
{{~for item in x.items ~}}
|
||||
{{x.go_full_name}}_{{item.name}} = {{item.value}}
|
||||
{{~end~}}
|
||||
)
|
||||
|
||||
");
|
||||
var template = t_enumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/go/enum"));
|
||||
var result = template.RenderCode(e, new Dictionary<string, object>() { ["package"] = package });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,132 +14,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{x.java_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent_def_type.full_name_with_top_module}} {{else}} bright.serialization.AbstractBean {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{java_deserialize '_buf' field.java_style_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
||||
{
|
||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}});
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.java_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
||||
{
|
||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.readInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name_with_top_module}}.ID: return new {{child.full_name_with_top_module}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{java_define_type field.ctype}} {{field.java_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public final java.util.HashMap<{{java_box_define_type field.index_field.ctype}}, {{java_box_define_type field.ctype.element_type}}> {{field.java_style_name}}_Index = new java.util.HashMap<>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.java_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public static final int ID = {{x.id}};
|
||||
|
||||
@Override
|
||||
public int getTypeId() { return ID; }
|
||||
{{~end~}}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf os)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf os)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{java_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{java_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ ""{{field.java_style_name}}:"" + {{java_to_string field.java_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -149,91 +24,7 @@ public {{x.java_class_modifier}} class {{name}} extends {{if parent_def_type}} {
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.readSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
_dataMap.put(_v.{{x.index_field.java_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> getDataMap() { return _dataMap; }
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
@SuppressWarnings(""unchecked"")
|
||||
public <T extends {{java_box_define_type value_type}}> T getAs({{java_define_type key_type}} key) { return (T)_dataMap.get(key); }
|
||||
{{~end~}}
|
||||
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
for({{java_box_define_type value_type}} v : _dataList)
|
||||
{
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private final {{java_define_type value_type}} _data;
|
||||
|
||||
public final {{java_define_type value_type}} data() { return _data; }
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.readSize();
|
||||
if (n != 1) throw new SerializationException(""table mode=one, but size != 1"");
|
||||
{{java_deserialize '_buf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{java_define_type field.ctype}} {{field.java_getter_name}}() { return _data.{{field.java_style_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
_data.resolve(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -243,40 +34,7 @@ public final class {{name}}
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
package {{package}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
public final class {{name}}
|
||||
{
|
||||
public static interface IByteBufLoader {
|
||||
ByteBuf load(String file) throws java.io.IOException;
|
||||
}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{table.full_name_with_top_module}} {{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(IByteBufLoader loader) throws java.io.IOException {
|
||||
var tables = new java.util.HashMap<String, Object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name_with_top_module}}(loader.load(""{{table.output_data_file}}""));
|
||||
tables.put(""{{table.full_name}}"", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
{{table.name}}.resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -18,145 +18,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
var enums = types.Where(t => t is DefEnum).ToList();
|
||||
var beans = types.Where(t => t is DefBean).ToList();
|
||||
var tables = types.Where(t => t is DefTable).ToList();
|
||||
var template = t_allRender ??= Template.Parse(LuaStringTemplate.BaseDefines + @"
|
||||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local readByte = methods.readByte
|
||||
local readShort = methods.readShort
|
||||
local readFshort = methods.readFshort
|
||||
local readInt = methods.readInt
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local readFlong = methods.readFlong
|
||||
local readFloat = methods.readFloat
|
||||
local readDouble = methods.readDouble
|
||||
local readSize = methods.readSize
|
||||
|
||||
local readString = methods.readString
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local readArray = readList
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
||||
|
||||
local beans = {}
|
||||
{{~ for bean in beans ~}}
|
||||
do
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.export_fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end~}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{bean.id}}
|
||||
class._name = '{{bean.full_name}}'
|
||||
local id2name = { {{for c in bean.hierarchy_not_abstract_children}} [{{c.id}}] = '{{c.full_name}}', {{end}} }
|
||||
{{~if bean.is_abstract_type~}}
|
||||
class._deserialize = function(bs)
|
||||
local id = readInt(bs)
|
||||
return beans[id2name[id]]._deserialize(bs)
|
||||
end
|
||||
{{~else~}}
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{-else-}} readNullableBool(bs) {{-end-}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
{{~end~}}
|
||||
beans[class._name] = class
|
||||
end
|
||||
{{~end~}}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
||||
end
|
||||
|
||||
return { InitTypes = InitTypes }
|
||||
|
||||
|
||||
");
|
||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base") + StringTemplateUtil.GetTemplateString("config/lua_bin/all"));
|
||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,58 +19,8 @@ namespace Luban.Job.Cfg.Generate
|
|||
var enums = types.Where(t => t is DefEnum).ToList();
|
||||
var beans = types.Where(t => t is DefBean).ToList();
|
||||
var tables = types.Where(t => t is DefTable).ToList();
|
||||
var template = t_allRender ??= Template.Parse(LuaStringTemplate.BaseDefines + @"
|
||||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local beans = {}
|
||||
{{~ for bean in beans ~}}
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.export_fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end~}}
|
||||
beans['{{bean.full_name}}'] =
|
||||
{
|
||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||
{ name='{{field.name}}', type='{{lua_comment_type field.ctype}}'},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
||||
|
||||
");
|
||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base")
|
||||
+ StringTemplateUtil.GetTemplateString("config/lua_lua/all"));
|
||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Luban.Job.Cfg.Generate
|
||||
{
|
||||
|
|
@ -12,48 +11,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
|
||||
{{
|
||||
name = x.py_full_name
|
||||
is_abstract_type = x.is_abstract_type
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if is_abstract_type}}(metaclass=abc.ABCMeta){{end}}:
|
||||
{{~if x.is_abstract_type~}}
|
||||
_childrenTypes = None
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
childrenTypes = {{name}}._childrenTypes
|
||||
if not childrenTypes:
|
||||
childrenTypes = {{name}}._childrenTypes = {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
'{{child.name}}': {{child.py_full_name}},
|
||||
{{~end~}}
|
||||
}
|
||||
type = _json_['__type__']
|
||||
child = {{name}}._childrenTypes.get(type)
|
||||
if child != None:
|
||||
return child(_json_)
|
||||
else:
|
||||
raise Exception()
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.py_full_name}}.__init__(self, _json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{py3_deserialize_field ('self.' + field.py_style_name) '_json_' field.name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~if export_fields.empty?}}
|
||||
pass
|
||||
{{~end~}}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -63,50 +21,7 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.py_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~if x.is_map_table ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataMap = {}
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
self._dataMap[_v.{{x.index_field.py_style_name}}] = _v
|
||||
|
||||
def getDataMap(self) : return self._dataMap
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, key) : return self._dataMap.get(key)
|
||||
|
||||
{{~else~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
if (len(_json_) != 1): raise Exception('table mode=one, but size != 1')
|
||||
{{py3_deserialize_value 'self._data' '_json_[0]' value_type}}
|
||||
|
||||
def getData(self) : return self._data
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
'''
|
||||
{{field.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
def {{field.py_style_name}}(self) : return self._data.{{field.py_style_name}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Scriban;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -8,93 +9,21 @@ namespace Luban.Job.Cfg.Generate
|
|||
{
|
||||
abstract class PythonCodeRenderBase : CodeRenderBase
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static Template t_tsConstRender;
|
||||
public override string Render(DefConst c)
|
||||
{
|
||||
var ctx = new TemplateContext();
|
||||
var env = new TTypeTemplateCommonExtends
|
||||
{
|
||||
["x"] = c
|
||||
};
|
||||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_tsConstRender ??= Template.Parse(@"
|
||||
{{~if x.comment != '' ~}}
|
||||
'''
|
||||
{{x.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
class {{x.py_full_name}}:
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
'''
|
||||
{{item.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
{{item.name}} = {{py_const_value item.ctype item.value}}
|
||||
{{~end~}}
|
||||
{{~if (x.items == empty)~}}
|
||||
pass
|
||||
{{~end~}}
|
||||
|
||||
");
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
return RenderUtil.RenderPythonConstClass(c);
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_tsEnumRender;
|
||||
public override string Render(DefEnum e)
|
||||
{
|
||||
var template = t_tsEnumRender ??= Template.Parse(@"
|
||||
{{~if comment != '' ~}}
|
||||
'''
|
||||
{{comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
class {{py_full_name}}(Enum):
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
'''
|
||||
{{item.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}}
|
||||
{{~end~}}
|
||||
{{~if (items == empty)~}}
|
||||
pass
|
||||
{{~end~}}
|
||||
");
|
||||
var result = template.Render(e);
|
||||
|
||||
return result;
|
||||
return RenderUtil.RenderPythonEnumClass(e);
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~ for table in tables ~}}
|
||||
#def {{table.name}} : return self._{{table.name}}
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, loader):
|
||||
{{~for table in tables ~}}
|
||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.output_data_file}}'));
|
||||
{{~end~}}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -13,70 +13,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_buf_: ByteBuf): {{name}} {
|
||||
switch (_buf_.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: return new {{child.full_name}}(_buf_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{ts_bin_constructor ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -86,76 +23,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
|
||||
for(let n = _buf_.ReadInt() ; n > 0 ; n--) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_bin_constructor '_v' '_buf_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key) }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
if (_buf_.ReadInt() != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_bin_constructor 'this._data' '_buf_' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}} }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -165,41 +33,7 @@ export class {{name}} {
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type ByteBufLoader = (file: string) => ByteBuf
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}}}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: ByteBufLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -13,73 +13,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
private static Template t_beanRender;
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_json_: any): {{name}} {
|
||||
switch (_json_.__type__) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case '{{child.name}}': return new {{child.full_name}}(_json_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_json_: any) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if !field.ctype.is_nullable~}}
|
||||
if (_json_.{{field.name}} == undefined) { throw new Error() }
|
||||
{{~end~}}
|
||||
{{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -89,73 +23,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
|
|||
private static Template t_tableRender;
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}}{
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_json_constructor '_v' '_json2_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key); }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
constructor(_json_: any) {
|
||||
if (_json_.length != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_json_constructor 'this._data' '_json_[0]' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data; }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -165,41 +33,7 @@ export class {{name}}{
|
|||
private static Template t_serviceRender;
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_serviceRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type JsonLoader = (file: string) => any
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}};}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: JsonLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/tables"));
|
||||
var result = template.RenderCode(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -556,7 +556,9 @@ namespace Luban.Job.Cfg
|
|||
|
||||
if (args.EmbedBrightTypes)
|
||||
{
|
||||
fileContent.Add(isGenBinary ? TypescriptStringTemplate.VectorTypesByteBuf : TypescriptStringTemplate.VectorTypesJson);
|
||||
fileContent.Add(isGenBinary ?
|
||||
StringTemplateUtil.GetTemplateString("config/typescript_bin/vectors")
|
||||
: StringTemplateUtil.GetTemplateString("config/typescript_json/vectors"));
|
||||
if (isGenBinary)
|
||||
{
|
||||
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
||||
|
|
|
|||
|
|
@ -17,29 +17,7 @@ namespace Luban.Job.Common.Utils
|
|||
};
|
||||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_constRender ??= Template.Parse(@"
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{item.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public const {{cs_define_type item.ctype}} {{item.name}} = {{cs_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_constRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cs/const"));
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
|
|
@ -49,32 +27,7 @@ namespace {{x.namespace_with_top_module}}
|
|||
private static Template t_enumRender;
|
||||
public static string RenderCsEnumClass(DefEnum e)
|
||||
{
|
||||
var template = t_enumRender ??= Template.Parse(@"
|
||||
namespace {{namespace_with_top_module}}
|
||||
{
|
||||
{{~if comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{~if is_flags~}}
|
||||
[System.Flags]
|
||||
{{~end~}}
|
||||
public enum {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{item.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
");
|
||||
var template = t_enumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cs/enum"));
|
||||
var result = template.Render(e);
|
||||
|
||||
return result;
|
||||
|
|
@ -92,28 +45,7 @@ namespace {{namespace_with_top_module}}
|
|||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_javaConstRender ??= Template.Parse(@"
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final class {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public static final {{java_define_type item.ctype}} {{item.name}} = {{java_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
");
|
||||
var template = t_javaConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/java/const"));
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
|
|
@ -123,48 +55,12 @@ public final class {{x.name}}
|
|||
private static Template t_javaEnumRender;
|
||||
public static string RenderJavaEnumClass(DefEnum e)
|
||||
{
|
||||
var template = t_javaEnumRender ??= Template.Parse(@"
|
||||
package {{namespace_with_top_module}};
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public enum {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}}({{item.value}}),
|
||||
{{~end~}}
|
||||
;
|
||||
|
||||
private final int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
{{name}}(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static {{name}} valueOf(int value) {
|
||||
{{~ for item in items ~}}
|
||||
if (value == {{item.value}}) return {{item.name}};
|
||||
{{~end~}}
|
||||
throw new IllegalArgumentException("""");
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_javaEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/java/enum"));
|
||||
var result = template.Render(e);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_cppConstRender;
|
||||
public static string RenderCppConstClass(DefConst c)
|
||||
|
|
@ -177,29 +73,8 @@ public enum {{name}}
|
|||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_cppConstRender ??= Template.Parse(@"
|
||||
{{x.cpp_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
struct {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
static constexpr {{cpp_define_type item.ctype}} {{item.name}} = {{cpp_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
};
|
||||
{{x.cpp_namespace_end}}
|
||||
|
||||
");
|
||||
var template = t_cppConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cpp/const"));
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -207,31 +82,38 @@ struct {{x.name}}
|
|||
private static Template t_cppEnumRender;
|
||||
public static string RenderCppEnumClass(DefEnum e)
|
||||
{
|
||||
var template = t_cppEnumRender ??= Template.Parse(@"
|
||||
{{cpp_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
enum class {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
};
|
||||
{{cpp_namespace_end}}
|
||||
");
|
||||
var template = t_cppEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cpp/enum"));
|
||||
var result = template.Render(e);
|
||||
return result;
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_pythonConstRender;
|
||||
public static string RenderPythonConstClass(DefConst c)
|
||||
{
|
||||
var ctx = new TemplateContext();
|
||||
var env = new TTypeTemplateCommonExtends
|
||||
{
|
||||
["x"] = c
|
||||
};
|
||||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_pythonConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/python/const"));
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_pythonEnumRender;
|
||||
public static string RenderPythonEnumClass(DefEnum e)
|
||||
{
|
||||
var template = t_pythonEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/python/enum"));
|
||||
var result = template.Render(e);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static Template t_tsConstRender;
|
||||
|
|
@ -245,26 +127,7 @@ enum class {{name}}
|
|||
ctx.PushGlobal(env);
|
||||
|
||||
|
||||
var template = t_tsConstRender ??= Template.Parse(@"
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{x.name}} {
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
static {{item.name}} = {{ts_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
|
||||
");
|
||||
var template = t_tsConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/typescript/const"));
|
||||
var result = template.Render(ctx);
|
||||
|
||||
return result;
|
||||
|
|
@ -274,25 +137,7 @@ export class {{x.name}} {
|
|||
private static Template t_tsEnumRender;
|
||||
public static string RenderTypescriptEnumClass(DefEnum e)
|
||||
{
|
||||
var template = t_tsEnumRender ??= Template.Parse(@"
|
||||
{{typescript_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export enum {{name}} {
|
||||
{{~for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
}
|
||||
{{typescript_namespace_end}}
|
||||
");
|
||||
var template = t_tsEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/typescript/enum"));
|
||||
var result = template.Render(e);
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Job.Common.Utils
|
||||
{
|
||||
public static class StringTemplateUtil
|
||||
{
|
||||
public static string TemplateDir { get; set; }
|
||||
|
||||
public static string GetTemplateString(string templateName)
|
||||
{
|
||||
return File.ReadAllText($"{TemplateDir}/{templateName}.tpl", Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,169 +69,6 @@ export abstract class Protocol implements ISerializable {
|
|||
abstract serialize(buf: ByteBuf): void
|
||||
abstract deserialize(buf: ByteBuf): void
|
||||
}
|
||||
";
|
||||
|
||||
public const string VectorTypesJson = @"
|
||||
|
||||
export class Vector2 {
|
||||
static deserializeFromJson(json: any): Vector2 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
if (x == null || y == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector2(x, y)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 {
|
||||
static deserializeFromJson(json: any): Vector3 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
let z = json['z']
|
||||
if (x == null || y == null || z == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector3(x, y, z)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 {
|
||||
static deserializeFromJson(json: any): Vector4 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
let z = json['z']
|
||||
let w = json['w']
|
||||
if (x == null || y == null || z == null || w == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector4(x, y, z, w)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
}
|
||||
|
||||
";
|
||||
|
||||
public const string VectorTypesByteBuf = @"
|
||||
|
||||
export class Vector2 implements ISerializable {
|
||||
|
||||
static deserializeFrom(buf: ByteBuf): Vector2 {
|
||||
var v = new Vector2()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 implements ISerializable{
|
||||
static deserializeFrom(buf: ByteBuf): Vector3 {
|
||||
var v = new Vector3()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 implements ISerializable {
|
||||
static deserializeFrom(buf: ByteBuf): Vector4 {
|
||||
var v = new Vector4()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
_buf_.WriteFloat(this.w)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,210 +35,7 @@ namespace Luban.Job.Db.Generate
|
|||
private static Template t_beanRender;
|
||||
public string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = ""IReadOnly"" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.cs_style_name}} {get;}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : Bright.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => new Bright.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -247,70 +44,7 @@ public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.paren
|
|||
private static Template t_tableRender;
|
||||
public string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, ""{{x.full_name}}"")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> GetAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.GetAsync(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> CreateIfNotExistAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
public static Task InsertAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.InsertAsync(key, value);
|
||||
}
|
||||
|
||||
public static Task RemoveAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public static Task PutAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.PutAsync(key, value);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -320,25 +54,7 @@ public sealed class {{name}}
|
|||
private static Template t_stubRender;
|
||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<Bright.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<Bright.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -35,210 +35,7 @@ namespace Luban.Job.Db.Generate
|
|||
private static Template t_beanRender;
|
||||
public string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = ""IReadOnly"" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.cs_style_name}} {get;}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : Bright.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => new Bright.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -247,75 +44,7 @@ public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.paren
|
|||
private static Template t_tableRender;
|
||||
public string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, ""{{x.full_name}}"")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} Get({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Get(key);
|
||||
}
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} CreateIfNotExist({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExist(key);
|
||||
}
|
||||
|
||||
public static void Insert({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Insert(key, value);
|
||||
}
|
||||
|
||||
public static void Remove({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
Table.Remove(key);
|
||||
}
|
||||
|
||||
public static void Put({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Put(key, value);
|
||||
}
|
||||
|
||||
public static {{db_cs_readonly_define_type value_ttype}} Select({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Select(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -325,25 +54,7 @@ public sealed class {{name}}
|
|||
private static Template t_stubRender;
|
||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<Bright.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<Bright.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -37,165 +37,7 @@ namespace Luban.Job.Db.Generate
|
|||
private static Template t_beanRender;
|
||||
public string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = ""IReadOnly"" + name
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{x.ts_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent}} {{else}} TxnBeanBase {{end}}{
|
||||
{{~ for field in fields~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{field.internal_name}}: {{db_ts_define_type field.ctype}}
|
||||
{{~end}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields~}}
|
||||
{{db_ts_init_field field.internal_name_with_this field.log_type field.ctype }}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{~ctype = field.ctype~}}
|
||||
{{~if has_setter ctype~}}
|
||||
private static {{field.log_type}} = class extends FieldLoggerGeneric2<{{name}}, {{db_ts_define_type ctype}}> {
|
||||
constructor(self:{{name}}, value: {{db_ts_define_type ctype}}) { super(self, value) }
|
||||
|
||||
get fieldId(): number { return this.host.getObjectId() + {{field.id}} }
|
||||
|
||||
get tagId(): number { return FieldTag.{{tag_name ctype}} }
|
||||
|
||||
commit() { this.host.{{field.internal_name}} = this.value }
|
||||
|
||||
writeBlob(_buf: ByteBuf) {
|
||||
{{ts_write_blob '_buf' 'this.value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{db_ts_define_type ctype}} {
|
||||
if (this.isManaged) {
|
||||
var txn = TransactionContext.current
|
||||
if (txn == null) return {{field.internal_name_with_this}}
|
||||
let log: any = txn.getField(this.getObjectId() + {{field.id}})
|
||||
return log != null ? log.value : {{field.internal_name_with_this}}
|
||||
} else {
|
||||
return {{field.internal_name_with_this}};
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
set {{field.ts_style_name}}(value: {{db_ts_define_type ctype}}) {
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new Error()
|
||||
{{~end~}}
|
||||
if (this.isManaged) {
|
||||
let txn = TransactionContext.current!
|
||||
txn.putFieldLong(this.getObjectId() + {{field.id}}, new {{name}}.{{field.log_type}}(this, value))
|
||||
{{~if ctype.need_set_children_root~}}
|
||||
value?.initRoot(this.getRoot())
|
||||
{{~end~}}
|
||||
} else {
|
||||
{{field.internal_name_with_this}} = value
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{db_ts_define_type ctype}} { return {{field.internal_name_with_this}} }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
static serialize{{name}}Any(_buf: ByteBuf, x: {{name}}) {
|
||||
if (x == null) { _buf.WriteInt(0); return }
|
||||
_buf.WriteInt(x.getTypeId())
|
||||
x.serialize(_buf)
|
||||
}
|
||||
|
||||
deserialize{{name}}Any(_buf: ByteBuf): {{name}}{
|
||||
let x: {{name}}
|
||||
switch (_buf.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
x.deserialize(_buf)
|
||||
return x
|
||||
}
|
||||
{{~else~}}
|
||||
serialize(_buf: ByteBuf) {
|
||||
_buf.WriteNumberAsLong(this.getObjectId())
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_ts_compatible_serialize '_buf' field.internal_name_with_this field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
deserialize(_buf: ByteBuf) {
|
||||
this.setObjectId(_buf.ReadLongAsNumber())
|
||||
while(_buf.NotEmpty) {
|
||||
let _tag_ = _buf.ReadInt()
|
||||
switch (_tag_) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_ts_compatible_deserialize '_buf' field.internal_name_with_this field.ctype}}; break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId(): number { return {{name}}.ID }
|
||||
{{~end~}}
|
||||
|
||||
initChildrenRoot(root: TKey) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
{{field.internal_name_with_this}}?.initRoot(root)
|
||||
{{~end~}}
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ ""{{field.ts_style_name}}:"" + {{ts_to_string ('this.' + field.ts_style_name) field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}""
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -204,80 +46,7 @@ export {{x.ts_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x
|
|||
private static Template t_tableRender;
|
||||
public string Render(DefTable p)
|
||||
{
|
||||
var template = t_tableRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
class {{internal_table_type}} extends TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> {
|
||||
constructor() {
|
||||
super({{x.table_uid}}, ""{{x.full_name}}"")
|
||||
}
|
||||
|
||||
newValue(): {{db_ts_define_type value_ttype}} { return new {{db_ts_define_type value_ttype}}() }
|
||||
|
||||
serializeKey(buf: ByteBuf, key: {{db_ts_define_type key_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'key' key_ttype}}
|
||||
}
|
||||
|
||||
serializeValue(buf: ByteBuf, value: {{db_ts_define_type value_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'value' value_ttype}}
|
||||
}
|
||||
|
||||
deserializeKey(buf: ByteBuf): {{db_ts_define_type key_ttype}} {
|
||||
let key: {{db_ts_define_type key_ttype}}
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'key' key_ttype}}
|
||||
return key
|
||||
}
|
||||
|
||||
deserializeValue(buf: ByteBuf): {{db_ts_define_type value_ttype}} {
|
||||
let value = new {{db_ts_define_type value_ttype}}()
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'value' value_ttype}}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
static readonly _table = new {{internal_table_type}}();
|
||||
static get table(): TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> { return this._table }
|
||||
|
||||
static getAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.getAsync(key);
|
||||
}
|
||||
|
||||
static createIfNotExistAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.createIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
static insertAsync(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.insertAsync(key, value);
|
||||
}
|
||||
|
||||
static removeAsync(key: {{db_ts_define_type key_ttype}}): Promise<void> {
|
||||
return {{name}}._table.removeAsync(key);
|
||||
}
|
||||
|
||||
static put(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.putAsync(key, value);
|
||||
}
|
||||
|
||||
static selectAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.selectAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
||||
");
|
||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/table"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -287,17 +56,7 @@ export class {{name}} {
|
|||
private static Template t_stubRender;
|
||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
|
||||
export class {{name}} {
|
||||
static readonly tableList: TxnTable[] = [
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.table,
|
||||
{{~end}}
|
||||
]
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/tables"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -37,125 +37,7 @@ namespace Luban.Job.Proto.Generate
|
|||
private static Template t_beanRender;
|
||||
private string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{
|
||||
is_value_type = x.is_value_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{if is_value_type}}struct{{else}}{{x.cs_class_modifier}} class{{end}} {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Serialization.BeanBase {{end}}
|
||||
{
|
||||
{{~if !is_value_type~}}
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||
{{~else if is_value_type~}}
|
||||
{{field.cs_style_name}} = default;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
if (x != null)
|
||||
{
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
_buf.WriteInt(0);
|
||||
}
|
||||
{{~else~}}
|
||||
x.Serialize(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
{{full_name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
{{~else~}}
|
||||
var x = new {{full_name}}();
|
||||
x.Deserialize(_buf);
|
||||
{{~end~}}
|
||||
return x;
|
||||
}
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_serialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -165,90 +47,7 @@ namespace {{x.namespace_with_top_module}}
|
|||
private static Template t_protoRender;
|
||||
private string Render(DefProto p)
|
||||
{
|
||||
var template = t_protoRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Protocol
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
public const int ID = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_serialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in fields ~}}
|
||||
+ ""{{field.cs_style_name}}:"" + {{cs_to_string field.cs_style_name field.ctype}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_protoRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/proto"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -258,56 +57,7 @@ namespace {{x.namespace_with_top_module}}
|
|||
private static Template t_rpcRender;
|
||||
private string Render(DefRpc r)
|
||||
{
|
||||
var template = t_rpcRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
targ_type = x.targ_type
|
||||
tres_type = x.tres_type
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Rpc<{{cs_define_type targ_type}}, {{cs_define_type tres_type}}>
|
||||
{
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $""{{full_name}}{%{ {{arg:{Arg},res:{Res} }} }%}"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_rpcRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/rpc"));
|
||||
var result = template.RenderCode(r);
|
||||
|
||||
return result;
|
||||
|
|
@ -317,28 +67,7 @@ namespace {{x.namespace_with_top_module}}
|
|||
private static Template t_stubRender;
|
||||
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator>
|
||||
{
|
||||
{{~ for proto in protos ~}}
|
||||
[{{proto.full_name}}.ID] = () => new {{proto.full_name}}(),
|
||||
{{~end~}}
|
||||
|
||||
{{~ for rpc in rpcs ~}}
|
||||
[{{rpc.full_name}}.ID] = () => new {{rpc.full_name}}(),
|
||||
{{~end~}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/stub"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Luban.Job.Proto.Defs;
|
||||
using Scriban;
|
||||
using System;
|
||||
|
|
@ -19,268 +20,7 @@ namespace Luban.Job.Proto.Generate
|
|||
var beans = types.Where(t => t is DefBean).ToList();
|
||||
var protos = types.Where(t => t is DefProto).ToList();
|
||||
var rpcs = types.Where(t => t is DefRpc).ToList();
|
||||
var template = t_allRender ??= Template.Parse(@"
|
||||
{{
|
||||
consts = x.consts
|
||||
enums = x.enums
|
||||
beans = x.beans
|
||||
protos = x.protos
|
||||
}}
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local tinsert = table.insert
|
||||
|
||||
local function SimpleClass()
|
||||
local class = {}
|
||||
class.__index = class
|
||||
class.New = function(...)
|
||||
local ctor = class.ctor
|
||||
local o = ctor and ctor(...) or {}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
return class
|
||||
end
|
||||
|
||||
|
||||
local function get_map_size(m)
|
||||
local n = 0
|
||||
for _ in pairs(m) do
|
||||
n = n + 1
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local writeBool = methods.writeBool
|
||||
local readByte = methods.readByte
|
||||
local writeByte = methods.writeByte
|
||||
local readShort = methods.readShort
|
||||
local writeShort = methods.writeShort
|
||||
local readFshort = methods.readFshort
|
||||
local writeInt = methods.writeInt
|
||||
local readInt = methods.readInt
|
||||
local writeFint = methods.writeFint
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local writeLong = methods.writeLong
|
||||
local readFlong = methods.readFlong
|
||||
local writeFlong = methods.writeFlong
|
||||
local readFloat = methods.readFloat
|
||||
local writeFloat = methods.writeFloat
|
||||
local readDouble = methods.readDouble
|
||||
local writeDouble = methods.writeDouble
|
||||
local readSize = methods.readSize
|
||||
local writeSize = methods.writeSize
|
||||
|
||||
local readString = methods.readString
|
||||
local writeString = methods.writeString
|
||||
local readBytes = methods.readBytes
|
||||
local writeBytes = methods.writeBytes
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector2(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector3(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
writeFloat(bs, v.z)
|
||||
end
|
||||
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector4(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
writeFloat(bs, v.z)
|
||||
writeFloat(bs, v.w)
|
||||
end
|
||||
|
||||
local function writeList(bs, list, keyFun)
|
||||
writeSize(bs, #list)
|
||||
for _, v in pairs(list) do
|
||||
keyFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local writeArray = writeList
|
||||
local readArray = readList
|
||||
|
||||
local function writeSet(bs, set, keyFun)
|
||||
writeSize(bs, #set)
|
||||
for _, v in ipairs(set) do
|
||||
keyFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function writeMap(bs, map, keyFun, valueFun)
|
||||
writeSize(bs, get_map_size(map))
|
||||
for k, v in pairs(map) do
|
||||
keyFun(bs, k)
|
||||
valueFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
||||
|
||||
local default_vector2 = {x=0,y=0}
|
||||
local default_vector3 = {x=0,y=0,z=0}
|
||||
local default_vector4 = {x=0,y=0,z=0,w=0}
|
||||
|
||||
local beans = {}
|
||||
{{ for bean in beans }}
|
||||
do
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{bean.id}}
|
||||
class._name = '{{bean.full_name}}'
|
||||
local id2name = { {{for c in bean.hierarchy_not_abstract_children}} [{{c.id}}] = '{{c.full_name}}', {{end}} }
|
||||
{{if bean.is_abstract_type}}
|
||||
class._serialize = function(bs, self)
|
||||
writeInt(bs, {{bean.id}})
|
||||
beans[self._name]._serialize(bs, self)
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local id = readInt(bs)
|
||||
return beans[id2name[id]]._deserialize(bs)
|
||||
end
|
||||
{{else}}
|
||||
class._serialize = function(bs, self)
|
||||
{{~ for field in bean.hierarchy_fields ~}}
|
||||
{{lua_serialize_while_nil 'bs' ('self.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in bean.hierarchy_fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{else}} readNullableBool(bs) {{end}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
{{end}}
|
||||
beans[class._name] = class
|
||||
end
|
||||
{{end}}
|
||||
|
||||
local protos = { }
|
||||
{{ for proto in protos }}
|
||||
do
|
||||
---@class {{proto.full_name}}
|
||||
{{~ for field in proto.fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{proto.id}}
|
||||
class._name = '{{proto.full_name}}'
|
||||
class._serialize = function(bs, self)
|
||||
{{~ for field in proto.fields ~}}
|
||||
{{lua_serialize_while_nil 'bs' ('self.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in proto.fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{else}} readNullableBool(bs) {{end}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
protos[class._id] = class
|
||||
protos[class._name] = class
|
||||
end
|
||||
{{end}}
|
||||
|
||||
return { consts = consts, enums = enums, beans = beans, protos = protos }
|
||||
end
|
||||
|
||||
return { InitTypes = InitTypes}
|
||||
|
||||
|
||||
");
|
||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/lua/all"));
|
||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Protos = protos, Rpcs = rpcs });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,96 +40,7 @@ namespace Luban.Job.Proto.Generate
|
|||
private static Template t_beanRender;
|
||||
private string Render(DefBean b)
|
||||
{
|
||||
var template = t_beanRender ??= Template.Parse(@"
|
||||
{{
|
||||
is_value_type = x.is_value_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
}}
|
||||
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if parent_def_type}}{{x.parent}}{{else}}BeanBase{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static serializeTo(_buf_ : ByteBuf, _bean_ : {{name}}) {
|
||||
_buf_.WriteInt(_bean_.getTypeId())
|
||||
_bean_.serialize(_buf_)
|
||||
}
|
||||
|
||||
static deserializeFrom(_buf_ : ByteBuf) : {{name}} {
|
||||
let _bean_ :{{name}}
|
||||
switch (_buf_.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: _bean_ = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
_bean_.deserialize(_buf_)
|
||||
return _bean_
|
||||
}
|
||||
{{else}}
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId() { return {{name}}.ID }
|
||||
{{~end~}}
|
||||
|
||||
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
serialize(_buf_ : ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super.serialize(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_serialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
deserialize(_buf_ : ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super.deserialize(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_deserialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
+ ""{{field.ts_style_name}}:"" + this.{{field.ts_style_name}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}""
|
||||
}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/bean"));
|
||||
var result = template.RenderCode(b);
|
||||
|
||||
return result;
|
||||
|
|
@ -139,63 +50,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if pa
|
|||
private static Template t_protoRender;
|
||||
private string Render(DefProto p)
|
||||
{
|
||||
var template = t_protoRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} extends Protocol {
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId() { return {{name}}.ID }
|
||||
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
serialize(_buf_ : ByteBuf) {
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_serialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
deserialize(_buf_ : ByteBuf) {
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_deserialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return ""{{full_name}}{ ""
|
||||
{{~ for field in fields ~}}
|
||||
+ ""{{field.ts_style_name}}:"" + this.{{field.ts_style_name}} + "",""
|
||||
{{~end~}}
|
||||
+ ""}""
|
||||
}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
");
|
||||
var template = t_protoRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/proto"));
|
||||
var result = template.RenderCode(p);
|
||||
|
||||
return result;
|
||||
|
|
@ -205,19 +60,7 @@ export class {{name}} extends Protocol {
|
|||
private static Template t_rpcRender;
|
||||
private string Render(DefRpc r)
|
||||
{
|
||||
var template = t_rpcRender ??= Template.Parse(@"
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
targ_type = x.targ_type
|
||||
tres_type = x.tres_type
|
||||
}}
|
||||
|
||||
// TODO {{full_name}}
|
||||
|
||||
");
|
||||
var template = t_rpcRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/rpc"));
|
||||
var result = template.RenderCode(r);
|
||||
|
||||
return result;
|
||||
|
|
@ -227,26 +70,7 @@ export class {{name}} extends Protocol {
|
|||
private static Template t_stubRender;
|
||||
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
||||
{
|
||||
var template = t_stubRender ??= Template.Parse(@"
|
||||
|
||||
type ProtocolFactory = () => Protocol
|
||||
|
||||
export class {{name}} {
|
||||
static readonly Factories = new Map<number, ProtocolFactory>([
|
||||
|
||||
{{~ for proto in protos ~}}
|
||||
[{{proto.full_name}}.ID, () => new {{proto.full_name}}()],
|
||||
{{~end~}}
|
||||
|
||||
{{~ for rpc in rpcs ~}}
|
||||
// TODO RPC .. [{{rpc.full_name}}.ID] = () => new {{rpc.full_name}}(),
|
||||
{{~end~}}
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
|
||||
");
|
||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/stub"));
|
||||
var result = template.Render(new
|
||||
{
|
||||
Name = name,
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ namespace Luban.Job.Proto
|
|||
}
|
||||
if (args.EmbedBrightTypes)
|
||||
{
|
||||
fileContent.Add(TypescriptStringTemplate.VectorTypesByteBuf);
|
||||
fileContent.Add(StringTemplateUtil.GetTemplateString("config/typescript_bin/vectors"));
|
||||
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
||||
fileContent.Add(TypescriptStringTemplate.ProtoTypes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,217 @@
|
|||
<ProjectReference Include="..\Luban.Server.Common\Luban.Server.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Templates\common\cpp\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\cpp\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\cs\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\cs\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\go\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\go\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\java\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\java\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\lua\base.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\python\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\python\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\typescript\const.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\common\typescript\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cpp_bin\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cpp_bin\stub.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cpp_bin\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cpp_bin\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_bin\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_bin\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_bin\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_editor_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_editor_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_editor_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_unity_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_unity_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\cs_unity_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_bin\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_bin\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_bin\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\go_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\java_bin\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\java_bin\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\java_bin\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\lua_bin\all.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\lua_bin\method.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\lua_lua\all.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\python_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\python_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\python_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_bin\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_bin\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_bin\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_bin\vectors.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_json\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_json\vectors.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_async\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_async\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_async\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_sync\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_sync\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\cs_sync\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\typescript\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\typescript\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\db\typescript\tables.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\cs\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\cs\proto.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\cs\rpc.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\cs\stub.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\lua\all.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\typescript\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\typescript\proto.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\typescript\rpc.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\proto\typescript\stub.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"profiles": {
|
||||
"Luban.Server": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-p 8899"
|
||||
"commandLineArgs": "-p 8899 -t ../../../Templates"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ namespace Luban.Server
|
|||
|
||||
public void RegisterJob(string jobType, IJobController jobController)
|
||||
{
|
||||
s_logger.Info("register job. name:{name} class:{class}", jobType, jobController.GetType().FullName);
|
||||
s_logger.Debug("register job. name:{name} class:{class}", jobType, jobController.GetType().FullName);
|
||||
_jobs.Add(jobType, jobController);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ namespace Luban.Server
|
|||
|
||||
[Option('l', "loglevel", Required = false, HelpText = "log level. default INFO. avaliable value: TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF")]
|
||||
public string LogLevel { get; set; } = "INFO";
|
||||
|
||||
[Option('t', "string template directory", Required = false, HelpText = "string template directory.")]
|
||||
public string StringTemplateDir { get; set; } = "Templates";
|
||||
}
|
||||
|
||||
private static CommandLineOptions ParseOptions(String[] args)
|
||||
|
|
@ -45,6 +48,8 @@ namespace Luban.Server
|
|||
|
||||
var options = ParseOptions(args);
|
||||
|
||||
Job.Common.Utils.StringTemplateUtil.TemplateDir = options.StringTemplateDir;
|
||||
|
||||
Luban.Common.Utils.LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel));
|
||||
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
|
@ -58,6 +63,8 @@ namespace Luban.Server
|
|||
int processorCount = System.Environment.ProcessorCount;
|
||||
ThreadPool.SetMinThreads(Math.Max(4, processorCount), 5);
|
||||
ThreadPool.SetMaxThreads(Math.Max(16, processorCount * 4), 10);
|
||||
|
||||
Console.WriteLine("== running ==");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
{{x.cpp_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
struct {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
static constexpr {{cpp_define_type item.ctype}} {{item.name}} = {{cpp_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
};
|
||||
{{x.cpp_namespace_end}}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{{cpp_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
enum class {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
};
|
||||
{{cpp_namespace_end}}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{item.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public const {{cs_define_type item.ctype}} {{item.name}} = {{cs_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
namespace {{namespace_with_top_module}}
|
||||
{
|
||||
{{~if comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{~if is_flags~}}
|
||||
[System.Flags]
|
||||
{{~end~}}
|
||||
public enum {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{item.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package {{package}}
|
||||
|
||||
const (
|
||||
{{~for item in x.items ~}}
|
||||
{{x.go_full_name}}_{{item.name}} = {{go_const_value item.ctype item.value}}
|
||||
{{~end~}}
|
||||
)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package {{package}}
|
||||
|
||||
const (
|
||||
{{~for item in x.items ~}}
|
||||
{{x.go_full_name}}_{{item.name}} = {{item.int_value}}
|
||||
{{~end~}}
|
||||
)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final class {{x.name}}
|
||||
{
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public static final {{java_define_type item.ctype}} {{item.name}} = {{java_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package {{namespace_with_top_module}};
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public enum {{name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}}({{item.int_value}}),
|
||||
{{~end~}}
|
||||
;
|
||||
|
||||
private final int value;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
{{name}}(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static {{name}} valueOf(int value) {
|
||||
{{~ for item in items ~}}
|
||||
if (value == {{item.int_value}}) return {{item.name}};
|
||||
{{~end~}}
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
{{
|
||||
consts = x.consts
|
||||
enums = x.enums
|
||||
beans = x.beans
|
||||
tables = x.tables
|
||||
}}
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local tinsert = table.insert
|
||||
|
||||
local function SimpleClass()
|
||||
local class = {}
|
||||
class.__index = class
|
||||
class.New = function(...)
|
||||
local ctor = class.ctor
|
||||
local o = ctor and ctor(...) or {}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
return class
|
||||
end
|
||||
|
||||
|
||||
local function get_map_size(m)
|
||||
local n = 0
|
||||
for _ in pairs(m) do
|
||||
n = n + 1
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{{~if x.comment != '' ~}}
|
||||
'''
|
||||
{{x.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
class {{x.py_full_name}}:
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
'''
|
||||
{{item.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
{{item.name}} = {{py_const_value item.ctype item.value}}
|
||||
{{~end~}}
|
||||
{{~if (x.items == empty)~}}
|
||||
pass
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{{~if comment != '' ~}}
|
||||
'''
|
||||
{{comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
class {{py_full_name}}(Enum):
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
'''
|
||||
{{item.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}}
|
||||
{{~end~}}
|
||||
{{~if (items == empty)~}}
|
||||
pass
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{x.name}} {
|
||||
{{~ for item in x.items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
static {{item.name}} = {{ts_const_value item.ctype item.value}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{{typescript_namespace_begin}}
|
||||
{{~if comment != '' ~}}
|
||||
/**
|
||||
* {{comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export enum {{name}} {
|
||||
{{~for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/**
|
||||
* {{item.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
}
|
||||
{{typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{{x.cpp_namespace_begin}}
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
class {{name}} : public {{if parent_def_type}} {{parent_def_type.cpp_full_name}} {{else}} bright::CfgBean {{end}}
|
||||
{
|
||||
public:
|
||||
|
||||
static bool deserialize{{name}}(ByteBuf& _buf, ::bright::SharedPtr<{{name}}>& _out);
|
||||
|
||||
{{name}}()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
{{~if !hierarchy_export_fields.empty?~}}
|
||||
{{name}}({{- for field in hierarchy_export_fields }}{{cpp_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
||||
{{~if parent_def_type~}}
|
||||
: {{parent_def_type.cpp_full_name}}({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}})
|
||||
{{~end~}}
|
||||
{
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
this->{{field.cpp_style_name}} = {{field.name}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
virtual ~{{name}}() {}
|
||||
|
||||
bool deserialize(ByteBuf& _buf);
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}} {{field.cpp_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
::bright::HashMap<{{cpp_define_type field.index_field.ctype}}, {{cpp_define_type field.ctype.element_type}}> {{field.cpp_style_name}}_Index;
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.cpp_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
static constexpr int ID = {{x.id}};
|
||||
|
||||
int getTypeId() const { return ID; }
|
||||
{{~end~}}
|
||||
|
||||
virtual void resolve(::bright::HashMap<::bright::String, void*>& _tables);
|
||||
};
|
||||
|
||||
{{x.cpp_namespace_end}}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
#include <algorithm>
|
||||
#include "gen_types.h"
|
||||
|
||||
using ByteBuf = bright::serialization::ByteBuf;
|
||||
|
||||
namespace {{x.top_module}}
|
||||
{
|
||||
{{~for type in x.types~}}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize(ByteBuf& _buf)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
if (!{{type.parent_def_type.cpp_full_name}}::deserialize(_buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{cpp_deserialize '_buf' field.cpp_style_name field.ctype}}
|
||||
{{~if field.index_field ~}}
|
||||
for(auto& _v : this->{{field.cpp_style_name}})
|
||||
{
|
||||
{{field.cpp_style_name}}_Index.insert({_v->{{field.index_field.cpp_style_name}}, _v});
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize{{type.name}}(ByteBuf& _buf, ::bright::SharedPtr<{{type.cpp_full_name}}>& _out)
|
||||
{
|
||||
{{~if type.is_abstract_type~}}
|
||||
int id;
|
||||
if (!_buf.readInt(id)) return false;
|
||||
switch (id)
|
||||
{
|
||||
{{~for child in type.hierarchy_not_abstract_children~}}
|
||||
case {{child.cpp_full_name}}::ID: { _out.reset(new {{child.cpp_full_name}}()); if (_out->deserialize(_buf)) { return true; } else { _out.reset(); return false;} }
|
||||
{{~end~}}
|
||||
default: { _out = nullptr; return false;}
|
||||
}
|
||||
{{~else~}}
|
||||
_out.reset(new {{type.cpp_full_name}}());
|
||||
if (_out->deserialize(_buf))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_out.reset();
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
void {{type.cpp_full_name}}::resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
{{type.parent_def_type.name}}::resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cpp_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cpp_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
{{x.cpp_namespace_begin}}
|
||||
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private:
|
||||
::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}> _dataMap;
|
||||
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
|
||||
|
||||
public:
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
for(; n > 0 ; --n)
|
||||
{
|
||||
{{cpp_define_type value_type}} _v;
|
||||
{{cpp_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.push_back(_v);
|
||||
_dataMap[_v->{{x.index_field.cpp_style_name}}] = _v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const ::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}>& getDataMap() const { return _dataMap; }
|
||||
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
|
||||
|
||||
{{value_type.bean.cpp_full_name}}* getRaw({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
|
||||
{{cpp_define_type value_type}} get({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
for(auto v : _dataList)
|
||||
{
|
||||
v->resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private:
|
||||
{{cpp_define_type value_type}} _data;
|
||||
|
||||
public:
|
||||
{{cpp_define_type value_type}} data() const { return _data; }
|
||||
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
if (n != 1) return false;
|
||||
{{cpp_deserialize '_buf' '_data' value_type}}
|
||||
return true;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
_data->resolve(_tables);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}}& {{field.cpp_getter_name}}() const { return _data->{{field.cpp_style_name}}; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
};
|
||||
{{x.cpp_namespace_end}}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
class {{name}}
|
||||
{
|
||||
public:
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{table.cpp_full_name}} {{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
bool load(::bright::Function<bool(ByteBuf&, const ::bright::String&)> loader)
|
||||
{
|
||||
::bright::HashMap<::bright::String, void*> __tables__;
|
||||
|
||||
ByteBuf buf;
|
||||
{{~for table in tables~}}
|
||||
if (!loader(buf, "{{table.output_data_file}}")) return false;
|
||||
if (!{{table.name}}.load(buf)) return false;
|
||||
__tables__["{{table.full_name}}"] = &{{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.resolve(__tables__);
|
||||
{{~end~}}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}})
|
||||
{
|
||||
{{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}})
|
||||
{
|
||||
{{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: return new {{child.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.ReadSize();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{cs_deserialize '_buf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, ByteBuf> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public {{cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}} {{else}} ISerializable {{if is_abstract_type}}, ITypeId {{end}} {{end}}
|
||||
{
|
||||
public {{name}}() {{if parent_def_type}} : base() {{end}}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{~if field.ctype.need_init~}}
|
||||
{{field.proto_cs_init_field}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(false); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
public {{field.ctype.cs_define_type}} {{field.cs_style_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if !parent_def_type && is_abstract_type~}}
|
||||
public abstract int GetTypeId();
|
||||
{{~end~}}
|
||||
{{~if parent_def_type && !is_abstract_type~}}
|
||||
public const int ID = {{id}};
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
public {{cs_method_modifer}} void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Serialize(_buf);
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_serialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{cs_method_modifer}} void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Deserialize(_buf);
|
||||
{{~end~}}
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_deserialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{field.proto_cs_to_string}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}} : Bright.Net.Protocol
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
public {{field.ctype.cs_define_type}} {{field.cs_style_name}};
|
||||
{{~end~}}
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{~if field.ctype.need_init~}}
|
||||
{{field.proto_cs_init_field}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
public const int ID = {{id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_serialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~for field in fields ~}}
|
||||
{{field.cs_deserialize}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{field.proto_cs_to_string}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<int, Bright.Net.IProtocolFactory> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.IProtocolFactory>
|
||||
{
|
||||
{{~for proto in protos ~}}
|
||||
[{{proto.full_name}}.ID] = () => new {{proto.full_name}}(false),
|
||||
{{~end~}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(JsonElement _json) {{if parent_def_type}} : base(_json) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_json_deserialize '_json' field.cs_style_name field.name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(JsonElement _json)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_json.GetProperty("__type__").GetString())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case "{{child.name}}": return new {{child.full_name}}(_json);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_json);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JsonElement _json)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
foreach(JsonElement _row in _json.EnumerateArray())
|
||||
{
|
||||
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(JsonElement _json)
|
||||
{
|
||||
int n = _json.GetArrayLength();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using Bright.Serialization;
|
||||
using System.Text.Json;
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, JsonElement> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(JSONNode _json) {{if parent_def_type}} : base(_json) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_unity_json_deserialize '_json' field.cs_style_name field.name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.cs_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.cs_style_name}}) { {{field.cs_style_name}}_Index.Add(_v.{{field.index_field.cs_style_name}}, _v); }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(JSONNode _json)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
string type = _json["__type__"];
|
||||
switch (type)
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case "{{child.name}}": return new {{child.full_name}}(_json);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_json);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JSONNode _json)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
foreach(JSONNode _row in _json.Children)
|
||||
{
|
||||
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.cs_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(JSONNode _json)
|
||||
{
|
||||
if(!_json.IsArray)
|
||||
{
|
||||
throw new SerializationException();
|
||||
}
|
||||
if (_json.Count != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}} => _data.{{field.cs_style_name}};
|
||||
{{~if field.ref~}}
|
||||
public {{field.cs_ref_type_name}} {{field.cs_ref_var_name}} => _data.{{field.cs_ref_var_name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
OnResolveFinish(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using Bright.Serialization;
|
||||
using SimpleJSON;
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed partial class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, JSONNode> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
import (
|
||||
"bright/serialization"
|
||||
)
|
||||
|
||||
{{x.go_bin_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.go_full_name}}
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{field.cs_style_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
func ({{go_full_name}}) GetTypeId() int {
|
||||
return {{x.id}}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err error) {
|
||||
var id int32
|
||||
if id, err = _buf.ReadInt() ; err != nil {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: return New{{child.go_full_name}}(_buf)
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func New{{go_full_name}}_Body(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_field field.ctype ("_v." + field.go_style_name) '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_field field.ctype ("_v." + field.go_style_name) '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
import "bright/serialization"
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, size)
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.cs_style_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.cs_style_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import "errors"
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else if size != 1 {
|
||||
return nil, errors.New(" size != 1 ")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
package {{package}}
|
||||
|
||||
import "bright/serialization"
|
||||
|
||||
type ByteBufLoader func(string) (*serialization.ByteBuf, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader ByteBufLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf *serialization.ByteBuf
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader("{{table.output_data_file}}") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
{{x.go_json_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.go_full_name}}
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{field.cs_style_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
func ({{go_full_name}}) GetTypeId() int {
|
||||
return {{x.id}}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func New{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err error) {
|
||||
var id string
|
||||
var _ok_ bool
|
||||
if id, _ok_ = _buf["__type__"].(string) ; !_ok_ {
|
||||
return nil, errors.New("type id missing")
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case "{{child.name}}": return New{{child.go_full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func New{{go_full_name}}_Body(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_json_field field.ctype ("_v." + field.go_style_name) field.name '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~else~}}
|
||||
func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~if parent_def_type~}}
|
||||
var _p *{{parent_def_type.go_full_name}}
|
||||
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||
_v.{{parent_def_type.go_full_name}} = *_p
|
||||
{{~end~}}
|
||||
{{~for field in export_fields ~}}
|
||||
{{go_deserialize_json_field field.ctype ("_v." + field.go_style_name) field.name '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
-}}
|
||||
|
||||
package {{package}}
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, len(_buf))
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
for _, _ele_ := range _buf {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_ele_'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.cs_style_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.cs_style_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import "errors"
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
if len(_buf) != 1 {
|
||||
return nil, errors.New(" size != 1 ")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf[0]'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
package {{package}}
|
||||
|
||||
type JsonLoader func(string) ([]map[string]interface{}, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader JsonLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf []map[string]interface{}
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader("{{table.output_data_file}}") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{x.java_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent_def_type.full_name_with_top_module}} {{else}} bright.serialization.AbstractBean {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{java_deserialize '_buf' field.java_style_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
||||
{
|
||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}});
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
this.{{field.java_style_name}} = {{field.name}};
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
||||
{
|
||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.readInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name_with_top_module}}.ID: return new {{child.full_name_with_top_module}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{java_define_type field.ctype}} {{field.java_style_name}};
|
||||
{{~if field.index_field~}}
|
||||
public final java.util.HashMap<{{java_box_define_type field.index_field.ctype}}, {{java_box_define_type field.ctype.element_type}}> {{field.java_style_name}}_Index = new java.util.HashMap<>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.java_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public static final int ID = {{x.id}};
|
||||
|
||||
@Override
|
||||
public int getTypeId() { return ID; }
|
||||
{{~end~}}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf os)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf os)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{java_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{java_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.java_style_name}}:" + {{java_to_string field.java_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.readSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
_dataMap.put(_v.{{x.index_field.java_style_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> getDataMap() { return _dataMap; }
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends {{java_box_define_type value_type}}> T getAs({{java_define_type key_type}} key) { return (T)_dataMap.get(key); }
|
||||
{{~end~}}
|
||||
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
for({{java_box_define_type value_type}} v : _dataList)
|
||||
{
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private final {{java_define_type value_type}} _data;
|
||||
|
||||
public final {{java_define_type value_type}} data() { return _data; }
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.readSize();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{java_deserialize '_buf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{java_define_type field.ctype}} {{field.java_getter_name}}() { return _data.{{field.java_style_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
||||
{
|
||||
_data.resolve(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package {{package}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
public final class {{name}}
|
||||
{
|
||||
public static interface IByteBufLoader {
|
||||
ByteBuf load(String file) throws java.io.IOException;
|
||||
}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{table.full_name_with_top_module}} {{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(IByteBufLoader loader) throws java.io.IOException {
|
||||
var tables = new java.util.HashMap<String, Object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
||||
tables.put("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
{{table.name}}.resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local readByte = methods.readByte
|
||||
local readShort = methods.readShort
|
||||
local readFshort = methods.readFshort
|
||||
local readInt = methods.readInt
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local readFlong = methods.readFlong
|
||||
local readFloat = methods.readFloat
|
||||
local readDouble = methods.readDouble
|
||||
local readSize = methods.readSize
|
||||
|
||||
local readString = methods.readString
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local readArray = readList
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
||||
|
||||
local beans = {}
|
||||
{{~ for bean in beans ~}}
|
||||
do
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.export_fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end~}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{bean.id}}
|
||||
class._name = '{{bean.full_name}}'
|
||||
local id2name = { {{for c in bean.hierarchy_not_abstract_children}} [{{c.id}}] = '{{c.full_name}}', {{end}} }
|
||||
{{~if bean.is_abstract_type~}}
|
||||
class._deserialize = function(bs)
|
||||
local id = readInt(bs)
|
||||
return beans[id2name[id]]._deserialize(bs)
|
||||
end
|
||||
{{~else~}}
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{-else-}} readNullableBool(bs) {{-end-}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
{{~end~}}
|
||||
beans[class._name] = class
|
||||
end
|
||||
{{~end~}}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
||||
end
|
||||
|
||||
return { InitTypes = InitTypes }
|
||||
|
||||
|
|
@ -1,47 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Job.Common.Utils
|
||||
{
|
||||
public static class LuaStringTemplate
|
||||
{
|
||||
public const string BaseDefines = @"
|
||||
{{
|
||||
consts = x.consts
|
||||
enums = x.enums
|
||||
beans = x.beans
|
||||
tables = x.tables
|
||||
}}
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local tinsert = table.insert
|
||||
|
||||
local function SimpleClass()
|
||||
local class = {}
|
||||
class.__index = class
|
||||
class.New = function(...)
|
||||
local ctor = class.ctor
|
||||
local o = ctor and ctor(...) or {}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
return class
|
||||
end
|
||||
|
||||
|
||||
local function get_map_size(m)
|
||||
local n = 0
|
||||
for _ in pairs(m) do
|
||||
n = n + 1
|
||||
end
|
||||
return n
|
||||
end";
|
||||
|
||||
public const string MethodHeader = @"local function InitTypes(methods)
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local readByte = methods.readByte
|
||||
local readShort = methods.readShort
|
||||
|
|
@ -102,6 +59,4 @@ end";
|
|||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end";
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local beans = {}
|
||||
{{~ for bean in beans ~}}
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.export_fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end~}}
|
||||
beans['{{bean.full_name}}'] =
|
||||
{
|
||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||
{ name='{{field.name}}', type='{{lua_comment_type field.ctype}}'},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
{{
|
||||
name = x.py_full_name
|
||||
is_abstract_type = x.is_abstract_type
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if is_abstract_type}}(metaclass=abc.ABCMeta){{end}}:
|
||||
{{~if x.is_abstract_type~}}
|
||||
_childrenTypes = None
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
childrenTypes = {{name}}._childrenTypes
|
||||
if not childrenTypes:
|
||||
childrenTypes = {{name}}._childrenTypes = {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
'{{child.name}}': {{child.py_full_name}},
|
||||
{{~end~}}
|
||||
}
|
||||
type = _json_['__type__']
|
||||
child = {{name}}._childrenTypes.get(type)
|
||||
if child != None:
|
||||
return child(_json_)
|
||||
else:
|
||||
raise Exception()
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.py_full_name}}.__init__(self, _json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{py3_deserialize_field ('self.' + field.py_style_name) '_json_' field.name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~if export_fields.empty?}}
|
||||
pass
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
{{
|
||||
name = x.py_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~if x.is_map_table ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataMap = {}
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
self._dataMap[_v.{{x.index_field.py_style_name}}] = _v
|
||||
|
||||
def getDataMap(self) : return self._dataMap
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, key) : return self._dataMap.get(key)
|
||||
|
||||
{{~else~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
if (len(_json_) != 1): raise Exception('table mode=one, but size != 1')
|
||||
{{py3_deserialize_value 'self._data' '_json_[0]' value_type}}
|
||||
|
||||
def getData(self) : return self._data
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
'''
|
||||
{{field.comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
def {{field.py_style_name}}(self) : return self._data.{{field.py_style_name}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~ for table in tables ~}}
|
||||
#def {{table.name}} : return self._{{table.name}}
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, loader):
|
||||
{{~for table in tables ~}}
|
||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.output_data_file}}'));
|
||||
{{~end~}}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_buf_: ByteBuf): {{name}} {
|
||||
switch (_buf_.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: return new {{child.full_name}}(_buf_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{ts_bin_constructor ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
|
||||
for(let n = _buf_.ReadInt() ; n > 0 ; n--) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_bin_constructor '_v' '_buf_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key) }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
if (_buf_.ReadInt() != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_bin_constructor 'this._data' '_buf_' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}} }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type ByteBufLoader = (file: string) => ByteBuf
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}}}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: ByteBufLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
export class Vector2 implements ISerializable {
|
||||
|
||||
static deserializeFrom(buf: ByteBuf): Vector2 {
|
||||
var v = new Vector2()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 implements ISerializable{
|
||||
static deserializeFrom(buf: ByteBuf): Vector3 {
|
||||
var v = new Vector3()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 implements ISerializable {
|
||||
static deserializeFrom(buf: ByteBuf): Vector4 {
|
||||
var v = new Vector4()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
_buf_.WriteFloat(this.w)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_json_: any): {{name}} {
|
||||
switch (_json_.__type__) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case '{{child.name}}': return new {{child.full_name}}(_json_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_json_: any) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if !field.ctype.is_nullable~}}
|
||||
if (_json_.{{field.name}} == undefined) { throw new Error() }
|
||||
{{~end~}}
|
||||
{{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}}{
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_json_constructor '_v' '_json2_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key); }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
constructor(_json_: any) {
|
||||
if (_json_.length != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_json_constructor 'this._data' '_json_[0]' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data; }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type JsonLoader = (file: string) => any
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}};}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: JsonLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
export class Vector2 {
|
||||
static deserializeFromJson(json: any): Vector2 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
if (x == null || y == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector2(x, y)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 {
|
||||
static deserializeFromJson(json: any): Vector3 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
let z = json['z']
|
||||
if (x == null || y == null || z == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector3(x, y, z)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 {
|
||||
static deserializeFromJson(json: any): Vector4 {
|
||||
let x = json['x']
|
||||
let y = json['y']
|
||||
let z = json['z']
|
||||
let w = json['w']
|
||||
if (x == null || y == null || z == null || w == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector4(x, y, z, w)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.cs_style_name}} {get;}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : Bright.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => new Bright.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> GetAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.GetAsync(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> CreateIfNotExistAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
public static Task InsertAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.InsertAsync(key, value);
|
||||
}
|
||||
|
||||
public static Task RemoveAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public static Task PutAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.PutAsync(key, value);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<Bright.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<Bright.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.cs_style_name}} {get;}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : Bright.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = Bright.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.cs_style_name}} => new Bright.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} Get({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Get(key);
|
||||
}
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} CreateIfNotExist({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExist(key);
|
||||
}
|
||||
|
||||
public static void Insert({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Insert(key, value);
|
||||
}
|
||||
|
||||
public static void Remove({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
Table.Remove(key);
|
||||
}
|
||||
|
||||
public static void Put({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Put(key, value);
|
||||
}
|
||||
|
||||
public static {{db_cs_readonly_define_type value_ttype}} Select({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Select(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<Bright.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<Bright.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = 'IReadOnly' + name
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{x.ts_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent}} {{else}} TxnBeanBase {{end}}{
|
||||
{{~ for field in fields~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{field.internal_name}}: {{db_ts_define_type field.ctype}}
|
||||
{{~end}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields~}}
|
||||
{{db_ts_init_field field.internal_name_with_this field.log_type field.ctype }}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{~ctype = field.ctype~}}
|
||||
{{~if has_setter ctype~}}
|
||||
private static {{field.log_type}} = class extends FieldLoggerGeneric2<{{name}}, {{db_ts_define_type ctype}}> {
|
||||
constructor(self:{{name}}, value: {{db_ts_define_type ctype}}) { super(self, value) }
|
||||
|
||||
get fieldId(): number { return this.host.getObjectId() + {{field.id}} }
|
||||
|
||||
get tagId(): number { return FieldTag.{{tag_name ctype}} }
|
||||
|
||||
commit() { this.host.{{field.internal_name}} = this.value }
|
||||
|
||||
writeBlob(_buf: ByteBuf) {
|
||||
{{ts_write_blob '_buf' 'this.value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{db_ts_define_type ctype}} {
|
||||
if (this.isManaged) {
|
||||
var txn = TransactionContext.current
|
||||
if (txn == null) return {{field.internal_name_with_this}}
|
||||
let log: any = txn.getField(this.getObjectId() + {{field.id}})
|
||||
return log != null ? log.value : {{field.internal_name_with_this}}
|
||||
} else {
|
||||
return {{field.internal_name_with_this}};
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
set {{field.ts_style_name}}(value: {{db_ts_define_type ctype}}) {
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new Error()
|
||||
{{~end~}}
|
||||
if (this.isManaged) {
|
||||
let txn = TransactionContext.current!
|
||||
txn.putFieldLong(this.getObjectId() + {{field.id}}, new {{name}}.{{field.log_type}}(this, value))
|
||||
{{~if ctype.need_set_children_root~}}
|
||||
value?.initRoot(this.getRoot())
|
||||
{{~end~}}
|
||||
} else {
|
||||
{{field.internal_name_with_this}} = value
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{db_ts_define_type ctype}} { return {{field.internal_name_with_this}} }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
static serialize{{name}}Any(_buf: ByteBuf, x: {{name}}) {
|
||||
if (x == null) { _buf.WriteInt(0); return }
|
||||
_buf.WriteInt(x.getTypeId())
|
||||
x.serialize(_buf)
|
||||
}
|
||||
|
||||
deserialize{{name}}Any(_buf: ByteBuf): {{name}}{
|
||||
let x: {{name}}
|
||||
switch (_buf.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
x.deserialize(_buf)
|
||||
return x
|
||||
}
|
||||
{{~else~}}
|
||||
serialize(_buf: ByteBuf) {
|
||||
_buf.WriteNumberAsLong(this.getObjectId())
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_ts_compatible_serialize '_buf' field.internal_name_with_this field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
deserialize(_buf: ByteBuf) {
|
||||
this.setObjectId(_buf.ReadLongAsNumber())
|
||||
while(_buf.NotEmpty) {
|
||||
let _tag_ = _buf.ReadInt()
|
||||
switch (_tag_) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_ts_compatible_deserialize '_buf' field.internal_name_with_this field.ctype}}; break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId(): number { return {{name}}.ID }
|
||||
{{~end~}}
|
||||
|
||||
initChildrenRoot(root: TKey) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
{{field.internal_name_with_this}}?.initRoot(root)
|
||||
{{~end~}}
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '{{full_name}}{ '
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ '{{field.ts_style_name}}:' + {{ts_to_string ('this.' + field.ts_style_name) field.ctype}} + ','
|
||||
{{~end~}}
|
||||
+ '}'
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
class {{internal_table_type}} extends TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> {
|
||||
constructor() {
|
||||
super({{x.table_uid}}, '{{x.full_name}}')
|
||||
}
|
||||
|
||||
newValue(): {{db_ts_define_type value_ttype}} { return new {{db_ts_define_type value_ttype}}() }
|
||||
|
||||
serializeKey(buf: ByteBuf, key: {{db_ts_define_type key_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'key' key_ttype}}
|
||||
}
|
||||
|
||||
serializeValue(buf: ByteBuf, value: {{db_ts_define_type value_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'value' value_ttype}}
|
||||
}
|
||||
|
||||
deserializeKey(buf: ByteBuf): {{db_ts_define_type key_ttype}} {
|
||||
let key: {{db_ts_define_type key_ttype}}
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'key' key_ttype}}
|
||||
return key
|
||||
}
|
||||
|
||||
deserializeValue(buf: ByteBuf): {{db_ts_define_type value_ttype}} {
|
||||
let value = new {{db_ts_define_type value_ttype}}()
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'value' value_ttype}}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
static readonly _table = new {{internal_table_type}}();
|
||||
static get table(): TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> { return this._table }
|
||||
|
||||
static getAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.getAsync(key);
|
||||
}
|
||||
|
||||
static createIfNotExistAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.createIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
static insertAsync(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.insertAsync(key, value);
|
||||
}
|
||||
|
||||
static removeAsync(key: {{db_ts_define_type key_ttype}}): Promise<void> {
|
||||
return {{name}}._table.removeAsync(key);
|
||||
}
|
||||
|
||||
static put(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.putAsync(key, value);
|
||||
}
|
||||
|
||||
static selectAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.selectAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
export class {{name}} {
|
||||
static readonly tableList: TxnTable[] = [
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.table,
|
||||
{{~end}}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
{{
|
||||
is_value_type = x.is_value_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{if is_value_type}}struct{{else}}{{x.cs_class_modifier}} class{{end}} {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Serialization.BeanBase {{end}}
|
||||
{
|
||||
{{~if !is_value_type~}}
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||
{{~else if is_value_type~}}
|
||||
{{field.cs_style_name}} = default;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
if (x != null)
|
||||
{
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
_buf.WriteInt(0);
|
||||
}
|
||||
{{~else~}}
|
||||
x.Serialize(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
{{full_name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.ID: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
{{~else~}}
|
||||
var x = new {{full_name}}();
|
||||
x.Deserialize(_buf);
|
||||
{{~end~}}
|
||||
return x;
|
||||
}
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
public const int ID = {{x.id}};
|
||||
public override int GetTypeId() => ID;
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_serialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Protocol
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
public const int ID = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_serialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_deserialize '_buf' field.cs_style_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in fields ~}}
|
||||
+ "{{field.cs_style_name}}:" + {{cs_to_string field.cs_style_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
targ_type = x.targ_type
|
||||
tres_type = x.tres_type
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Rpc<{{cs_define_type targ_type}}, {{cs_define_type tres_type}}>
|
||||
{
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public const int ID = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{full_name}}{%{ {{arg:{Arg},res:{Res} }} }%}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator>
|
||||
{
|
||||
{{~ for proto in protos ~}}
|
||||
[{{proto.full_name}}.ID] = () => new {{proto.full_name}}(),
|
||||
{{~end~}}
|
||||
|
||||
{{~ for rpc in rpcs ~}}
|
||||
[{{rpc.full_name}}.ID] = () => new {{rpc.full_name}}(),
|
||||
{{~end~}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,258 @@
|
|||
{{
|
||||
consts = x.consts
|
||||
enums = x.enums
|
||||
beans = x.beans
|
||||
protos = x.protos
|
||||
}}
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local tinsert = table.insert
|
||||
|
||||
local function SimpleClass()
|
||||
local class = {}
|
||||
class.__index = class
|
||||
class.New = function(...)
|
||||
local ctor = class.ctor
|
||||
local o = ctor and ctor(...) or {}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
return class
|
||||
end
|
||||
|
||||
|
||||
local function get_map_size(m)
|
||||
local n = 0
|
||||
for _ in pairs(m) do
|
||||
n = n + 1
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local consts =
|
||||
{
|
||||
{{~ for c in consts ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} {{item.type}}
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} int
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local writeBool = methods.writeBool
|
||||
local readByte = methods.readByte
|
||||
local writeByte = methods.writeByte
|
||||
local readShort = methods.readShort
|
||||
local writeShort = methods.writeShort
|
||||
local readFshort = methods.readFshort
|
||||
local writeInt = methods.writeInt
|
||||
local readInt = methods.readInt
|
||||
local writeFint = methods.writeFint
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local writeLong = methods.writeLong
|
||||
local readFlong = methods.readFlong
|
||||
local writeFlong = methods.writeFlong
|
||||
local readFloat = methods.readFloat
|
||||
local writeFloat = methods.writeFloat
|
||||
local readDouble = methods.readDouble
|
||||
local writeDouble = methods.writeDouble
|
||||
local readSize = methods.readSize
|
||||
local writeSize = methods.writeSize
|
||||
|
||||
local readString = methods.readString
|
||||
local writeString = methods.writeString
|
||||
local readBytes = methods.readBytes
|
||||
local writeBytes = methods.writeBytes
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector2(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector3(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
writeFloat(bs, v.z)
|
||||
end
|
||||
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function writeVector4(bs, v)
|
||||
writeFloat(bs, v.x)
|
||||
writeFloat(bs, v.y)
|
||||
writeFloat(bs, v.z)
|
||||
writeFloat(bs, v.w)
|
||||
end
|
||||
|
||||
local function writeList(bs, list, keyFun)
|
||||
writeSize(bs, #list)
|
||||
for _, v in pairs(list) do
|
||||
keyFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local writeArray = writeList
|
||||
local readArray = readList
|
||||
|
||||
local function writeSet(bs, set, keyFun)
|
||||
writeSize(bs, #set)
|
||||
for _, v in ipairs(set) do
|
||||
keyFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function writeMap(bs, map, keyFun, valueFun)
|
||||
writeSize(bs, get_map_size(map))
|
||||
for k, v in pairs(map) do
|
||||
keyFun(bs, k)
|
||||
valueFun(bs, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
||||
|
||||
local default_vector2 = {x=0,y=0}
|
||||
local default_vector3 = {x=0,y=0,z=0}
|
||||
local default_vector4 = {x=0,y=0,z=0,w=0}
|
||||
|
||||
local beans = {}
|
||||
{{ for bean in beans }}
|
||||
do
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{bean.id}}
|
||||
class._name = '{{bean.full_name}}'
|
||||
local id2name = { {{for c in bean.hierarchy_not_abstract_children}} [{{c.id}}] = '{{c.full_name}}', {{end}} }
|
||||
{{if bean.is_abstract_type}}
|
||||
class._serialize = function(bs, self)
|
||||
writeInt(bs, {{bean.id}})
|
||||
beans[self._name]._serialize(bs, self)
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local id = readInt(bs)
|
||||
return beans[id2name[id]]._deserialize(bs)
|
||||
end
|
||||
{{else}}
|
||||
class._serialize = function(bs, self)
|
||||
{{~ for field in bean.hierarchy_fields ~}}
|
||||
{{lua_serialize_while_nil 'bs' ('self.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in bean.hierarchy_fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{else}} readNullableBool(bs) {{end}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
{{end}}
|
||||
beans[class._name] = class
|
||||
end
|
||||
{{end}}
|
||||
|
||||
local protos = { }
|
||||
{{ for proto in protos }}
|
||||
do
|
||||
---@class {{proto.full_name}}
|
||||
{{~ for field in proto.fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{proto.id}}
|
||||
class._name = '{{proto.full_name}}'
|
||||
class._serialize = function(bs, self)
|
||||
{{~ for field in proto.fields ~}}
|
||||
{{lua_serialize_while_nil 'bs' ('self.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
end
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in proto.fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{else}} readNullableBool(bs) {{end}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
protos[class._id] = class
|
||||
protos[class._name] = class
|
||||
end
|
||||
{{end}}
|
||||
|
||||
return { consts = consts, enums = enums, beans = beans, protos = protos }
|
||||
end
|
||||
|
||||
return { InitTypes = InitTypes}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
{{
|
||||
is_value_type = x.is_value_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
}}
|
||||
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if parent_def_type}}{{x.parent}}{{else}}BeanBase{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static serializeTo(_buf_ : ByteBuf, _bean_ : {{name}}) {
|
||||
_buf_.WriteInt(_bean_.getTypeId())
|
||||
_bean_.serialize(_buf_)
|
||||
}
|
||||
|
||||
static deserializeFrom(_buf_ : ByteBuf) : {{name}} {
|
||||
let _bean_ :{{name}}
|
||||
switch (_buf_.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: _bean_ = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
_bean_.deserialize(_buf_)
|
||||
return _bean_
|
||||
}
|
||||
{{else}}
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId() { return {{name}}.ID }
|
||||
{{~end~}}
|
||||
|
||||
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
serialize(_buf_ : ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super.serialize(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_serialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
deserialize(_buf_ : ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super.deserialize(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_deserialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '{{full_name}}{ '
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
+ '{{field.ts_style_name}}:' + this.{{field.ts_style_name}} + ','
|
||||
{{~end~}}
|
||||
+ '}'
|
||||
}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} extends Protocol {
|
||||
static readonly ID = {{x.id}}
|
||||
getTypeId() { return {{name}}.ID }
|
||||
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
serialize(_buf_ : ByteBuf) {
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_serialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
deserialize(_buf_ : ByteBuf) {
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_deserialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '{{full_name}}{ '
|
||||
{{~ for field in fields ~}}
|
||||
+ '{{field.ts_style_name}}:' + this.{{field.ts_style_name}} + ','
|
||||
{{~end~}}
|
||||
+ '}'
|
||||
}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue