blob: 292ee58f277a2de016da051dea5a80971712f7cf [file] [log] [blame]
// 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.
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