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

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

Issue 1956603002: Mojo C++ bindings: switch union to use the new serialization interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20_array_serializer
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698