| 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_MAP_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
| 7 | 7 |
| 8 #include <utility> |
| 9 |
| 8 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 9 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" | 11 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" |
| 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" | 12 #include "mojo/public/cpp/bindings/lib/map_internal.h" |
| 11 #include "mojo/public/cpp/bindings/lib/string_serialization.h" | 13 #include "mojo/public/cpp/bindings/lib/string_serialization.h" |
| 12 #include "mojo/public/cpp/bindings/map.h" | 14 #include "mojo/public/cpp/bindings/map.h" |
| 13 | 15 |
| 14 namespace mojo { | 16 namespace mojo { |
| 15 | 17 |
| 16 template <typename Key, typename Value> | 18 template <typename Key, typename Value> |
| 17 inline size_t GetSerializedSize_(const Map<Key, Value>& input); | 19 inline size_t GetSerializedSize_(const Map<Key, Value>& input); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 const internal::ArrayValidateParams* value_validate_params) { | 143 const internal::ArrayValidateParams* value_validate_params) { |
| 142 if (input) { | 144 if (input) { |
| 143 internal::Map_Data<DataKey, DataValue>* result = | 145 internal::Map_Data<DataKey, DataValue>* result = |
| 144 internal::Map_Data<DataKey, DataValue>::New(buf); | 146 internal::Map_Data<DataKey, DataValue>::New(buf); |
| 145 if (result) { | 147 if (result) { |
| 146 Array<MapKey> keys; | 148 Array<MapKey> keys; |
| 147 Array<MapValue> values; | 149 Array<MapValue> values; |
| 148 input.DecomposeMapTo(&keys, &values); | 150 input.DecomposeMapTo(&keys, &values); |
| 149 const internal::ArrayValidateParams* key_validate_params = | 151 const internal::ArrayValidateParams* key_validate_params = |
| 150 internal::MapKeyValidateParamsFactory<DataKey>::Get(); | 152 internal::MapKeyValidateParamsFactory<DataKey>::Get(); |
| 151 SerializeArray_(keys.Pass(), buf, &result->keys.ptr, key_validate_params); | 153 SerializeArray_(std::move(keys), buf, &result->keys.ptr, |
| 152 SerializeArray_(values.Pass(), buf, &result->values.ptr, | 154 key_validate_params); |
| 155 SerializeArray_(std::move(values), buf, &result->values.ptr, |
| 153 value_validate_params); | 156 value_validate_params); |
| 154 } | 157 } |
| 155 *output = result; | 158 *output = result; |
| 156 } else { | 159 } else { |
| 157 *output = nullptr; | 160 *output = nullptr; |
| 158 } | 161 } |
| 159 } | 162 } |
| 160 | 163 |
| 161 template <typename MapKey, | 164 template <typename MapKey, |
| 162 typename MapValue, | 165 typename MapValue, |
| 163 typename DataKey, | 166 typename DataKey, |
| 164 typename DataValue> | 167 typename DataValue> |
| 165 inline bool Deserialize_(internal::Map_Data<DataKey, DataValue>* input, | 168 inline bool Deserialize_(internal::Map_Data<DataKey, DataValue>* input, |
| 166 Map<MapKey, MapValue>* output, | 169 Map<MapKey, MapValue>* output, |
| 167 internal::SerializationContext* context) { | 170 internal::SerializationContext* context) { |
| 168 bool success = true; | 171 bool success = true; |
| 169 if (input) { | 172 if (input) { |
| 170 Array<MapKey> keys; | 173 Array<MapKey> keys; |
| 171 Array<MapValue> values; | 174 Array<MapValue> values; |
| 172 | 175 |
| 173 // Note that we rely on complete deserialization taking place in order to | 176 // Note that we rely on complete deserialization taking place in order to |
| 174 // transfer ownership of all encoded handles. Therefore we don't | 177 // transfer ownership of all encoded handles. Therefore we don't |
| 175 // short-circuit on failure here. | 178 // short-circuit on failure here. |
| 176 if (!Deserialize_(input->keys.ptr, &keys, context)) | 179 if (!Deserialize_(input->keys.ptr, &keys, context)) |
| 177 success = false; | 180 success = false; |
| 178 if (!Deserialize_(input->values.ptr, &values, context)) | 181 if (!Deserialize_(input->values.ptr, &values, context)) |
| 179 success = false; | 182 success = false; |
| 180 | 183 |
| 181 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); | 184 *output = Map<MapKey, MapValue>(std::move(keys), std::move(values)); |
| 182 } else { | 185 } else { |
| 183 output->reset(); | 186 output->reset(); |
| 184 } | 187 } |
| 185 return success; | 188 return success; |
| 186 } | 189 } |
| 187 | 190 |
| 188 } // namespace mojo | 191 } // namespace mojo |
| 189 | 192 |
| 190 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 193 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
| OLD | NEW |