【特性】cfg typescript,lua,python,go均新增对可空bean支持
parent
dcaee15c0e
commit
ccea1359d3
|
|
@ -124,13 +124,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
var bean = type.Type;
|
var bean = type.Type;
|
||||||
if (bean.IsAbstractType)
|
if (bean.IsAbstractType)
|
||||||
{
|
{
|
||||||
// null 时特殊处理
|
line.Append($"{{ _name='{type.ImplType.Name}',");
|
||||||
if (type.ImplType == null)
|
|
||||||
{
|
|
||||||
line.Append("nil");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
line.Append($"{{ _name='{type.ImplType.FullName}',");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,6 @@ func NewChild{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch id {
|
switch id {
|
||||||
case 0 : return nil, nil
|
|
||||||
{{~for child in hierarchy_not_abstract_children~}}
|
{{~for child in hierarchy_not_abstract_children~}}
|
||||||
case {{child.id}}: return New{{child.go_full_name}}(_buf);
|
case {{child.id}}: return New{{child.go_full_name}}(_buf);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ local function InitTypes(methods)
|
||||||
{{~if bean.is_abstract_type~}}
|
{{~if bean.is_abstract_type~}}
|
||||||
class._deserialize = function(bs)
|
class._deserialize = function(bs)
|
||||||
local id = readInt(bs)
|
local id = readInt(bs)
|
||||||
if id ~= 0 then return beans[id2name[id]]._deserialize(bs) end
|
return beans[id2name[id]]._deserialize(bs)
|
||||||
end
|
end
|
||||||
{{~else~}}
|
{{~else~}}
|
||||||
class._deserialize = function(bs)
|
class._deserialize = function(bs)
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,11 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{end}}:
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
type = _json_['__type__']
|
type = _json_['__type__']
|
||||||
if type != None:
|
|
||||||
child = {{name}}._childrenTypes.get(type)
|
child = {{name}}._childrenTypes.get(type)
|
||||||
if child != None:
|
if child != None:
|
||||||
return child(_json_)
|
return child(_json_)
|
||||||
else:
|
else:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
else:
|
|
||||||
return None
|
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
def __init__(self, _json_):
|
def __init__(self, _json_):
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,11 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
type = _json_['__type__']
|
type = _json_['__type__']
|
||||||
if type != None:
|
|
||||||
child = {{name}}._childrenTypes.get(type)
|
child = {{name}}._childrenTypes.get(type)
|
||||||
if child != None:
|
if child != None:
|
||||||
return child(_json_)
|
return child(_json_)
|
||||||
else:
|
else:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
else:
|
|
||||||
return None
|
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
def __init__(self, _json_):
|
def __init__(self, _json_):
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||||
{{~if x.is_abstract_type~}}
|
{{~if x.is_abstract_type~}}
|
||||||
static constructorFrom(_buf_: Bright.Serialization.ByteBuf): {{name}} {
|
static constructorFrom(_buf_: Bright.Serialization.ByteBuf): {{name}} {
|
||||||
switch (_buf_.ReadInt())
|
switch (_buf_.ReadInt()) {
|
||||||
{
|
|
||||||
case 0: return null
|
|
||||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||||
case {{child.id}}: return new {{child.full_name}}(_buf_)
|
case {{child.id}}: return new {{child.full_name}}(_buf_)
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
@ -98,7 +96,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
|
||||||
value_type = x.value_ttype
|
value_type = x.value_ttype
|
||||||
}}
|
}}
|
||||||
{{x.typescript_namespace_begin}}
|
{{x.typescript_namespace_begin}}
|
||||||
export class {{name}}{
|
export class {{name}} {
|
||||||
{{~if x.is_map_table ~}}
|
{{~if x.is_map_table ~}}
|
||||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||||
private _dataList: {{ts_define_type value_type}}[]
|
private _dataList: {{ts_define_type value_type}}[]
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
|
||||||
{{~if x.is_abstract_type~}}
|
{{~if x.is_abstract_type~}}
|
||||||
static constructorFrom(_json_: any): {{name}} {
|
static constructorFrom(_json_: any): {{name}} {
|
||||||
switch (_json_.__type__) {
|
switch (_json_.__type__) {
|
||||||
case null: return null
|
|
||||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||||
case '{{child.name}}': return new {{child.full_name}}(_json_)
|
case '{{child.name}}': return new {{child.full_name}}(_json_)
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,5 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
return type.Apply(UnderringVisitor, jsonFieldName, fieldName);
|
return type.Apply(UnderringVisitor, jsonFieldName, fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(TBean type, string bufName, string fieldName)
|
|
||||||
{
|
|
||||||
return type.Apply(UnderringVisitor, bufName, fieldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,5 @@ namespace Luban.Job.Common.TypeVisitors
|
||||||
return type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName);
|
return type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, byteBufName, fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 设计需要简化,现在造成多态bean的可空与其他字段类型不一样,而需要单独处理
|
|
||||||
// 多态bean不浪费一个字段,直接用typeid==0表示空
|
|
||||||
// 因此不跟普通字段一样,需要 ReadBool()来区别是否为空
|
|
||||||
public override string Accept(TBean type, string bufName, string fieldName)
|
|
||||||
{
|
|
||||||
return type.Apply(TypescriptBinUnderingConstructorVisitor.Ins, bufName, fieldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TMap type, string jsonVarName, string fieldName)
|
public string Accept(TMap type, string jsonVarName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _entry_ of {jsonVarName}) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, "_entry_[0]", "_k")} let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, "_entry_[1]", "_v")}; {fieldName}.set(_k, _v); }}";
|
return $"{fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(var _entry_ of {jsonVarName}) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, "_entry_[0]", "_k")}; let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, "_entry_[1]", "_v")}; {fieldName}.set(_k, _v); }}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ namespace Luban.Job.Common.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TMap type, string bufVarName, string fieldName)
|
public string Accept(TMap type, string bufVarName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{ {fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(let i = 0, n = {bufVarName}.ReadSize() ; i < n ; i++) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, bufVarName, "_k")} let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, bufVarName, "_v")} {fieldName}.set(_k, _v); }} }}";
|
return $"{{ {fieldName} = new {type.Apply(TypescriptDefineTypeName.Ins)}(); for(let i = 0, n = {bufVarName}.ReadSize() ; i < n ; i++) {{ let _k:{type.KeyType.Apply(TypescriptDefineTypeName.Ins)}; {type.KeyType.Apply(this, bufVarName, "_k")}; let _v:{type.ValueType.Apply(TypescriptDefineTypeName.Ins)}; {type.ValueType.Apply(this, bufVarName, "_v")} {fieldName}.set(_k, _v); }} }}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue