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 <utility> | 10 #include <utility> |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 size += GetSerializedSize_(input[i]); | 157 size += GetSerializedSize_(input[i]); |
158 return size; | 158 return size; |
159 } | 159 } |
160 | 160 |
161 static void SerializeElements(Array<S> input, | 161 static void SerializeElements(Array<S> input, |
162 Buffer* buf, | 162 Buffer* buf, |
163 Array_Data<S_Data*>* output, | 163 Array_Data<S_Data*>* output, |
164 const ArrayValidateParams* validate_params) { | 164 const ArrayValidateParams* validate_params) { |
165 for (size_t i = 0; i < input.size(); ++i) { | 165 for (size_t i = 0; i < input.size(); ++i) { |
166 S_Data* element; | 166 S_Data* element; |
167 SerializeCaller<S>::Run(input[i].Pass(), buf, &element, | 167 SerializeCaller<S>::Run(std::move(input[i]), buf, &element, |
168 validate_params->element_validate_params); | 168 validate_params->element_validate_params); |
169 output->at(i) = element; | 169 output->at(i) = element; |
170 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 170 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
171 !validate_params->element_is_nullable && !element, | 171 !validate_params->element_is_nullable && !element, |
172 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 172 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
173 MakeMessageWithArrayIndex("null in array expecting valid pointers", | 173 MakeMessageWithArrayIndex("null in array expecting valid pointers", |
174 input.size(), i)); | 174 input.size(), i)); |
175 } | 175 } |
176 } | 176 } |
177 static bool DeserializeElements(Array_Data<S_Data*>* input, | 177 static bool DeserializeElements(Array_Data<S_Data*>* input, |
(...skipping 25 matching lines...) Expand all Loading... |
203 Serialize_(input.Pass(), buf, output); | 203 Serialize_(input.Pass(), buf, output); |
204 } | 204 } |
205 }; | 205 }; |
206 | 206 |
207 template <typename T> | 207 template <typename T> |
208 struct SerializeCaller<Array<T>> { | 208 struct SerializeCaller<Array<T>> { |
209 static void Run(Array<T> input, | 209 static void Run(Array<T> input, |
210 Buffer* buf, | 210 Buffer* buf, |
211 typename Array<T>::Data_** output, | 211 typename Array<T>::Data_** output, |
212 const ArrayValidateParams* validate_params) { | 212 const ArrayValidateParams* validate_params) { |
213 SerializeArray_(input.Pass(), buf, output, validate_params); | 213 SerializeArray_(std::move(input), buf, output, validate_params); |
214 } | 214 } |
215 }; | 215 }; |
216 | 216 |
217 template <typename T, typename U> | 217 template <typename T, typename U> |
218 struct SerializeCaller<Map<T, U>> { | 218 struct SerializeCaller<Map<T, U>> { |
219 static void Run(Map<T, U> input, | 219 static void Run(Map<T, U> input, |
220 Buffer* buf, | 220 Buffer* buf, |
221 typename Map<T, U>::Data_** output, | 221 typename Map<T, U>::Data_** output, |
222 const ArrayValidateParams* validate_params) { | 222 const ArrayValidateParams* validate_params) { |
223 SerializeMap_(input.Pass(), buf, output, validate_params); | 223 SerializeMap_(std::move(input), buf, output, validate_params); |
224 } | 224 } |
225 }; | 225 }; |
226 }; | 226 }; |
227 | 227 |
228 // Handles serialization and deserialization of arrays of unions. | 228 // Handles serialization and deserialization of arrays of unions. |
229 template <typename U, typename U_Data> | 229 template <typename U, typename U_Data> |
230 struct ArraySerializer<U, U_Data, true> { | 230 struct ArraySerializer<U, U_Data, true> { |
231 static size_t GetSerializedSize(const Array<U>& input) { | 231 static size_t GetSerializedSize(const Array<U>& input) { |
232 size_t size = sizeof(Array_Data<U_Data>); | 232 size_t size = sizeof(Array_Data<U_Data>); |
233 for (size_t i = 0; i < input.size(); ++i) { | 233 for (size_t i = 0; i < input.size(); ++i) { |
234 // GetSerializedSize_ will account for both the data in the union and the | 234 // GetSerializedSize_ will account for both the data in the union and the |
235 // space in the array used to hold the union. | 235 // space in the array used to hold the union. |
236 size += GetSerializedSize_(input[i], false); | 236 size += GetSerializedSize_(input[i], false); |
237 } | 237 } |
238 return size; | 238 return size; |
239 } | 239 } |
240 | 240 |
241 static void SerializeElements(Array<U> input, | 241 static void SerializeElements(Array<U> input, |
242 Buffer* buf, | 242 Buffer* buf, |
243 Array_Data<U_Data>* output, | 243 Array_Data<U_Data>* output, |
244 const ArrayValidateParams* validate_params) { | 244 const ArrayValidateParams* validate_params) { |
245 for (size_t i = 0; i < input.size(); ++i) { | 245 for (size_t i = 0; i < input.size(); ++i) { |
246 U_Data* result = output->storage() + i; | 246 U_Data* result = output->storage() + i; |
247 SerializeUnion_(input[i].Pass(), buf, &result, true); | 247 SerializeUnion_(std::move(input[i]), buf, &result, true); |
248 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 248 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
249 !validate_params->element_is_nullable && output->at(i).is_null(), | 249 !validate_params->element_is_nullable && output->at(i).is_null(), |
250 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 250 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
251 MakeMessageWithArrayIndex("null in array expecting valid unions", | 251 MakeMessageWithArrayIndex("null in array expecting valid unions", |
252 input.size(), i)); | 252 input.size(), i)); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 static bool DeserializeElements(Array_Data<U_Data>* input, | 256 static bool DeserializeElements(Array_Data<U_Data>* input, |
257 Array<U>* output, | 257 Array<U>* output, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } | 365 } |
366 } else { | 366 } else { |
367 output->reset(); | 367 output->reset(); |
368 } | 368 } |
369 return true; | 369 return true; |
370 } | 370 } |
371 | 371 |
372 } // namespace mojo | 372 } // namespace mojo |
373 | 373 |
374 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 374 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
OLD | NEW |