Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/native_serialization.h |
| diff --git a/mojo/public/cpp/bindings/lib/native_serialization.h b/mojo/public/cpp/bindings/lib/native_serialization.h |
| index 3c2e54efac58d2416d45b6ca3934afd582f94cdd..2d16ac139325d30606887ac17f0c6adf6d4b6e69 100644 |
| --- a/mojo/public/cpp/bindings/lib/native_serialization.h |
| +++ b/mojo/public/cpp/bindings/lib/native_serialization.h |
| @@ -29,7 +29,9 @@ struct ShouldUseNativeSerializer { static const bool value = false; }; |
| template <typename T> |
| size_t GetSerializedSizeNative_(const T& value) { |
| - return IPC::ParamTraits<T>::GetSize(value); |
| + base::PickleSizer sizer; |
| + IPC::ParamTraits<T>::GetSize(&sizer, value); |
| + return sizer.payload_size(); |
| } |
| template <typename T> |
| @@ -46,8 +48,20 @@ void SerializeNative_(const T& value, |
| base::Pickle* pickle = pickler->pickle(); |
| const char* data_start = pickle->end_of_payload(); |
| +#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| + size_t size_before_write = pickle->payload_size(); |
| +#endif |
| + |
| IPC::ParamTraits<T>::Write(pickle, value); |
| +#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| + DCHECK_GE(pickle->payload_size(), size_before_write); |
|
jam
2016/02/04 18:34:01
this is checking that the payload size didn't shri
|
| + // Explicitly validate that the value returned by GetSize() always equals the |
| + // number of bytes actually written by Write(). |
| + size_t bytes_written = pickle->payload_size() - size_before_write; |
| + DCHECK_EQ(bytes_written, GetSerializedSizeNative_(value)); |
| +#endif |
| + |
| // Fix up the ArrayHeader so that num_elements contains the length of the |
| // pickled data. |
| size_t pickled_size = pickle->end_of_payload() - data_start; |