| Index: mojo/public/cpp/bindings/struct_traits.h
|
| diff --git a/mojo/public/cpp/bindings/struct_traits.h b/mojo/public/cpp/bindings/struct_traits.h
|
| index b2a60c7887b9280d2772266bca0c3c25822e4497..c3ea5ad3dce5cd045dadadfb01caff28574170bb 100644
|
| --- a/mojo/public/cpp/bindings/struct_traits.h
|
| +++ b/mojo/public/cpp/bindings/struct_traits.h
|
| @@ -8,7 +8,11 @@
|
| namespace mojo {
|
|
|
| // This must be specialized for any type |T| to be serialized/deserialized as
|
| -// a mojom struct of type |MojomType|.
|
| +// a mojom struct. |DataViewType| is the corresponding data view type of the
|
| +// mojom struct. For example, if the mojom struct 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).
|
| //
|
| // Each specialization needs to implement a few things:
|
| // 1. Static getters for each field in the Mojom type. These should be
|
| @@ -20,19 +24,22 @@ namespace mojo {
|
| // from |input|.
|
| //
|
| // Serializable form of a field:
|
| -// Value or reference of the same type used in |MojomType|, or the
|
| -// following alternatives:
|
| +// Value or reference of the same type used in the generated stuct
|
| +// wrapper type, or the following alternatives:
|
| // - string:
|
| // Value or reference of any type that has a StringTraits defined.
|
| -// Supported by default: base::StringPiece, std::string.
|
| +// Supported by default: base::StringPiece, std::string, mojo::String,
|
| +// WTF::String (in blink).
|
| //
|
| // - array:
|
| // Value or reference of any type that has an ArrayTraits defined.
|
| -// Supported by default: std::vector, WTF::Vector (in blink), CArray.
|
| +// Supported by default: std::vector, CArray, mojo::Array, WTF::Vector
|
| +// (in blink), mojo::WTFArray (in blink).
|
| //
|
| // - map:
|
| // Value or reference of any type that has a MapTraits defined.
|
| -// Supported by default: std::map.
|
| +// Supported by default: std::map, std::unordered_map, mojo::Map,
|
| +// WTF::HashMap (in blink), mojo::WTFMap (in blink).
|
| //
|
| // - struct:
|
| // Value or reference of any type that has a StructTraits defined.
|
| @@ -40,6 +47,10 @@ namespace mojo {
|
| // - enum:
|
| // Value of any type that has an EnumTraits defined.
|
| //
|
| +// For any nullable string/struct/array/map/union field you could also
|
| +// return value or reference of base::Optional<T>/WTF::Optional<T>, if T
|
| +// has the right *Traits defined.
|
| +//
|
| // During serialization, getters for string/struct/array/map/union fields
|
| // are called twice (one for size calculation and one for actual
|
| // serialization). If you want to return a value (as opposed to a
|
| @@ -49,14 +60,13 @@ namespace mojo {
|
| // Getters for fields of other types are called once.
|
| //
|
| // 2. A static Read() method to set the contents of a |T| instance from a
|
| -// |MojomType|DataView (e.g., if |MojomType| is test::Example, the data
|
| -// view will be test::ExampleDataView).
|
| +// DataViewType.
|
| //
|
| -// static bool Read(|MojomType|DataView data, T* output);
|
| +// static bool Read(DataViewType data, T* output);
|
| //
|
| -// The generated |MojomType|DataView type provides a convenient,
|
| -// inexpensive view of a serialized struct's field data. The caller
|
| -// guarantees that |!data.is_null()|.
|
| +// The generated DataViewType provides a convenient, inexpensive view of a
|
| +// serialized struct's field data. The caller guarantees that
|
| +// |!data.is_null()|.
|
| //
|
| // Returning false indicates invalid incoming data and causes the message
|
| // pipe receiving it to be disconnected. Therefore, you can do custom
|
| @@ -112,9 +122,12 @@ namespace mojo {
|
| // reference/value to the Mojo bindings for serialization:
|
| // - if T is used in the "type_mappings" section of a typemap config file,
|
| // you need to declare it as pass-by-value:
|
| -// type_mappings = [ "MojomType=T(pass_by_value)" ]
|
| -// - if another type U's StructTraits has a getter for T, it needs to return
|
| -// non-const reference/value.
|
| +// type_mappings = [ "MojomType=T(move_only)" ]
|
| +// or
|
| +// type_mappings = [ "MojomType=T(copyable_pass_by_value)" ]
|
| +//
|
| +// - if another type U's StructTraits/UnionTraits has a getter for T, it
|
| +// needs to return non-const reference/value.
|
| //
|
| // EXAMPLE:
|
| //
|
| @@ -129,7 +142,7 @@ namespace mojo {
|
| //
|
| // StructTraits for Foo:
|
| // template <>
|
| -// struct StructTraits<Foo, CustomFoo> {
|
| +// struct StructTraits<FooDataView, CustomFoo> {
|
| // // Optional methods dealing with null:
|
| // static bool IsNull(const CustomFoo& input);
|
| // static void SetToNull(CustomFoo* output);
|
| @@ -145,7 +158,7 @@ namespace mojo {
|
| // static bool Read(FooDataView data, CustomFoo* output);
|
| // };
|
| //
|
| -template <typename MojomType, typename T>
|
| +template <typename DataViewType, typename T>
|
| struct StructTraits;
|
|
|
| } // namespace mojo
|
|
|