【特性】cfg typescript,lua,python,go均新增对可空bean支持

main
walon 2021-06-29 20:10:34 +08:00
parent dcaee15c0e
commit ccea1359d3
11 changed files with 14 additions and 43 deletions

View File

@ -124,13 +124,7 @@ namespace Luban.Job.Cfg.DataVisitors
var bean = type.Type;
if (bean.IsAbstractType)
{
// null 时特殊处理
if (type.ImplType == null)
{
line.Append("nil");
return;
}
line.Append($"{{ _name='{type.ImplType.FullName}',");
line.Append($"{{ _name='{type.ImplType.Name}',");
}
else
{

View File

@ -118,7 +118,6 @@ func NewChild{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err
return
}
switch id {
case 0 : return nil, nil
{{~for child in hierarchy_not_abstract_children~}}
case {{child.id}}: return New{{child.go_full_name}}(_buf);
{{~end~}}

View File

@ -148,7 +148,7 @@ local function InitTypes(methods)
{{~if bean.is_abstract_type~}}
class._deserialize = function(bs)
local id = readInt(bs)
if id ~= 0 then return beans[id2name[id]]._deserialize(bs) end
return beans[id2name[id]]._deserialize(bs)
end
{{~else~}}
class._deserialize = function(bs)

View File

@ -82,14 +82,11 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{end}}:
{{~end~}}
}
type = _json_['__type__']
if type != None:
child = {{name}}._childrenTypes.get(type)
if child != None:
return child(_json_)
else:
raise Exception()
else:
return None
{{~end~}}
def __init__(self, _json_):

View File

@ -82,14 +82,11 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if
{{~end~}}
}
type = _json_['__type__']
if type != None:
child = {{name}}._childrenTypes.get(type)
if child != None:
return child(_json_)
else:
raise Exception()
else:
return None
{{~end~}}
def __init__(self, _json_):

View File

@ -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}} {
{{~if x.is_abstract_type~}}
static constructorFrom(_buf_: Bright.Serialization.ByteBuf): {{name}} {
switch (_buf_.ReadInt())
{
case 0: return null
switch (_buf_.ReadInt()) {
{{~ for child in x.hierarchy_not_abstract_children~}}
case {{child.id}}: return new {{child.full_name}}(_buf_)
{{~end~}}
@ -98,7 +96,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
value_type = x.value_ttype
}}
{{x.typescript_namespace_begin}}
export class {{name}}{
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}}[]

View File

@ -38,7 +38,6 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
{{~if x.is_abstract_type~}}
static constructorFrom(_json_: any): {{name}} {
switch (_json_.__type__) {
case null: return null
{{~ for child in x.hierarchy_not_abstract_children~}}
case '{{child.name}}': return new {{child.full_name}}(_json_)
{{~end~}}

View File

@ -32,10 +32,5 @@ namespace Luban.Job.Cfg.TypeVisitors
return type.Apply(UnderringVisitor, jsonFieldName, fieldName);
}
}
public override string Accept(TBean type, string bufName, string fieldName)
{
return type.Apply(UnderringVisitor, bufName, fieldName);
}
}
}

View File

@ -18,13 +18,5 @@ namespace Luban.Job.Common.TypeVisitors
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);
}
}
}

View File

@ -127,7 +127,7 @@ namespace Luban.Job.Cfg.TypeVisitors
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); }}";
}

View File

@ -138,7 +138,7 @@ namespace Luban.Job.Common.TypeVisitors
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); }} }}";
}