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