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

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

Issue 2228733002: Mojo C++ bindings: add test cases for union custom typemapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@86_union_traits
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
1 {%- set mojom_type = union|get_qualified_name_for_kind %} 1 {%- set mojom_type = union|get_qualified_name_for_kind %}
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 template <> 4 template <>
5 struct {{export_attribute}} UnionTraits<{{mojom_type}}, {{mojom_type}}Ptr> { 5 struct {{export_attribute}} UnionTraits<{{mojom_type}}, {{mojom_type}}Ptr> {
6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } 6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; }
7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } 7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); }
8 8
9 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) { 9 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) {
10 return input->which(); 10 return input->which();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 in_{{name}}, context); 65 in_{{name}}, context);
66 {%- endif %} 66 {%- endif %}
67 {%- endif %} 67 {%- endif %}
68 break; 68 break;
69 } 69 }
70 {%- endfor %} 70 {%- endfor %}
71 } 71 }
72 return size; 72 return size;
73 } 73 }
74 74
75 static void Serialize({{mojom_type}}Ptr& input, 75 static void Serialize(MaybeConstUserType& input,
76 Buffer* buffer, 76 Buffer* buffer,
77 {{data_type}}** output, 77 {{data_type}}** output,
78 bool inlined, 78 bool inlined,
79 SerializationContext* context) { 79 SerializationContext* context) {
80 if (CallIsNullIfExists<Traits>(input)) { 80 if (CallIsNullIfExists<Traits>(input)) {
81 if (inlined) 81 if (inlined)
82 (*output)->set_null(); 82 (*output)->set_null();
83 else 83 else
84 *output = nullptr; 84 *output = nullptr;
85 return; 85 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 {%- endif %} 149 {%- endif %}
150 break; 150 break;
151 } 151 }
152 {%- endfor %} 152 {%- endfor %}
153 } 153 }
154 154
155 CustomContextHelper<Traits>::TearDown(input, custom_context); 155 CustomContextHelper<Traits>::TearDown(input, custom_context);
156 } 156 }
157 157
158 static bool Deserialize({{data_type}}* input, 158 static bool Deserialize({{data_type}}* input,
159 {{mojom_type}}Ptr* output, 159 UserType* output,
160 SerializationContext* context) { 160 SerializationContext* context) {
161 if (!input || input->is_null()) 161 if (!input || input->is_null())
162 return CallSetToNullIfExists<Traits>(output); 162 return CallSetToNullIfExists<Traits>(output);
163 163
164 {{mojom_type}}DataView data_view(input, context); 164 {{mojom_type}}DataView data_view(input, context);
165 return Traits::Read(data_view, output); 165 return Traits::Read(data_view, output);
166 } 166 }
167 }; 167 };
168 168
169 } // namespace internal 169 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698