Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 {%- set class_name = struct.name ~ "_Data" -%}
2
3 class {{class_name}} {
4 public:
5 static {{class_name}}* New(mojo::internal::Buffer* buf);
6
7 static mojo::internal::ValidationError Validate(
8 const void* data,
9 mojo::internal::BoundsChecker* bounds_checker,
10 std::string* err);
11
12 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles);
13 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles);
14
15 mojo::internal::StructHeader header_;
16 {%- for packed_field in struct.packed.packed_fields %}
17 {%- set name = packed_field.field.name %}
18 {%- set kind = packed_field.field.kind %}
19 {%- if kind.spec == 'b' %}
20 uint8_t {{name}} : 1;
21 {%- elif kind|is_enum_kind %}
22 int32_t {{name}};
23 {%- else %}
24 {{kind|cpp_field_type}} {{name}};
25 {%- endif %}
26 {%- if not loop.last %}
27 {%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %}
28 {%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %}
29 {%- if pad > 0 %}
30 uint8_t pad{{loop.index0}}_[{{pad}}];
31 {%- endif %}
32 {%- endif %}
33 {%- endfor %}
34
35 {%- set num_fields = struct.versions[-1].num_fields %}
36 {%- if num_fields > 0 %}
37 {%- set last_field = struct.packed.packed_fields[num_fields - 1] %}
38 {%- set offset = last_field.offset + last_field.size %}
39 {%- set pad = offset|get_pad(8) %}
40 {%- if pad > 0 %}
41 uint8_t padfinal_[{{pad}}];
42 {%- endif %}
43 {%- endif %}
44
45 private:
46 {{class_name}}();
47 ~{{class_name}}() = delete;
48 };
49 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}},
50 "Bad sizeof({{class_name}})");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698