summaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/union_traits.h
blob: 292ee58f277a2de016da051dea5a80971712f7cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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. |DataViewType| is the corresponding data view type of the
// mojom union. For example, if the mojom union is example.Foo, |DataViewType|
// will be example::FooDataView, which can also be referred to by
// example::Foo::DataView (in chromium) and example::blink::Foo::DataView (in
// blink).
//
// 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 DataViewType::Tag GetTag(const T& input);
//
//      During serialization, only the field getter corresponding to this tag
//      will be called.
//
template <typename DataViewType, typename T>
struct UnionTraits;

}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_