| 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 4407de850d676ec73d9d76286846141968a71750..5bc684c9f4ca2fbaa48882dcc524c779e79a237b 100644
|
| --- a/mojo/public/cpp/bindings/lib/array_serialization.h
|
| +++ b/mojo/public/cpp/bindings/lib/array_serialization.h
|
| @@ -11,6 +11,7 @@
|
|
|
| #include "mojo/public/c/system/macros.h"
|
| #include "mojo/public/cpp/bindings/lib/array_internal.h"
|
| +#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
|
| #include "mojo/public/cpp/bindings/lib/string_serialization.h"
|
| #include "mojo/public/cpp/bindings/lib/template_util.h"
|
| #include "mojo/public/cpp/bindings/lib/validation_errors.h"
|
| @@ -31,6 +32,17 @@ inline void SerializeArray_(Array<E> input, internal::Buffer* buf,
|
| template <typename E, typename F>
|
| inline void Deserialize_(internal::Array_Data<F>* data, Array<E>* output);
|
|
|
| +template <typename ValueValidateParams,
|
| + typename KeyWrapperType,
|
| + typename ValueWrapperType,
|
| + typename KeySerializationType,
|
| + typename ValueSerializationType>
|
| +inline void SerializeMap_(
|
| + Map<KeyWrapperType, ValueWrapperType> input,
|
| + internal::Buffer* buf,
|
| + internal::MapPointerPair<KeySerializationType,
|
| + ValueSerializationType>* output);
|
| +
|
| namespace internal {
|
|
|
| template <typename E, typename F, bool move_only = IsMoveOnlyType<E>::value>
|
| @@ -212,6 +224,55 @@ template <> struct ArraySerializer<String, String_Data*, false> {
|
| }
|
| };
|
|
|
| +template <typename KeyWrapperType, typename ValueWrapperType,
|
| + typename KeySerializationType, typename ValueSerializationType>
|
| + struct ArraySerializer<
|
| + Map<KeyWrapperType, ValueWrapperType>,
|
| + MapPointerPair<KeySerializationType, ValueSerializationType>,
|
| + true> {
|
| + static size_t GetSerializedSize(
|
| + const Array<Map<KeyWrapperType, ValueWrapperType>>& input) {
|
| + size_t size = sizeof(ArrayHeader) +
|
| + input.size() * sizeof(MapPointerPair<KeySerializationType,
|
| + ValueSerializationType>);
|
| + for (size_t i = 0; i < input.size(); ++i)
|
| + size += GetSerializedSize_(input[i]);
|
| + return size;
|
| + }
|
| +
|
| + template <bool element_is_nullable, typename ElementValidateParams>
|
| + static void SerializeElements(
|
| + Array<Map<KeyWrapperType, ValueWrapperType>> input,
|
| + Buffer* buf,
|
| + Array_Data<MapPointerPair<KeySerializationType,
|
| + ValueSerializationType>>* output) {
|
| + for (size_t i = 0; i < input.size(); ++i) {
|
| + MapPointerPair<KeySerializationType, ValueSerializationType> element;
|
| + SerializeMap_<ElementValidateParams>(input[i].Pass(), buf, &element);
|
| + output->at(i) = element;
|
| + MOJO_DCHECK(!!element.keys.ptr == !!element.values.ptr);
|
| + MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
|
| + !element_is_nullable && !element.keys.ptr,
|
| + VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
|
| + MakeMessageWithArrayIndex(
|
| + "null in array expecting valid pointers", input.size(), i));
|
| + }
|
| + }
|
| +
|
| + static void DeserializeElements(
|
| + Array_Data<
|
| + MapPointerPair<KeySerializationType, ValueSerializationType>>* input,
|
| + Array<Map<KeyWrapperType, ValueWrapperType>>* output) {
|
| + Array<Map<KeyWrapperType, ValueWrapperType>> result(input->size());
|
| + for (size_t i = 0; i < input->size(); ++i) {
|
| + Map<KeyWrapperType, ValueWrapperType> element;
|
| + Deserialize_(&input->at(i), &element);
|
| + result[i] = element.Pass();
|
| + }
|
| + output->Swap(&result);
|
| + }
|
| +};
|
| +
|
| } // namespace internal
|
|
|
| template <typename E>
|
|
|