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

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

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
Patch Set: . Created 4 years, 5 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
1 {%- import "validation_macros.tmpl" as validation_macros %} 1 {%- import "validation_macros.tmpl" as validation_macros %}
2 {%- set class_name = union.name ~ "_Data" %} 2 {%- set class_name = union.name ~ "_Data" %}
3 {%- set enum_name = union.name ~ "_Tag" -%} 3 {%- set enum_name = union.name ~ "_Tag" -%}
4 4
5 // static 5 // static
6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) {
7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
8 } 8 }
9 9
10 // static 10 // static
(...skipping 30 matching lines...) Expand all
41 41
42 void {{class_name}}::set_null() { 42 void {{class_name}}::set_null() {
43 size = 0U; 43 size = 0U;
44 tag = static_cast<{{enum_name}}>(0); 44 tag = static_cast<{{enum_name}}>(0);
45 data.unknown = 0U; 45 data.unknown = 0U;
46 } 46 }
47 47
48 {{class_name}}::{{class_name}}() { 48 {{class_name}}::{{class_name}}() {
49 } 49 }
50 50
51 void {{class_name}}::EncodePointers() {
52 switch (tag) {
53 {%- for field in union.fields %}
54 case {{enum_name}}::{{field.name|upper}}: {
55 {%- if field.kind|is_object_kind %}
56 mojo::internal::Encode(&data.f_{{field.name}});
57 {%- endif %}
58 return;
59 }
60 {%- endfor %}
61 }
62 }
63
64 void {{class_name}}::DecodePointers() {
65 switch (tag) {
66 {%- for field in union.fields %}
67 case {{enum_name}}::{{field.name|upper}}: {
68 {%- if field.kind|is_object_kind %}
69 mojo::internal::Decode(&data.f_{{field.name}});
70 {%- endif %}
71 return;
72 }
73 {%- endfor %}
74 }
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698