| Index: mojo/public/cpp/bindings/lib/array_serialization.h
|
| diff --git a/mojo/public/cpp/bindings/lib/array_serialization.h b/mojo/public/cpp/bindings/lib/array_serialization.h
|
| index eacf298ec80ea46fffebe0afa499a32f83325316..154ac9f7662b346a3d287d56ee1b36cf8276a109 100644
|
| --- a/mojo/public/cpp/bindings/lib/array_serialization.h
|
| +++ b/mojo/public/cpp/bindings/lib/array_serialization.h
|
| @@ -45,11 +45,16 @@ inline void Deserialize_(internal::Array_Data<F>* data, Array<E>* output);
|
|
|
| namespace internal {
|
|
|
| -template <typename E, typename F, bool move_only = IsMoveOnlyType<E>::value>
|
| +template <typename E,
|
| + typename F,
|
| + bool move_only = IsMoveOnlyType<E>::value,
|
| + bool is_union =
|
| + IsUnionDataType<typename RemovePointer<F>::type>::value>
|
| struct ArraySerializer;
|
|
|
| +// Handles serialization and deserialization of arrays of pod types.
|
| template <typename E, typename F>
|
| -struct ArraySerializer<E, F, false> {
|
| +struct ArraySerializer<E, F, false, false> {
|
| static_assert(sizeof(E) == sizeof(F), "Incorrect array serializer");
|
| static size_t GetSerializedSize(const Array<E>& input) {
|
| return sizeof(Array_Data<F>) + Align(input.size() * sizeof(E));
|
| @@ -74,8 +79,9 @@ struct ArraySerializer<E, F, false> {
|
| }
|
| };
|
|
|
| +// Serializes and deserializes arrays of bools.
|
| template <>
|
| -struct ArraySerializer<bool, bool, false> {
|
| +struct ArraySerializer<bool, bool, false, false> {
|
| static size_t GetSerializedSize(const Array<bool>& input) {
|
| return sizeof(Array_Data<bool>) + Align((input.size() + 7) / 8);
|
| }
|
| @@ -102,8 +108,9 @@ struct ArraySerializer<bool, bool, false> {
|
| }
|
| };
|
|
|
| +// Serializes and deserializes arrays of handles.
|
| template <typename H>
|
| -struct ArraySerializer<ScopedHandleBase<H>, H, true> {
|
| +struct ArraySerializer<ScopedHandleBase<H>, H, true, false> {
|
| static size_t GetSerializedSize(const Array<ScopedHandleBase<H>>& input) {
|
| return sizeof(Array_Data<H>) + Align(input.size() * sizeof(H));
|
| }
|
| @@ -142,7 +149,8 @@ struct ArraySerializer<S,
|
| internal::IsPointer<typename internal::WrapperTraits<
|
| S>::DataType>::value,
|
| typename internal::WrapperTraits<S>::DataType>::type,
|
| - true> {
|
| + true,
|
| + false> {
|
| typedef typename internal::RemovePointer<
|
| typename internal::WrapperTraits<S>::DataType>::type S_Data;
|
| static size_t GetSerializedSize(const Array<S>& input) {
|
| @@ -172,9 +180,7 @@ struct ArraySerializer<S,
|
| Array<S>* output) {
|
| Array<S> result(input->size());
|
| for (size_t i = 0; i < input->size(); ++i) {
|
| - S element;
|
| - Deserialize_(input->at(i), &element);
|
| - result[i] = element.Pass();
|
| + Deserialize_(input->at(i), &result[i]);
|
| }
|
| output->Swap(&result);
|
| }
|
| @@ -211,6 +217,44 @@ struct ArraySerializer<S,
|
| };
|
| };
|
|
|
| +// Handles serialization and deserialization of arrays of unions.
|
| +template <typename U, typename U_Data>
|
| +struct ArraySerializer<U, U_Data, true, true> {
|
| + static size_t GetSerializedSize(const Array<U>& input) {
|
| + size_t size = sizeof(Array_Data<U_Data>);
|
| + for (size_t i = 0; i < input.size(); ++i) {
|
| + // GetSerializedSize_ will account for both the data in the union and the
|
| + // space in the array used to hold the union.
|
| + size += GetSerializedSize_(input[i]);
|
| + }
|
| + return size;
|
| + }
|
| +
|
| + template <bool element_is_nullable, typename ElementValidateParams>
|
| + static void SerializeElements(Array<U> input,
|
| + Buffer* buf,
|
| + Array_Data<U_Data>* output) {
|
| + for (size_t i = 0; i < input.size(); ++i) {
|
| + U_Data* result = output->storage() + i;
|
| + SerializeUnion_(input[i].Pass(), buf, &result, true);
|
| + MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
|
| + !element_is_nullable && output->at(i).is_null(),
|
| + VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
|
| + MakeMessageWithArrayIndex("null in array expecting valid unions",
|
| + input.size(), i));
|
| + }
|
| + }
|
| +
|
| + static void DeserializeElements(Array_Data<U_Data>* input, Array<U>* output) {
|
| + Array<U> result(input->size());
|
| + for (size_t i = 0; i < input->size(); ++i) {
|
| + Deserialize_(&input->at(i), &result[i]);
|
| + }
|
| + output->Swap(&result);
|
| + }
|
| +};
|
| +
|
| +// Handles serialization and deserialization of arrays of strings.
|
| template <>
|
| struct ArraySerializer<String, String_Data*, false> {
|
| static size_t GetSerializedSize(const Array<String>& input) {
|
|
|