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

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

Issue 2259283003: Mojo C++ bindings: share DataView class between chromium and blink variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@92_change_traits_param
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 mojom_type = union|get_qualified_name_for_kind %}
2
3 // static
4 bool UnionTraits<{{mojom_type}}::DataView, {{mojom_type}}Ptr>::Read(
5 {{mojom_type}}::DataView input,
6 {{mojom_type}}Ptr* output) {
7 *output = {{mojom_type}}::New();
8 {{mojom_type}}Ptr& result = *output;
9
10 internal::UnionAccessor<{{mojom_type}}> result_acc(result.get());
11 switch (input.tag()) {
12 {%- for field in union.fields %}
13 case {{mojom_type}}::Tag::{{field.name|upper}}: {
14 {%- set name = field.name %}
15 {%- set kind = field.kind %}
16 {%- set serializer_type = kind|unmapped_type_for_serializer %}
17 {%- if kind|is_object_kind %}
18 result_acc.SwitchActive({{mojom_type}}::Tag::{{name|upper}});
19 if (!input.Read{{name|under_to_camel}}(result_acc.data()->{{name}}))
20 return false;
21
22 {%- elif kind|is_any_handle_or_interface_kind %}
23 auto result_{{name}} = input.Take{{name|under_to_camel}}();
24 result->set_{{name}}(std::move(result_{{name}}));
25
26 {%- elif kind|is_enum_kind %}
27 decltype(result->get_{{name}}()) result_{{name}};
28 if (!input.Read{{name|under_to_camel}}(&result_{{name}}))
29 return false;
30 result->set_{{name}}(result_{{name}});
31
32 {%- else %}
33 result->set_{{name}}(input.{{name}}());
34 {%- endif %}
35 break;
36 }
37 {%- endfor %}
38 default:
39 return false;
40 }
41 return true;
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698