| 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_FORWARD_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_FORWARD_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_FORWARD_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_FORWARD_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/array.h" | |
| 11 #include "mojo/public/cpp/bindings/array_traits.h" | 10 #include "mojo/public/cpp/bindings/array_traits.h" |
| 12 #include "mojo/public/cpp/bindings/lib/wtf_string_serialization.h" | 11 #include "mojo/public/cpp/bindings/lib/wtf_string_serialization.h" |
| 13 #include "mojo/public/cpp/bindings/map.h" | |
| 14 #include "mojo/public/cpp/bindings/native_struct.h" | 12 #include "mojo/public/cpp/bindings/native_struct.h" |
| 15 #include "mojo/public/cpp/bindings/string_traits.h" | 13 #include "mojo/public/cpp/bindings/string_traits.h" |
| 16 #include "mojo/public/cpp/bindings/struct_traits.h" | 14 #include "mojo/public/cpp/bindings/struct_traits.h" |
| 17 | 15 |
| 18 // This file is included by serialization implementation files to avoid circular | 16 // This file is included by serialization implementation files to avoid circular |
| 19 // includes. | 17 // includes. |
| 20 // Users of the serialization funtions should include serialization.h (and also | 18 // Users of the serialization funtions should include serialization.h (and also |
| 21 // wtf_serialization.h if necessary). | 19 // wtf_serialization.h if necessary). |
| 22 | 20 |
| 23 namespace mojo { | 21 namespace mojo { |
| 24 | |
| 25 template <typename T> | |
| 26 class WTFArray; | |
| 27 | |
| 28 namespace internal { | 22 namespace internal { |
| 29 | 23 |
| 30 template <typename T> | |
| 31 class Array_Data; | |
| 32 | |
| 33 class ArrayValidateParams; | |
| 34 | |
| 35 class Buffer; | 24 class Buffer; |
| 36 | 25 |
| 37 template <typename K, typename V> | |
| 38 class Map_Data; | |
| 39 | |
| 40 class NativeStruct_Data; | 26 class NativeStruct_Data; |
| 41 | 27 |
| 42 struct SerializationContext; | 28 struct SerializationContext; |
| 43 | 29 |
| 44 template <typename T> | |
| 45 struct ShouldUseNativeSerializer; | |
| 46 | |
| 47 template <typename MojomType, typename MaybeConstUserType> | 30 template <typename MojomType, typename MaybeConstUserType> |
| 48 struct Serializer; | 31 struct Serializer; |
| 49 | 32 |
| 33 // PrepareToSerialize() must be matched by a Serialize() for the same input |
| 34 // later. Moreover, within the same SerializationContext if PrepareToSerialize() |
| 35 // is called for |input_1|, ..., |input_n|, Serialize() must be called for |
| 36 // those objects in the exact same order. |
| 50 template <typename MojomType, typename InputUserType, typename... Args> | 37 template <typename MojomType, typename InputUserType, typename... Args> |
| 51 size_t PrepareToSerialize(InputUserType&& input, Args&&... args) { | 38 size_t PrepareToSerialize(InputUserType&& input, Args&&... args) { |
| 52 return Serializer<MojomType, | 39 return Serializer<MojomType, |
| 53 typename std::remove_reference<InputUserType>::type>:: | 40 typename std::remove_reference<InputUserType>::type>:: |
| 54 PrepareToSerialize(std::forward<InputUserType>(input), | 41 PrepareToSerialize(std::forward<InputUserType>(input), |
| 55 std::forward<Args>(args)...); | 42 std::forward<Args>(args)...); |
| 56 } | 43 } |
| 57 | 44 |
| 58 template <typename MojomType, typename InputUserType, typename... Args> | 45 template <typename MojomType, typename InputUserType, typename... Args> |
| 59 void Serialize(InputUserType&& input, Args&&... args) { | 46 void Serialize(InputUserType&& input, Args&&... args) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 85 void Serialize_(NativeStructPtr input, | 72 void Serialize_(NativeStructPtr input, |
| 86 internal::Buffer* buffer, | 73 internal::Buffer* buffer, |
| 87 internal::NativeStruct_Data** output, | 74 internal::NativeStruct_Data** output, |
| 88 internal::SerializationContext* context); | 75 internal::SerializationContext* context); |
| 89 | 76 |
| 90 bool Deserialize_(internal::NativeStruct_Data* input, | 77 bool Deserialize_(internal::NativeStruct_Data* input, |
| 91 NativeStructPtr* output, | 78 NativeStructPtr* output, |
| 92 internal::SerializationContext* context); | 79 internal::SerializationContext* context); |
| 93 | 80 |
| 94 // ----------------------------------------------------------------------------- | 81 // ----------------------------------------------------------------------------- |
| 95 // Forward declaration for Array. | |
| 96 | |
| 97 template <typename E> | |
| 98 inline size_t GetSerializedSize_(const Array<E>& input, | |
| 99 internal::SerializationContext* context); | |
| 100 | |
| 101 template <typename E> | |
| 102 inline void SerializeArray_( | |
| 103 Array<E> input, | |
| 104 internal::Buffer* buf, | |
| 105 typename Array<E>::Data_** output, | |
| 106 const internal::ArrayValidateParams* validate_params, | |
| 107 internal::SerializationContext* context); | |
| 108 | |
| 109 template <typename E> | |
| 110 inline bool Deserialize_(typename Array<E>::Data_* input, | |
| 111 Array<E>* output, | |
| 112 internal::SerializationContext* context); | |
| 113 | |
| 114 // ----------------------------------------------------------------------------- | |
| 115 // Forward declaration for WTFArray. | |
| 116 | |
| 117 template <typename E> | |
| 118 inline size_t GetSerializedSize_(const WTFArray<E>& input, | |
| 119 internal::SerializationContext* context); | |
| 120 | |
| 121 template <typename E> | |
| 122 inline void SerializeArray_( | |
| 123 WTFArray<E> input, | |
| 124 internal::Buffer* buf, | |
| 125 typename WTFArray<E>::Data_** output, | |
| 126 const internal::ArrayValidateParams* validate_params, | |
| 127 internal::SerializationContext* context); | |
| 128 | |
| 129 template <typename E> | |
| 130 inline bool Deserialize_(typename WTFArray<E>::Data_* input, | |
| 131 WTFArray<E>* output, | |
| 132 internal::SerializationContext* context); | |
| 133 | |
| 134 // ----------------------------------------------------------------------------- | |
| 135 // Forward declaration for Map. | |
| 136 | |
| 137 template <typename MapKey, typename MapValue> | |
| 138 inline size_t GetSerializedSize_(const Map<MapKey, MapValue>& input, | |
| 139 internal::SerializationContext* context); | |
| 140 | |
| 141 template <typename MapKey, | |
| 142 typename MapValue, | |
| 143 typename DataKey, | |
| 144 typename DataValue> | |
| 145 inline void SerializeMap_( | |
| 146 Map<MapKey, MapValue> input, | |
| 147 internal::Buffer* buf, | |
| 148 internal::Map_Data<DataKey, DataValue>** output, | |
| 149 const internal::ArrayValidateParams* value_validate_params, | |
| 150 internal::SerializationContext* context); | |
| 151 | |
| 152 template <typename MapKey, | |
| 153 typename MapValue, | |
| 154 typename DataKey, | |
| 155 typename DataValue> | |
| 156 inline bool Deserialize_(internal::Map_Data<DataKey, DataValue>* input, | |
| 157 Map<MapKey, MapValue>* output, | |
| 158 internal::SerializationContext* context); | |
| 159 | |
| 160 // ----------------------------------------------------------------------------- | |
| 161 // Forward declaration for String. | 82 // Forward declaration for String. |
| 162 | 83 |
| 163 size_t GetSerializedSize_(const String& input, | 84 size_t GetSerializedSize_(const String& input, |
| 164 internal::SerializationContext* context); | 85 internal::SerializationContext* context); |
| 165 void Serialize_(const String& input, | 86 void Serialize_(const String& input, |
| 166 internal::Buffer* buffer, | 87 internal::Buffer* buffer, |
| 167 internal::String_Data** output, | 88 internal::String_Data** output, |
| 168 internal::SerializationContext* context); | 89 internal::SerializationContext* context); |
| 169 bool Deserialize_(internal::String_Data* input, | 90 bool Deserialize_(internal::String_Data* input, |
| 170 String* output, | 91 String* output, |
| 171 internal::SerializationContext* context); | 92 internal::SerializationContext* context); |
| 172 | 93 |
| 173 } // namespace mojo | 94 } // namespace mojo |
| 174 | 95 |
| 175 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_FORWARD_H_ | 96 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_FORWARD_H_ |
| OLD | NEW |