bean.sbn 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {{~if ___top_module != ''~}}
  2. package {{__top_module}};
  3. {{~end~}}
  4. {{~
  5. go_full_name = full_name __this
  6. parent_def_type = __this.parent_def_type
  7. is_abstract_type = __this.is_abstract_type
  8. hierarchy_fields = __this.hierarchy_export_fields
  9. hierarchy_not_abstract_children = __this.hierarchy_not_abstract_children
  10. ~}}
  11. {{collect_import __this}}
  12. type {{go_full_name}} struct {
  13. {{~for field in hierarchy_fields ~}}
  14. {{format_field_name __code_style field.name}} {{declaring_type_name field.ctype}}
  15. {{~end~}}
  16. }
  17. const TypeId_{{go_full_name}} = {{__this.id}}
  18. func (*{{go_full_name}}) GetTypeId() int32 {
  19. return {{__this.id}}
  20. }
  21. {{~if is_abstract_type~}}
  22. func New{{go_full_name}}(_buf map[string]interface{}) (interface{}, error) {
  23. var id string
  24. var _ok_ bool
  25. if id, _ok_ = _buf["$type"].(string) ; !_ok_ {
  26. return nil, errors.New("type id missing")
  27. }
  28. switch id {
  29. {{~for child in hierarchy_not_abstract_children~}}
  30. case "{{impl_data_type child __this}}": _v, err := New{{full_name child}}(_buf); if err != nil { return nil, errors.New("{{full_name child|string.downcase}}") } else { return _v, nil }
  31. {{~end~}}
  32. default: return nil, errors.New("unknown type id")
  33. }
  34. }
  35. {{~else~}}
  36. func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
  37. _v = &{{go_full_name}}{}
  38. {{~for field in hierarchy_fields ~}}
  39. {{deserialize_field field.ctype ("_v." + (format_field_name __code_style field.name)) field.name '_buf'}}
  40. {{~end~}}
  41. return
  42. }
  43. {{~end~}}