初始化工程
This commit is contained in:
54
Config/Tools/Luban/Templates/go-bin/bean.sbn
Normal file
54
Config/Tools/Luban/Templates/go-bin/bean.sbn
Normal file
@@ -0,0 +1,54 @@
|
||||
{{~if ___top_module != ''~}}
|
||||
package {{__top_module}};
|
||||
{{~end~}}
|
||||
|
||||
{{~
|
||||
go_full_name = full_name __this
|
||||
parent_def_type = __this.parent_def_type
|
||||
is_abstract_type = __this.is_abstract_type
|
||||
hierarchy_fields = __this.hierarchy_export_fields
|
||||
hierarchy_not_abstract_children = __this.hierarchy_not_abstract_children
|
||||
~}}
|
||||
|
||||
import (
|
||||
"{{__luban_module_name}}"
|
||||
)
|
||||
|
||||
{{collect_import __this}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{format_field_name __code_style field.name}} {{declaring_type_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
const TypeId_{{go_full_name}} = {{__this.id}}
|
||||
|
||||
func (*{{go_full_name}}) GetTypeId() int32 {
|
||||
return {{__this.id}}
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func New{{go_full_name}}(_buf *luban.ByteBuf) (interface{}, error) {
|
||||
var id int32
|
||||
var err error
|
||||
if id, err = _buf.ReadInt() ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: _v, err := New{{full_name child}}(_buf); if err != nil { return nil, errors.New("{{child.full_name|string.downcase}}") } else { return _v, nil }
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
func New{{go_full_name}}(_buf *luban.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||
_v = &{{go_full_name}}{}
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{deserialize_field field.ctype ("_v." + (format_field_name __code_style field.name)) '_buf' 'err'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
{{~end~}}
|
||||
116
Config/Tools/Luban/Templates/go-bin/table.sbn
Normal file
116
Config/Tools/Luban/Templates/go-bin/table.sbn
Normal file
@@ -0,0 +1,116 @@
|
||||
{{~if ___top_module != ''~}}
|
||||
package {{__top_module}};
|
||||
{{~end~}}
|
||||
|
||||
{{~
|
||||
go_full_name = full_name __this
|
||||
key_type = __this.key_ttype
|
||||
value_type = __this.value_ttype
|
||||
index_field = __this.index_field
|
||||
~}}
|
||||
|
||||
import "{{__luban_module_name}}"
|
||||
|
||||
{{~if __this.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{declaring_type_name key_type}}]{{declaring_type_name value_type}}
|
||||
_dataList []{{declaring_type_name value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *luban.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{declaring_type_name value_type}}, 0, size)
|
||||
dataMap := make(map[{{declaring_type_name key_type}}]{{declaring_type_name value_type}})
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := New{{full_name value_type.def_bean}}(_buf); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.def_bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{full_name child}}) ; __is {
|
||||
dataMap[__v.{{format_field_name __code_style index_field.name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{format_field_name __code_style index_field.name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{declaring_type_name key_type}}]{{declaring_type_name value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{declaring_type_name value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{declaring_type_name key_type}}) {{declaring_type_name value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
{{~else if __this.is_list_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataList []{{declaring_type_name value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *luban.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{declaring_type_name value_type}}, 0, size)
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := New{{full_name value_type.def_bean}}(_buf); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{declaring_type_name value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(index int) {{declaring_type_name value_type}} {
|
||||
return table._dataList[index]
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import "errors"
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{declaring_type_name value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *luban.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 := New{{full_name value_type.def_bean}}(_buf); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{declaring_type_name value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
33
Config/Tools/Luban/Templates/go-bin/tables.sbn
Normal file
33
Config/Tools/Luban/Templates/go-bin/tables.sbn
Normal file
@@ -0,0 +1,33 @@
|
||||
{{~if __namespace != ''~}}
|
||||
package {{__namespace}};
|
||||
{{~end~}}
|
||||
|
||||
import (
|
||||
"{{__luban_module_name}}"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type ByteBufLoader func(string) (*luban.ByteBuf, error)
|
||||
|
||||
type {{__name}} struct {
|
||||
{{~for table in __tables ~}}
|
||||
{{table.name}} *{{full_name table}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader ByteBufLoader) (*{{__name}}, error) {
|
||||
var err error
|
||||
var buf *luban.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{{full_name table}}(buf) ; err != nil {
|
||||
return nil, errors.Join(errors.New("failed to load {{table.name}}"), err)
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user