diff --git a/tpl/codegen_bundle.twig b/tpl/codegen_bundle.twig index cbe6590..0314dda 100644 --- a/tpl/codegen_bundle.twig +++ b/tpl/codegen_bundle.twig @@ -18,19 +18,36 @@ var _ = sort.SearchInts func CreateById(classId uint32) (meta.IMetaStruct, error) { switch classId { - %create_struct_by_crc28% + +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaStruct')~%} + case {{u.object.classid}}: { return New{{u.object.name}}(), nil } +{%- endif ~%} +{%- endfor ~%} + default : return nil, errors.Errorf("Can't find struct for class id %d", classId) } } func CreateByName(name string) (meta.IMetaStruct, error) { switch name { - %create_struct_by_name% + +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaStruct')~%} + case "{{u.object.name}}": { return New{{u.object.name}}(), nil } +{%- endif ~%} +{%- endfor ~%} + default : return nil, errors.Errorf("Can't find struct for name %s", name) } } func CreateRPC(code uint32)(meta.IRPC, error) { switch code { -%create_rpc_by_code% + +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaRPC')~%} + case {{u.object.code}}: { return New{{u.object.name}}(), nil } +{%- endif ~%} +{%- endfor ~%} default: return nil, errors.Errorf("Can't find rpc for code %d", code) } } diff --git a/tpl/macro.twig b/tpl/macro.twig index bd5d5a4..d9a3f0d 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -146,7 +146,7 @@ map[string]map[string]string{ {% macro decl_struct_fields(o) %} {%- for f in o.fields ~%} -{{f.name|ucfirst}} {{f.type|go_type(f.tokens)}} {{f.name|first != '_' ? '`json:"' ~ f.name ~ '"`'}} +{{f.name|ucfirst}} {{f.type|go_type(f.tokens)}} {{_self.field_annotations(o, f)}} {%- endfor ~%} {%if has_token(o, 'bitfields') %} @@ -155,6 +155,12 @@ fieldsMask meta.FieldsMask //@bitfields support {% endmacro %} +{% macro field_annotations(o, f) %} +{%- if f.name|first != '_' -%} +`json:"{{f.name}}" {% if has_token(o, 'table') -%} db:"{{f.name}}"{%- endif -%}` +{%- endif -%} +{% endmacro %} + {% macro struct_reset_fields(o) %} {%- if o.parent ~%}