| 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 <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return count * sizeof(StructPointer<S_Data>); | 68 return count * sizeof(StructPointer<S_Data>); |
| 69 } | 69 } |
| 70 static size_t GetItemSize(const S& item) { | 70 static size_t GetItemSize(const S& item) { |
| 71 return item ? GetSerializedSize_(*UnwrapConstStructPtr<S>::value(item)) : 0; | 71 return item ? GetSerializedSize_(*UnwrapConstStructPtr<S>::value(item)) : 0; |
| 72 } | 72 } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 template <typename U, typename U_Data> | 75 template <typename U, typename U_Data> |
| 76 struct MapSerializer<U, U_Data, true, true> { | 76 struct MapSerializer<U, U_Data, true, true> { |
| 77 static size_t GetBaseArraySize(size_t count) { | 77 static size_t GetBaseArraySize(size_t count) { |
| 78 return count * sizeof(U_Data); | 78 // GetSerializedSize_ (called in GetItemSize()) will account for |
| 79 // sizeof(U_Data), so prevent double counting by having this count be 0. |
| 80 return 0; |
| 79 } | 81 } |
| 80 static size_t GetItemSize(const U& item) { | 82 static size_t GetItemSize(const U& item) { return GetSerializedSize_(item); } |
| 81 return GetSerializedSize_(item, true); | |
| 82 } | |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 template <> | 85 template <> |
| 86 struct MapSerializer<String, String_Data*, false, false> { | 86 struct MapSerializer<String, String_Data*, false, false> { |
| 87 static size_t GetBaseArraySize(size_t count) { | 87 static size_t GetBaseArraySize(size_t count) { |
| 88 return count * sizeof(StringPointer); | 88 return count * sizeof(StringPointer); |
| 89 } | 89 } |
| 90 static size_t GetItemSize(const String& item) { | 90 static size_t GetItemSize(const String& item) { |
| 91 return GetSerializedSize_(item); | 91 return GetSerializedSize_(item); |
| 92 } | 92 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); | 204 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); |
| 205 } else { | 205 } else { |
| 206 output->reset(); | 206 output->reset(); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace mojo | 210 } // namespace mojo |
| 211 | 211 |
| 212 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 212 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
| OLD | NEW |