Chromium Code Reviews| 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..a87c3b67bd28b852daa0d38194a85a4a8f4bf609 100644 |
| --- a/mojo/public/cpp/bindings/lib/array_serialization.h |
| +++ b/mojo/public/cpp/bindings/lib/array_serialization.h |
| @@ -45,11 +45,14 @@ 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 = internal::IsWrappedUnionPtr<E>::value> |
|
yzshen1
2015/02/25 21:07:00
nit: internal:: is not needed.
azani
2015/03/03 00:44:15
Done.
|
| struct ArraySerializer; |
| 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)); |
| @@ -75,7 +78,7 @@ struct ArraySerializer<E, F, false> { |
| }; |
| 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); |
| } |
| @@ -103,7 +106,7 @@ struct ArraySerializer<bool, bool, false> { |
| }; |
| 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 +145,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) { |
| @@ -211,6 +215,50 @@ struct ArraySerializer<S, |
| }; |
| }; |
| +template <typename U, typename U_Data> |
|
yzshen1
2015/02/25 21:06:59
nit: Please comment about what is this specializat
azani
2015/03/03 00:44:15
Done.
|
| +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) { |
| + 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; |
| + Serialize_(input[i].Pass(), buf, &result); |
|
yzshen1
2015/02/25 21:07:00
I think maybe we should make a different Serialize
azani
2015/03/03 00:44:15
Done.
|
| + } |
|
yzshen1
2015/02/25 21:07:00
Please look at line 168: we need to do similar thi
azani
2015/03/03 00:44:15
Done.
|
| + } |
| + |
| + 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) { |
| + U element; |
| + Deserialize_(&input->at(i), &element); |
| + result[i] = element.Pass(); |
| + } |
| + output->Swap(&result); |
| + } |
| +}; |
| +/* |
|
yzshen1
2015/02/25 21:07:00
If something is not useful, please remove it inste
azani
2015/03/03 00:44:15
Done.
|
| +template <typename U> |
| +struct ArraySerializer<U, |
| + typename internal::EnableIf< |
| + internal::IsWrappedUnionPtr<U>::value, |
| + typename internal::WrapperTraits<U>::DataType>::type, |
| +true> { |
| + static const int i = 10; |
| + static size_t GetSerializedSize(const Array<U>& input) { |
| + return 0; |
| + } |
| +}; |
| +*/ |
| + |
| template <> |
| struct ArraySerializer<String, String_Data*, false> { |
| static size_t GetSerializedSize(const Array<String>& input) { |