From 1d9b86d584542fbc34bf49726badaba2ca764228 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 8 Oct 2014 14:27:07 -0400 Subject: [PATCH] boost: drop dependency on is_fundamental in serialization There's only one case where a vector containing a fundamental type is serialized all-at-once, unsigned char. Anything else would lead to strange results. Use a dummy argument to overload in that case. --- src/serialize.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/serialize.h b/src/serialize.h index ff11edc06..8220fecb9 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -21,7 +21,6 @@ #include #include -#include class CAutoFile; class CDataStream; @@ -432,14 +431,15 @@ template void Serialize(Stream& os, const std::basi template void Unserialize(Stream& is, std::basic_string& str, int, int=0); // vector -template unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const boost::true_type&); -template unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const boost::false_type&); +// vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob. +template unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const unsigned char&); +template unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const V&); template inline unsigned int GetSerializeSize(const std::vector& v, int nType, int nVersion); -template void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const boost::true_type&); -template void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const boost::false_type&); +template void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const unsigned char&); +template void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const V&); template inline void Serialize(Stream& os, const std::vector& v, int nType, int nVersion); -template void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const boost::true_type&); -template void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const boost::false_type&); +template void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const unsigned char&); +template void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const V&); template inline void Unserialize(Stream& is, std::vector& v, int nType, int nVersion); // others derived from vector @@ -536,13 +536,13 @@ void Unserialize(Stream& is, std::basic_string& str, int, int) // vector // template -unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const boost::true_type&) +unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const unsigned char&) { return (GetSizeOfCompactSize(v.size()) + v.size() * sizeof(T)); } -template -unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const boost::false_type&) +template +unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nVersion, const V&) { unsigned int nSize = GetSizeOfCompactSize(v.size()); for (typename std::vector::const_iterator vi = v.begin(); vi != v.end(); ++vi) @@ -553,20 +553,20 @@ unsigned int GetSerializeSize_impl(const std::vector& v, int nType, int nV template inline unsigned int GetSerializeSize(const std::vector& v, int nType, int nVersion) { - return GetSerializeSize_impl(v, nType, nVersion, boost::is_fundamental()); + return GetSerializeSize_impl(v, nType, nVersion, T()); } template -void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const boost::true_type&) +void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const unsigned char&) { WriteCompactSize(os, v.size()); if (!v.empty()) os.write((char*)&v[0], v.size() * sizeof(T)); } -template -void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const boost::false_type&) +template +void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVersion, const V&) { WriteCompactSize(os, v.size()); for (typename std::vector::const_iterator vi = v.begin(); vi != v.end(); ++vi) @@ -576,12 +576,12 @@ void Serialize_impl(Stream& os, const std::vector& v, int nType, int nVers template inline void Serialize(Stream& os, const std::vector& v, int nType, int nVersion) { - Serialize_impl(os, v, nType, nVersion, boost::is_fundamental()); + Serialize_impl(os, v, nType, nVersion, T()); } template -void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const boost::true_type&) +void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const unsigned char&) { // Limit size per read so bogus size value won't cause out of memory v.clear(); @@ -596,8 +596,8 @@ void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, } } -template -void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const boost::false_type&) +template +void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, const V&) { v.clear(); unsigned int nSize = ReadCompactSize(is); @@ -617,7 +617,7 @@ void Unserialize_impl(Stream& is, std::vector& v, int nType, int nVersion, template inline void Unserialize(Stream& is, std::vector& v, int nType, int nVersion) { - Unserialize_impl(is, v, nType, nVersion, boost::is_fundamental()); + Unserialize_impl(is, v, nType, nVersion, T()); }