OLD | NEW |
1 {%- set class_name = struct.name ~ "_Data" -%} | 1 {%- set class_name = struct.name ~ "_Data" -%} |
2 | 2 |
3 class {{class_name}} { | 3 class {{class_name}} { |
4 public: | 4 public: |
5 static {{class_name}}* New(mojo::internal::Buffer* buf); | 5 static {{class_name}}* New(mojo::internal::Buffer* buf); |
6 | 6 |
7 static bool Validate(const void* data, | 7 static bool Validate(const void* data, |
8 mojo::internal::BoundsChecker* bounds_checker); | 8 mojo::internal::BoundsChecker* bounds_checker); |
9 | 9 |
10 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles); | 10 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles); |
11 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles); | 11 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles); |
12 | 12 |
| 13 {% from "enum_macros.tmpl" import enum_data_decl -%} |
| 14 {#--- Enums #} |
| 15 {%- for enum in struct.enums -%} |
| 16 {{enum_data_decl(enum)|indent(2)}} |
| 17 {%- endfor %} |
| 18 |
13 mojo::internal::StructHeader header_; | 19 mojo::internal::StructHeader header_; |
14 {%- for packed_field in struct.packed.packed_fields %} | 20 {%- for packed_field in struct.packed.packed_fields %} |
15 {%- set name = packed_field.field.name %} | 21 {%- set name = packed_field.field.name %} |
16 {%- set kind = packed_field.field.kind %} | 22 {%- set kind = packed_field.field.kind %} |
17 {%- if kind.spec == 'b' %} | 23 {%- if kind.spec == 'b' %} |
18 uint8_t {{name}} : 1; | 24 uint8_t {{name}} : 1; |
19 {%- elif kind|is_enum_kind %} | |
20 int32_t {{name}}; | |
21 {%- else %} | 25 {%- else %} |
22 {{kind|cpp_field_type}} {{name}}; | 26 {{kind|cpp_field_type}} {{name}}; |
23 {%- endif %} | 27 {%- endif %} |
24 {%- if not loop.last %} | 28 {%- if not loop.last %} |
25 {%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %} | 29 {%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %} |
26 {%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %} | 30 {%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %} |
27 {%- if pad > 0 %} | 31 {%- if pad > 0 %} |
28 uint8_t pad{{loop.index0}}_[{{pad}}]; | 32 uint8_t pad{{loop.index0}}_[{{pad}}]; |
29 {%- endif %} | 33 {%- endif %} |
30 {%- endif %} | 34 {%- endif %} |
31 {%- endfor %} | 35 {%- endfor %} |
32 | 36 |
33 {%- set num_fields = struct.versions[-1].num_fields %} | 37 {%- set num_fields = struct.versions[-1].num_fields %} |
34 {%- if num_fields > 0 %} | 38 {%- if num_fields > 0 %} |
35 {%- set last_field = struct.packed.packed_fields[num_fields - 1] %} | 39 {%- set last_field = struct.packed.packed_fields[num_fields - 1] %} |
36 {%- set offset = last_field.offset + last_field.size %} | 40 {%- set offset = last_field.offset + last_field.size %} |
37 {%- set pad = offset|get_pad(8) %} | 41 {%- set pad = offset|get_pad(8) %} |
38 {%- if pad > 0 %} | 42 {%- if pad > 0 %} |
39 uint8_t padfinal_[{{pad}}]; | 43 uint8_t padfinal_[{{pad}}]; |
40 {%- endif %} | 44 {%- endif %} |
41 {%- endif %} | 45 {%- endif %} |
42 | 46 |
43 private: | 47 private: |
44 {{class_name}}(); | 48 {{class_name}}(); |
45 ~{{class_name}}() = delete; | 49 ~{{class_name}}() = delete; |
46 }; | 50 }; |
47 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}}, | 51 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}}, |
48 "Bad sizeof({{class_name}})"); | 52 "Bad sizeof({{class_name}})"); |
OLD | NEW |