Index: mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl |
index d06f9753a06c826cd6949b155ba4b51a6fe3a915..bab90452272118fc97c38940eb5cf8887b0ff54a 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl |
@@ -1,11 +1,37 @@ |
-size_t GetSerializedSize_({{union.name}}Ptr& input, |
- bool inlined, |
- mojo::internal::SerializationContext* context); |
-void SerializeUnion_({{union.name}}Ptr input, |
- mojo::internal::Buffer* buffer, |
- internal::{{union.name}}_Data** output, |
- bool inlined, |
- mojo::internal::SerializationContext* context); |
-bool Deserialize_(internal::{{union.name}}_Data* input, |
- {{union.name}}Ptr* output, |
- mojo::internal::SerializationContext* context); |
+{%- set mojom_type = union|get_qualified_name_for_kind %} |
+{%- set data_type = union|get_qualified_name_for_kind(internal=True) %} |
+ |
+namespace internal { |
+ |
+template <typename MojomType> |
+struct UnionSerializerImpl; |
+ |
+template <> |
+struct UnionSerializerImpl<{{mojom_type}}Ptr> { |
+ static size_t PrepareToSerialize({{mojom_type}}Ptr& input, |
+ bool inlined, |
+ SerializationContext* context); |
+ |
+ static void Serialize({{mojom_type}}Ptr& input, |
Sam McNally
2016/05/09 01:14:59
Why are these taking a non-const lvalue reference?
yzshen1
2016/05/09 06:13:40
The old serialization API takes |input| by value,
Sam McNally
2016/05/09 07:02:29
I don't see why the input needs to be non-const. I
|
+ Buffer* buffer, |
+ {{data_type}}** output, |
+ bool inlined, |
+ SerializationContext* context); |
+ |
+ static bool Deserialize({{data_type}}* input, |
+ {{mojom_type}}Ptr* output, |
+ SerializationContext* context); |
+}; |
+ |
+template <typename MaybeConstUserType> |
+struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> |
+ : public UnionSerializerImpl<{{mojom_type}}Ptr> { |
+ using UserType = typename std::remove_const<MaybeConstUserType>::type; |
+ |
+ static_assert(std::is_same<MaybeConstUserType, UserType>::value, |
+ "Only support serialization of non-const Unions."); |
+ static_assert(std::is_same<UserType, {{mojom_type}}Ptr>::value, |
+ "Custom mapping of mojom union is not supported."); |
+}; |
+ |
+} // namespace internal |