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

Unified Diff: mojo/public/cpp/bindings/union_traits.h

Issue 2226853002: Mojo C++ bindings: add support for UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_10_inline_more
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_forward.h ('k') | mojo/public/tools/bindings/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/union_traits.h
diff --git a/mojo/public/cpp/bindings/union_traits.h b/mojo/public/cpp/bindings/union_traits.h
new file mode 100644
index 0000000000000000000000000000000000000000..452bac03fa6d3df51065a4f4d9b465f35f2dfd45
--- /dev/null
+++ b/mojo/public/cpp/bindings/union_traits.h
@@ -0,0 +1,35 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
+
+namespace mojo {
+
+// This must be specialized for any type |T| to be serialized/deserialized as
+// a mojom union of type |MojomType|.
+//
+// Similar to StructTraits, each specialization of UnionTraits implements the
+// following methods:
+// 1. Getters for each field in the Mojom type.
+// 2. Read() method.
+// 3. [Optional] IsNull() and SetToNull().
+// 4. [Optional] SetUpContext() and TearDownContext().
+// Please see the documentation of StructTraits for details of these methods.
+//
+// Unlike StructTraits, there is one more method to implement:
+// 5. A static GetTag() method indicating which field is the current active
+// field for serialization:
+//
+// static |MojomType|DataView::Tag GetTag(const T& input);
+//
+// During serialization, only the field getter corresponding to this tag
+// will be called.
+//
+template <typename MojomType, typename T>
+struct UnionTraits;
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_forward.h ('k') | mojo/public/tools/bindings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698