| 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 // TODO(vardhan): Currently, the logic for serializing a mojom type exists in | 5 // TODO(vardhan): Currently, the logic for serializing a mojom type exists in |
| 6 // two places: the C++ code generator template, and here. However, most types | 6 // two places: the C++ code generator template, and here. However, most types |
| 7 // are serialized the same way within Arrays or outside, with the exception of | 7 // are serialized the same way within Arrays or outside, with the exception of |
| 8 // |bool|. Consider defining serialization/deserialization traits for each | 8 // |bool|. Consider defining serialization/deserialization traits for each |
| 9 // serializable type and call those traits from here. This should help us | 9 // serializable type and call those traits from here. This should help us |
| 10 // remove most of the ArraySerializer<> specializations here. | 10 // remove most of the ArraySerializer<> specializations here. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 // Handles serialization and deserialization of arrays of unions. | 429 // Handles serialization and deserialization of arrays of unions. |
| 430 template <typename U, typename U_Data> | 430 template <typename U, typename U_Data> |
| 431 struct ArraySerializer<U, U_Data, true> { | 431 struct ArraySerializer<U, U_Data, true> { |
| 432 static size_t GetSerializedSize(const Array<U>& input) { | 432 static size_t GetSerializedSize(const Array<U>& input) { |
| 433 size_t size = sizeof(Array_Data<U_Data>); | 433 size_t size = sizeof(Array_Data<U_Data>); |
| 434 for (size_t i = 0; i < input.size(); ++i) { | 434 for (size_t i = 0; i < input.size(); ++i) { |
| 435 // GetSerializedSize_ will account for both the data in the union and the | 435 // GetSerializedSize_ will account for both the data in the union and the |
| 436 // space in the array used to hold the union. | 436 // space in the array used to hold the union. |
| 437 size += GetSerializedSize_(input[i], false); | 437 size += GetSerializedSize_(input[i]); |
| 438 } | 438 } |
| 439 return size; | 439 return size; |
| 440 } | 440 } |
| 441 | 441 |
| 442 template <typename Iterator> | 442 template <typename Iterator> |
| 443 static ValidationError SerializeElements( | 443 static ValidationError SerializeElements( |
| 444 Iterator it, | 444 Iterator it, |
| 445 size_t num_elements, | 445 size_t num_elements, |
| 446 Buffer* buf, | 446 Buffer* buf, |
| 447 Array_Data<U_Data>* output, | 447 Array_Data<U_Data>* output, |
| 448 const ArrayValidateParams* validate_params) { | 448 const ArrayValidateParams* validate_params) { |
| 449 for (size_t i = 0; i < num_elements; ++i, ++it) { | 449 for (size_t i = 0; i < num_elements; ++i, ++it) { |
| 450 U_Data* result = output->storage() + i; | 450 U_Data* result = output->storage() + i; |
| 451 auto retval = SerializeUnion_(it->get(), buf, &result, true); | 451 auto retval = SerializeUnion_(it->get(), buf, &result); |
| 452 if (retval != ValidationError::NONE) | 452 if (retval != ValidationError::NONE) |
| 453 return retval; | 453 return retval; |
| 454 if (!validate_params->element_is_nullable && output->at(i).is_null()) { | 454 if (!validate_params->element_is_nullable && output->at(i).is_null()) { |
| 455 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 455 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 456 | 456 |
| 457 ValidationError::UNEXPECTED_NULL_POINTER, | 457 ValidationError::UNEXPECTED_NULL_POINTER, |
| 458 MakeMessageWithArrayIndex("null in array expecting valid unions", | 458 MakeMessageWithArrayIndex("null in array expecting valid unions", |
| 459 num_elements, i)); | 459 num_elements, i)); |
| 460 return ValidationError::UNEXPECTED_NULL_POINTER; | 460 return ValidationError::UNEXPECTED_NULL_POINTER; |
| 461 } | 461 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 if (input) { | 532 if (input) { |
| 533 internal::ArraySerializer<E, F>::DeserializeElements(input, output); | 533 internal::ArraySerializer<E, F>::DeserializeElements(input, output); |
| 534 } else { | 534 } else { |
| 535 output->reset(); | 535 output->reset(); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 | 538 |
| 539 } // namespace mojo | 539 } // namespace mojo |
| 540 | 540 |
| 541 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 541 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
| OLD | NEW |