| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/array_traits_carray.h" | 10 #include "mojo/public/cpp/bindings/array_traits_carray.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // calloc sets the memory to all zero. | 51 // calloc sets the memory to all zero. |
| 52 result_buffer = calloc(size, 1); | 52 result_buffer = calloc(size, 1); |
| 53 DCHECK(IsAligned(result_buffer)); | 53 DCHECK(IsAligned(result_buffer)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 FixedBuffer buffer; | 56 FixedBuffer buffer; |
| 57 buffer.Initialize(result_buffer, size); | 57 buffer.Initialize(result_buffer, size); |
| 58 typename MojomType::Struct::Data_* data = nullptr; | 58 typename MojomType::Struct::Data_* data = nullptr; |
| 59 Serialize<MojomType>(*input, &buffer, &data, &context); | 59 Serialize<MojomType>(*input, &buffer, &data, &context); |
| 60 | 60 |
| 61 data->EncodePointers(); | |
| 62 | |
| 63 if (need_copy) { | 61 if (need_copy) { |
| 64 memcpy(&result.front(), result_buffer, size); | 62 memcpy(&result.front(), result_buffer, size); |
| 65 free(result_buffer); | 63 free(result_buffer); |
| 66 } | 64 } |
| 67 | 65 |
| 68 return result; | 66 return result; |
| 69 } | 67 } |
| 70 | 68 |
| 71 template <typename MojomType, typename DataArrayType, typename UserType> | 69 template <typename MojomType, typename DataArrayType, typename UserType> |
| 72 bool StructDeserializeImpl(DataArrayType input, UserType* output) { | 70 bool StructDeserializeImpl(DataArrayType input, UserType* output) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 if (need_copy) { | 83 if (need_copy) { |
| 86 input_buffer = malloc(input.size()); | 84 input_buffer = malloc(input.size()); |
| 87 DCHECK(IsAligned(input_buffer)); | 85 DCHECK(IsAligned(input_buffer)); |
| 88 memcpy(input_buffer, &input.front(), input.size()); | 86 memcpy(input_buffer, &input.front(), input.size()); |
| 89 } | 87 } |
| 90 | 88 |
| 91 ValidationContext validation_context(input_buffer, input.size(), 0); | 89 ValidationContext validation_context(input_buffer, input.size(), 0); |
| 92 bool result = false; | 90 bool result = false; |
| 93 if (DataType::Validate(input_buffer, &validation_context)) { | 91 if (DataType::Validate(input_buffer, &validation_context)) { |
| 94 auto data = reinterpret_cast<DataType*>(input_buffer); | 92 auto data = reinterpret_cast<DataType*>(input_buffer); |
| 95 if (data) | |
| 96 data->DecodePointers(); | |
| 97 | |
| 98 SerializationContext context; | 93 SerializationContext context; |
| 99 result = Deserialize<MojomType>(data, output, &context); | 94 result = Deserialize<MojomType>(data, output, &context); |
| 100 } | 95 } |
| 101 | 96 |
| 102 if (need_copy) | 97 if (need_copy) |
| 103 free(input_buffer); | 98 free(input_buffer); |
| 104 | 99 |
| 105 return result; | 100 return result; |
| 106 } | 101 } |
| 107 | 102 |
| 108 } // namespace internal | 103 } // namespace internal |
| 109 } // namespace mojo | 104 } // namespace mojo |
| 110 | 105 |
| 111 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_H_ | 106 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_H_ |
| OLD | NEW |