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