OLD | NEW |
1 {#--- Begin #} | 1 {#--- Begin #} |
2 {%- import "encoding_macros.tmpl" as encoding_macros %} | 2 {%- import "encoding_macros.tmpl" as encoding_macros %} |
3 {%- macro struct_def(struct, typepkg, package) %} | 3 {%- macro struct_def(struct, typepkg, package) %} |
4 {#--- Enums #} | 4 {#--- Enums #} |
5 {%- from "enum_definition.tmpl" import enum_def %} | 5 {%- from "enum_definition.tmpl" import enum_def %} |
6 {%- for enum in struct.enums %} | 6 {%- for enum in struct.enums %} |
7 {{enum_def(enum, typepkg, package)}} | 7 {{enum_def(enum, typepkg, package)}} |
8 {%- endfor %} | 8 {%- endfor %} |
9 | 9 |
10 class {{struct|name}} extends bindings.Struct { | 10 class {{struct|name}} extends bindings.Struct { |
11 static const List<bindings.StructDataHeader> kVersions = const [ | 11 static const List<bindings.StructDataHeader> kVersions = const [ |
12 {%- for version in struct.versions %} | 12 {%- for version in struct.versions %} |
13 const bindings.StructDataHeader({{version.num_bytes}}, {{version.version}}){
% if not loop.last %},{% endif %} | 13 const bindings.StructDataHeader({{version.num_bytes}}, {{version.version}}){
% if not loop.last %},{% endif %} |
14 {%- endfor %} | 14 {%- endfor %} |
15 ]; | 15 ]; |
16 | 16 |
17 {#--- Constants #} | 17 {#--- Constants #} |
18 {%- for constant in struct.constants %} | 18 {%- for constant in struct.constants %} |
19 static const {{constant.kind|dart_type}} {{constant|name}} = {{constant.resolv
ed_value}}; | 19 static const {{constant.kind|dart_type}} {{constant|name}} = {{constant.resolv
ed_value}}; |
20 {%- endfor %} | 20 {%- endfor %} |
21 | 21 |
22 {#--- initDefaults() #} | 22 {#--- initDefaults() #} |
23 {%- for packed_field in struct.packed.packed_fields %} | 23 {%- for packed_field in struct.packed.packed_fields %} |
24 {{packed_field.field.kind|dart_type}} {{packed_field.field|name}} = {{packed_f
ield.field|default_value}}; | 24 {{packed_field.field.kind|dart_type}} {{packed_field.field|name}} = {{packed_f
ield.field|default_value}}; |
25 {%- endfor %} | 25 {%- endfor %} |
26 | 26 |
27 {{struct|name}}() : super(kVersions.last.size); | 27 {{struct|name}}() : super(kVersions.last.size); |
28 | 28 |
| 29 {{struct|name}}.init( |
| 30 {%- for packed_field in struct.packed.packed_fields %} |
| 31 {{packed_field.field.kind|dart_type}} this.{{packed_field.field|name}}{% if
not loop.last %}, {% endif %} |
| 32 {%- endfor %} |
| 33 ) : super(kVersions.last.size); |
| 34 |
29 static {{struct|name}} deserialize(bindings.Message message) { | 35 static {{struct|name}} deserialize(bindings.Message message) { |
30 var decoder = new bindings.Decoder(message); | 36 var decoder = new bindings.Decoder(message); |
31 var result = decode(decoder); | 37 var result = decode(decoder); |
32 if (decoder.excessHandles != null) { | 38 if (decoder.excessHandles != null) { |
33 decoder.excessHandles.forEach((h) => h.close()); | 39 decoder.excessHandles.forEach((h) => h.close()); |
34 } | 40 } |
35 return result; | 41 return result; |
36 } | 42 } |
37 | 43 |
38 static {{struct|name}} decode(bindings.Decoder decoder0) { | 44 static {{struct|name}} decode(bindings.Decoder decoder0) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 {%- endfor %} | 110 {%- endfor %} |
105 return map; | 111 return map; |
106 {%- else %} | 112 {%- else %} |
107 throw new bindings.MojoCodecError( | 113 throw new bindings.MojoCodecError( |
108 'Object containing handles cannot be encoded to JSON.'); | 114 'Object containing handles cannot be encoded to JSON.'); |
109 {%- endif %} | 115 {%- endif %} |
110 } | 116 } |
111 } | 117 } |
112 | 118 |
113 {%- endmacro %} | 119 {%- endmacro %} |
OLD | NEW |