bean.sbn 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. {{~if __namespace_with_top_module != ''~}}
  2. package {{__namespace_with_top_module}};
  3. {{~end~}}
  4. import luban.*;
  5. {{~
  6. parent_def_type = __this.parent_def_type
  7. export_fields = __this.export_fields
  8. hierarchy_export_fields = __this.hierarchy_export_fields
  9. ~}}
  10. {{~if __this.comment != '' ~}}
  11. /**
  12. * {{escape_comment __this.comment}}
  13. */
  14. {{~end~}}
  15. public {{class_modifier __this}} class {{__name}} extends {{if parent_def_type}}{{__this.parent_def_type.full_name_with_top_module}}{{else}}AbstractBean{{end}} {
  16. public {{__name}}(ByteBuf _buf) {
  17. {{~if parent_def_type~}}
  18. super(_buf);
  19. {{~end~}}
  20. {{~ for field in export_fields ~}}
  21. {{deserialize '_buf' (format_field_name __code_style field.name) field.ctype}}
  22. {{~end~}}
  23. }
  24. public static {{__name}} deserialize(ByteBuf _buf) {
  25. {{~if __this.is_abstract_type~}}
  26. switch (_buf.readInt()) {
  27. {{~for child in __this.hierarchy_not_abstract_children~}}
  28. case {{child.full_name_with_top_module}}.__ID__: return new {{child.full_name_with_top_module}}(_buf);
  29. {{~end~}}
  30. default: throw new SerializationException();
  31. }
  32. {{~else~}}
  33. return new {{__this.full_name_with_top_module}}(_buf);
  34. {{~end~}}
  35. }
  36. {{~ for field in export_fields ~}}
  37. {{~if field.comment != '' ~}}
  38. /**
  39. * {{escape_comment field.comment}}
  40. */
  41. {{~end~}}
  42. public final {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}};
  43. {{~end~}}
  44. {{~if !__this.is_abstract_type~}}
  45. public static final int __ID__ = {{__this.id}};
  46. @Override
  47. public int getTypeId() { return __ID__; }
  48. {{~end~}}
  49. @Override
  50. public String toString() {
  51. return "{{full_name}}{ "
  52. {{~for field in hierarchy_export_fields ~}}
  53. + "{{format_field_name __code_style field.name}}:" + {{format_field_name __code_style field.name}} + ","
  54. {{~end~}}
  55. + "}";
  56. }
  57. }