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

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

Issue 2660733002: Mojo C++ bindings: introduce an optional array to store transferred interface IDs in messages. (Closed)
Patch Set: . Created 3 years, 10 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 {%- set data_view = union|get_qualified_name_for_kind ~ "DataView" %} 1 {%- set data_view = union|get_qualified_name_for_kind ~ "DataView" %}
2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %} 2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %}
3 3
4 namespace internal { 4 namespace internal {
5 5
6 template <typename MaybeConstUserType> 6 template <typename MaybeConstUserType>
7 struct Serializer<{{data_view}}, MaybeConstUserType> { 7 struct Serializer<{{data_view}}, MaybeConstUserType> {
8 using UserType = typename std::remove_const<MaybeConstUserType>::type; 8 using UserType = typename std::remove_const<MaybeConstUserType>::type;
9 using Traits = UnionTraits<{{data_view}}, UserType>; 9 using Traits = UnionTraits<{{data_view}}, UserType>;
10 10
11 static size_t PrepareToSerialize(MaybeConstUserType& input, 11 static size_t PrepareToSerialize(MaybeConstUserType& input,
12 bool inlined, 12 bool inlined,
13 SerializationContext* context) { 13 SerializationContext* context) {
14 size_t size = inlined ? 0 : sizeof({{data_type}}); 14 size_t size = inlined ? 0 : sizeof({{data_type}});
15 15
16 if (CallIsNullIfExists<Traits>(input)) 16 if (CallIsNullIfExists<Traits>(input))
17 return size; 17 return size;
18 18
19 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); 19 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context);
20 ALLOW_UNUSED_LOCAL(custom_context); 20 ALLOW_UNUSED_LOCAL(custom_context);
21 21
22 switch (CallWithContext(Traits::GetTag, input, custom_context)) { 22 switch (CallWithContext(Traits::GetTag, input, custom_context)) {
23 {%- for field in union.fields %} 23 {%- for field in union.fields %}
24 {%- set name = field.name %} 24 {%- set name = field.name %}
25 case {{data_view}}::Tag::{{name|upper}}: { 25 case {{data_view}}::Tag::{{name|upper}}: {
26 {%- if field.kind|is_object_kind %} 26 {%- if field.kind|is_object_kind or field.kind|is_associated_kind %}
27 {%- set kind = field.kind %} 27 {%- set kind = field.kind %}
28 {%- set serializer_type = kind|unmapped_type_for_serializer %} 28 {%- set serializer_type = kind|unmapped_type_for_serializer %}
29 decltype(CallWithContext(Traits::{{name}}, input, custom_context)) 29 decltype(CallWithContext(Traits::{{name}}, input, custom_context))
30 in_{{name}} = CallWithContext(Traits::{{name}}, input, 30 in_{{name}} = CallWithContext(Traits::{{name}}, input,
31 custom_context); 31 custom_context);
32 {%- if kind|is_union_kind %} 32 {%- if kind|is_union_kind %}
33 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( 33 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>(
34 in_{{name}}, false, context); 34 in_{{name}}, false, context);
35 {%- else %} 35 {%- else %}
36 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( 36 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>(
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 SerializationContext* context) { 132 SerializationContext* context) {
133 if (!input || input->is_null()) 133 if (!input || input->is_null())
134 return CallSetToNullIfExists<Traits>(output); 134 return CallSetToNullIfExists<Traits>(output);
135 135
136 {{data_view}} data_view(input, context); 136 {{data_view}} data_view(input, context);
137 return Traits::Read(data_view, output); 137 return Traits::Read(data_view, output);
138 } 138 }
139 }; 139 };
140 140
141 } // namespace internal 141 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698