From af0e8119c1b43721e472815e6d01d7f18bcaba39 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 8 Dec 2022 12:34:39 +0300 Subject: [PATCH] Gradually adding support for all features --- tpl/macro.twig | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/tpl/macro.twig b/tpl/macro.twig index 209a309..0c2ac66 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -11,10 +11,85 @@ {% endmacro %} {% macro decl_struct(o) %} + +//============================== +type {{o.name}} struct { +{% if o.parent %} +{{o.parent.name}} +{% endif %} + %fields% +} +var _{{o.name}}_class_props map[string]string +var _{{o.name}}_class_fields []string = %fields_names% +var _{{o.name}}_fields_props meta.ClassFieldsProps +func init() { + _{{o.name}}_class_props = %class_props% + _{{o.name}}_fields_props = %fields_props% +} +func {{o.name}}_CLASS_ID() uint32 { + return {{o.classid}} +} +type I{{o.name}} interface { + meta.IMetaStruct + Ptr{{o.name}}() *{{o.name}} +} +func (*{{o.name}}) CLASS_ID() uint32 { + return %class_id% +} +func (*{{o.name}}) CLASS_NAME() string { + return "{{o.name}}" +} +func (*{{o.name}}) CLASS_PROPS() *map[string]string { + return &_{{o.name}}_class_props +} +func (*{{o.name}}) CLASS_FIELDS() []string { + return _{{o.name}}_class_fields +} +func (*{{o.name}}) CLASS_FIELDS_PROPS() *meta.ClassFieldsProps { + return &_{{o.name}}_fields_props +} +//convenience getter +func Ptr{{o.name}}(m meta.IMetaStruct) *{{o.name}} { + p, ok := m.(I{{o.name}}) + if !ok { + return nil + } + return p.Ptr{{o.name}}() +} +func (self *{{o.name}}) Ptr{{o.name}}() *{{o.name}} { + return self +} +func New{{o.name}}() *{{o.name}} { + item := new ({{o.name}}) + item.Reset() + return item +} +func (self *{{o.name}}) Reset() { + %fields_reset% +} +func (self *{{o.name}}) Read(reader meta.Reader) error { + return meta.ReadStruct(reader, self, "") +} +func (self *{{o.name}}) ReadFields(reader meta.Reader) error { + self.Reset() + %read_buffer% + return nil +} +func (self *{{o.name}}) Write(writer meta.Writer) error { + return meta.WriteStruct(writer, self, "") +} +func (self *{{o.name}}) WriteFields(writer meta.Writer) error { + %write_buffer% + return nil +} +%ext_methods% +%analytics_methods% + {% endmacro %} {% macro decl_enum(o) %} +//============================== const ( {{_self.enum_consts(o)}} ) @@ -53,13 +128,13 @@ func New{{o.name}}ByName(name string) ({{o.name}}, error) { {% endmacro %} {% macro enum_values_list(o) %} -{%- for v in o.values -%} +{%- for v in o.values|sort ~%} {{v}}, {%- endfor ~%} {% endmacro %} {% macro enum_values_map(o) %} -{%- for k,v in o.values -%} +{%- for k,v in o.values ~%} "{{k}}" : {{v}}, {%- endfor ~%} {% endmacro %}