OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
7 | 7 |
8 #include <string.h> // For |memcpy()|. | 8 #include <string.h> // For |memcpy()|. |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "mojo/public/c/system/macros.h" | 12 #include "mojo/public/c/system/macros.h" |
13 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 13 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 14 #include "mojo/public/cpp/bindings/lib/map_serialization.h" |
14 #include "mojo/public/cpp/bindings/lib/string_serialization.h" | 15 #include "mojo/public/cpp/bindings/lib/string_serialization.h" |
15 #include "mojo/public/cpp/bindings/lib/template_util.h" | 16 #include "mojo/public/cpp/bindings/lib/template_util.h" |
16 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 17 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 | 20 |
20 template <typename E> | 21 template <typename E> |
21 inline size_t GetSerializedSize_(const Array<E>& input); | 22 inline size_t GetSerializedSize_(const Array<E>& input); |
22 | 23 |
23 // Because ValidateParams requires explicit argument specification, the | 24 // Because ValidateParams requires explicit argument specification, the |
24 // argument-dependent loopup technique used to omit namespace when calling | 25 // argument-dependent loopup technique used to omit namespace when calling |
25 // Serialize_() doesn't seem to work. Therefore, this function is named | 26 // Serialize_() doesn't seem to work. Therefore, this function is named |
26 // differently from those Serialize_() overloads. | 27 // differently from those Serialize_() overloads. |
27 template <typename ValidateParams, typename E, typename F> | 28 template <typename ValidateParams, typename E, typename F> |
28 inline void SerializeArray_(Array<E> input, | 29 inline void SerializeArray_(Array<E> input, |
29 internal::Buffer* buf, | 30 internal::Buffer* buf, |
30 internal::Array_Data<F>** output); | 31 internal::Array_Data<F>** output); |
31 | 32 |
| 33 template <typename ValueValidateParams, |
| 34 typename KeyWrapperType, |
| 35 typename ValueWrapperType, |
| 36 typename KeySerializationType, |
| 37 typename ValueSerializationType> |
| 38 inline void SerializeMap_( |
| 39 Map<KeyWrapperType, ValueWrapperType> input, |
| 40 internal::Buffer* buf, |
| 41 internal::Map_Data<KeySerializationType, ValueSerializationType>** output); |
| 42 |
32 template <typename E, typename F> | 43 template <typename E, typename F> |
33 inline void Deserialize_(internal::Array_Data<F>* data, Array<E>* output); | 44 inline void Deserialize_(internal::Array_Data<F>* data, Array<E>* output); |
34 | 45 |
35 namespace internal { | 46 namespace internal { |
36 | 47 |
37 template <typename E, typename F, bool move_only = IsMoveOnlyType<E>::value> | 48 template <typename E, typename F, bool move_only = IsMoveOnlyType<E>::value> |
38 struct ArraySerializer; | 49 struct ArraySerializer; |
39 | 50 |
40 template <typename E, typename F> | 51 template <typename E, typename F> |
41 struct ArraySerializer<E, F, false> { | 52 struct ArraySerializer<E, F, false> { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 }; | 181 }; |
171 | 182 |
172 template <typename T, typename Params> | 183 template <typename T, typename Params> |
173 struct SerializeCaller<Array<T>, Params> { | 184 struct SerializeCaller<Array<T>, Params> { |
174 static void Run(Array<T> input, | 185 static void Run(Array<T> input, |
175 Buffer* buf, | 186 Buffer* buf, |
176 typename Array<T>::Data_** output) { | 187 typename Array<T>::Data_** output) { |
177 SerializeArray_<Params>(input.Pass(), buf, output); | 188 SerializeArray_<Params>(input.Pass(), buf, output); |
178 } | 189 } |
179 }; | 190 }; |
| 191 |
| 192 template <typename T, typename U, typename Params> |
| 193 struct SerializeCaller<Map<T, U>, Params> { |
| 194 static void Run(Map<T, U> input, |
| 195 Buffer* buf, |
| 196 typename Map<T, U>::Data_** output) { |
| 197 SerializeMap_<Params>(input.Pass(), buf, output); |
| 198 } |
| 199 }; |
180 }; | 200 }; |
181 | 201 |
182 template <> | 202 template <> |
183 struct ArraySerializer<String, String_Data*, false> { | 203 struct ArraySerializer<String, String_Data*, false> { |
184 static size_t GetSerializedSize(const Array<String>& input) { | 204 static size_t GetSerializedSize(const Array<String>& input) { |
185 size_t size = sizeof(Array_Data<String_Data*>) + | 205 size_t size = sizeof(Array_Data<String_Data*>) + |
186 input.size() * sizeof(internal::StringPointer); | 206 input.size() * sizeof(internal::StringPointer); |
187 for (size_t i = 0; i < input.size(); ++i) | 207 for (size_t i = 0; i < input.size(); ++i) |
188 size += GetSerializedSize_(input[i]); | 208 size += GetSerializedSize_(input[i]); |
189 return size; | 209 return size; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (input) { | 280 if (input) { |
261 internal::ArraySerializer<E, F>::DeserializeElements(input, output); | 281 internal::ArraySerializer<E, F>::DeserializeElements(input, output); |
262 } else { | 282 } else { |
263 output->reset(); | 283 output->reset(); |
264 } | 284 } |
265 } | 285 } |
266 | 286 |
267 } // namespace mojo | 287 } // namespace mojo |
268 | 288 |
269 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 289 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
OLD | NEW |