| 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> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 static void SerializeElements(Array<ScopedHandleBase<H> > input, | 95 static void SerializeElements(Array<ScopedHandleBase<H> > input, |
| 96 Buffer* buf, | 96 Buffer* buf, |
| 97 Array_Data<H>* output) { | 97 Array_Data<H>* output) { |
| 98 MOJO_COMPILE_ASSERT( | 98 MOJO_COMPILE_ASSERT( |
| 99 (IsSame<ElementValidateParams, NoValidateParams>::value), | 99 (IsSame<ElementValidateParams, NoValidateParams>::value), |
| 100 Handle_type_should_not_have_array_validate_params); | 100 Handle_type_should_not_have_array_validate_params); |
| 101 | 101 |
| 102 for (size_t i = 0; i < input.size(); ++i) { | 102 for (size_t i = 0; i < input.size(); ++i) { |
| 103 output->at(i) = input[i].release(); // Transfer ownership of the handle. | 103 output->at(i) = input[i].release(); // Transfer ownership of the handle. |
| 104 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 104 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 105 IsNonNullableValidationEnabled() && !element_is_nullable && | 105 !element_is_nullable && !output->at(i).is_valid(), |
| 106 !output->at(i).is_valid(), | |
| 107 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); | 106 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 static void DeserializeElements( | 109 static void DeserializeElements( |
| 111 Array_Data<H>* input, Array<ScopedHandleBase<H> >* output) { | 110 Array_Data<H>* input, Array<ScopedHandleBase<H> >* output) { |
| 112 Array<ScopedHandleBase<H> > result(input->size()); | 111 Array<ScopedHandleBase<H> > result(input->size()); |
| 113 for (size_t i = 0; i < input->size(); ++i) | 112 for (size_t i = 0; i < input->size(); ++i) |
| 114 result.at(i) = MakeScopedHandle(FetchAndReset(&input->at(i))); | 113 result.at(i) = MakeScopedHandle(FetchAndReset(&input->at(i))); |
| 115 output->Swap(&result); | 114 output->Swap(&result); |
| 116 } | 115 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 127 template <bool element_is_nullable, typename ElementValidateParams> | 126 template <bool element_is_nullable, typename ElementValidateParams> |
| 128 static void SerializeElements(Array<S> input, | 127 static void SerializeElements(Array<S> input, |
| 129 Buffer* buf, | 128 Buffer* buf, |
| 130 Array_Data<typename S::Data_*>* output) { | 129 Array_Data<typename S::Data_*>* output) { |
| 131 for (size_t i = 0; i < input.size(); ++i) { | 130 for (size_t i = 0; i < input.size(); ++i) { |
| 132 typename S::Data_* element; | 131 typename S::Data_* element; |
| 133 SerializeCaller<S, ElementValidateParams>::Run( | 132 SerializeCaller<S, ElementValidateParams>::Run( |
| 134 input[i].Pass(), buf, &element); | 133 input[i].Pass(), buf, &element); |
| 135 output->at(i) = element; | 134 output->at(i) = element; |
| 136 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 135 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 137 IsNonNullableValidationEnabled() && !element_is_nullable && !element, | 136 !element_is_nullable && !element, |
| 138 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); | 137 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 static void DeserializeElements( | 140 static void DeserializeElements( |
| 142 Array_Data<typename S::Data_*>* input, Array<S>* output) { | 141 Array_Data<typename S::Data_*>* input, Array<S>* output) { |
| 143 Array<S> result(input->size()); | 142 Array<S> result(input->size()); |
| 144 for (size_t i = 0; i < input->size(); ++i) { | 143 for (size_t i = 0; i < input->size(); ++i) { |
| 145 S element; | 144 S element; |
| 146 Deserialize_(input->at(i), &element); | 145 Deserialize_(input->at(i), &element); |
| 147 result[i] = element.Pass(); | 146 result[i] = element.Pass(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 MOJO_COMPILE_ASSERT( | 185 MOJO_COMPILE_ASSERT( |
| 187 (IsSame<ElementValidateParams, | 186 (IsSame<ElementValidateParams, |
| 188 ArrayValidateParams<0, false, NoValidateParams> >::value), | 187 ArrayValidateParams<0, false, NoValidateParams> >::value), |
| 189 String_type_has_unexpected_array_validate_params); | 188 String_type_has_unexpected_array_validate_params); |
| 190 | 189 |
| 191 for (size_t i = 0; i < input.size(); ++i) { | 190 for (size_t i = 0; i < input.size(); ++i) { |
| 192 String_Data* element; | 191 String_Data* element; |
| 193 Serialize_(input[i], buf, &element); | 192 Serialize_(input[i], buf, &element); |
| 194 output->at(i) = element; | 193 output->at(i) = element; |
| 195 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 194 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 196 IsNonNullableValidationEnabled() && !element_is_nullable && !element, | 195 !element_is_nullable && !element, |
| 197 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); | 196 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); |
| 198 } | 197 } |
| 199 } | 198 } |
| 200 static void DeserializeElements( | 199 static void DeserializeElements( |
| 201 Array_Data<String_Data*>* input, Array<String>* output) { | 200 Array_Data<String_Data*>* input, Array<String>* output) { |
| 202 Array<String> result(input->size()); | 201 Array<String> result(input->size()); |
| 203 for (size_t i = 0; i < input->size(); ++i) | 202 for (size_t i = 0; i < input->size(); ++i) |
| 204 Deserialize_(input->at(i), &result[i]); | 203 Deserialize_(input->at(i), &result[i]); |
| 205 output->Swap(&result); | 204 output->Swap(&result); |
| 206 } | 205 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (input) { | 243 if (input) { |
| 245 internal::ArraySerializer<E, F>::DeserializeElements(input, output); | 244 internal::ArraySerializer<E, F>::DeserializeElements(input, output); |
| 246 } else { | 245 } else { |
| 247 output->reset(); | 246 output->reset(); |
| 248 } | 247 } |
| 249 } | 248 } |
| 250 | 249 |
| 251 } // namespace mojo | 250 } // namespace mojo |
| 252 | 251 |
| 253 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 252 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
| OLD | NEW |