| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 MojomTypeCategory::HANDLE | | 281 MojomTypeCategory::HANDLE | |
| 282 MojomTypeCategory::INTERFACE | | 282 MojomTypeCategory::INTERFACE | |
| 283 MojomTypeCategory::INTERFACE_REQUEST>::value>::type> { | 283 MojomTypeCategory::INTERFACE_REQUEST>::value>::type> { |
| 284 using UserType = typename std::remove_const<MaybeConstUserType>::type; | 284 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| 285 using Data = typename MojomTypeTraits<MojomType>::Data; | 285 using Data = typename MojomTypeTraits<MojomType>::Data; |
| 286 using Element = typename MojomType::Element; | 286 using Element = typename MojomType::Element; |
| 287 using Traits = ArrayTraits<UserType>; | 287 using Traits = ArrayTraits<UserType>; |
| 288 | 288 |
| 289 static size_t GetSerializedSize(UserTypeIterator* input, | 289 static size_t GetSerializedSize(UserTypeIterator* input, |
| 290 SerializationContext* context) { | 290 SerializationContext* context) { |
| 291 return sizeof(Data) + | 291 size_t element_count = input->GetSize(); |
| 292 Align(input->GetSize() * sizeof(typename Data::Element)); | 292 if (BelongsTo<Element, |
| 293 MojomTypeCategory::ASSOCIATED_INTERFACE | |
| 294 MojomTypeCategory::ASSOCIATED_INTERFACE_REQUEST>::value) { |
| 295 for (size_t i = 0; i < element_count; ++i) { |
| 296 typename UserTypeIterator::GetNextResult next = input->GetNext(); |
| 297 size_t size = PrepareToSerialize<Element>(next, context); |
| 298 DCHECK_EQ(size, 0u); |
| 299 } |
| 300 } |
| 301 return sizeof(Data) + Align(element_count * sizeof(typename Data::Element)); |
| 293 } | 302 } |
| 294 | 303 |
| 295 static void SerializeElements(UserTypeIterator* input, | 304 static void SerializeElements(UserTypeIterator* input, |
| 296 Buffer* buf, | 305 Buffer* buf, |
| 297 Data* output, | 306 Data* output, |
| 298 const ContainerValidateParams* validate_params, | 307 const ContainerValidateParams* validate_params, |
| 299 SerializationContext* context) { | 308 SerializationContext* context) { |
| 300 DCHECK(!validate_params->element_validate_params) | 309 DCHECK(!validate_params->element_validate_params) |
| 301 << "Handle or interface type should not have array validate params"; | 310 << "Handle or interface type should not have array validate params"; |
| 302 | 311 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (!input) | 546 if (!input) |
| 538 return CallSetToNullIfExists<Traits>(output); | 547 return CallSetToNullIfExists<Traits>(output); |
| 539 return Impl::DeserializeElements(input, output, context); | 548 return Impl::DeserializeElements(input, output, context); |
| 540 } | 549 } |
| 541 }; | 550 }; |
| 542 | 551 |
| 543 } // namespace internal | 552 } // namespace internal |
| 544 } // namespace mojo | 553 } // namespace mojo |
| 545 | 554 |
| 546 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 555 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
| OLD | NEW |