Home | History | Annotate | Download | only in bindings
      1 // Copyright 2016 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
      6 #define MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
      7 
      8 namespace mojo {
      9 
     10 // This must be specialized for any type |T| to be serialized/deserialized as
     11 // a mojom union. |DataViewType| is the corresponding data view type of the
     12 // mojom union. For example, if the mojom union is example.Foo, |DataViewType|
     13 // will be example::FooDataView, which can also be referred to by
     14 // example::Foo::DataView (in chromium) and example::blink::Foo::DataView (in
     15 // blink).
     16 //
     17 // Similar to StructTraits, each specialization of UnionTraits implements the
     18 // following methods:
     19 //   1. Getters for each field in the Mojom type.
     20 //   2. Read() method.
     21 //   3. [Optional] IsNull() and SetToNull().
     22 //   4. [Optional] SetUpContext() and TearDownContext().
     23 // Please see the documentation of StructTraits for details of these methods.
     24 //
     25 // Unlike StructTraits, there is one more method to implement:
     26 //   5. A static GetTag() method indicating which field is the current active
     27 //      field for serialization:
     28 //
     29 //        static DataViewType::Tag GetTag(const T& input);
     30 //
     31 //      During serialization, only the field getter corresponding to this tag
     32 //      will be called.
     33 //
     34 template <typename DataViewType, typename T>
     35 struct UnionTraits;
     36 
     37 }  // namespace mojo
     38 
     39 #endif  // MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
     40