diff --git a/src/serialize.h b/src/serialize.h index 19585c630ab..a0b012b25c8 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -710,14 +710,12 @@ template void Unserialize(Stream& is, std::basic_st /** * prevector - * prevectors of unsigned char are a special case and are intended to be serialized as a single opaque blob. */ template inline void Serialize(Stream& os, const prevector& v); template inline void Unserialize(Stream& is, prevector& v); /** * vector - * vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob. */ template inline void Serialize(Stream& os, const std::vector& v); template inline void Unserialize(Stream& is, std::vector& v); @@ -820,10 +818,9 @@ void Unserialize(Stream& is, std::basic_string& str) template void Serialize(Stream& os, const prevector& v) { - if constexpr (std::is_same_v) { + if constexpr (BasicByte) { // Use optimized version for unformatted basic bytes WriteCompactSize(os, v.size()); - if (!v.empty()) - os.write(MakeByteSpan(v)); + if (!v.empty()) os.write(MakeByteSpan(v)); } else { Serialize(os, Using>(v)); } @@ -833,7 +830,7 @@ void Serialize(Stream& os, const prevector& v) template void Unserialize(Stream& is, prevector& v) { - if constexpr (std::is_same_v) { + if constexpr (BasicByte) { // Use optimized version for unformatted basic bytes // Limit size per read so bogus size value won't cause out of memory v.clear(); unsigned int nSize = ReadCompactSize(is); @@ -856,10 +853,9 @@ void Unserialize(Stream& is, prevector& v) template void Serialize(Stream& os, const std::vector& v) { - if constexpr (std::is_same_v) { + if constexpr (BasicByte) { // Use optimized version for unformatted basic bytes WriteCompactSize(os, v.size()); - if (!v.empty()) - os.write(MakeByteSpan(v)); + if (!v.empty()) os.write(MakeByteSpan(v)); } else if constexpr (std::is_same_v) { // A special case for std::vector, as dereferencing // std::vector::const_iterator does not result in a const bool& @@ -877,7 +873,7 @@ void Serialize(Stream& os, const std::vector& v) template void Unserialize(Stream& is, std::vector& v) { - if constexpr (std::is_same_v) { + if constexpr (BasicByte) { // Use optimized version for unformatted basic bytes // Limit size per read so bogus size value won't cause out of memory v.clear(); unsigned int nSize = ReadCompactSize(is); diff --git a/src/span.h b/src/span.h index 2c27a54fc76..c974c265cec 100644 --- a/src/span.h +++ b/src/span.h @@ -287,9 +287,11 @@ Span MakeWritableByteSpan(V&& v) noexcept // Helper functions to safely cast basic byte pointers to unsigned char pointers. inline unsigned char* UCharCast(char* c) { return reinterpret_cast(c); } inline unsigned char* UCharCast(unsigned char* c) { return c; } +inline unsigned char* UCharCast(signed char* c) { return reinterpret_cast(c); } inline unsigned char* UCharCast(std::byte* c) { return reinterpret_cast(c); } inline const unsigned char* UCharCast(const char* c) { return reinterpret_cast(c); } inline const unsigned char* UCharCast(const unsigned char* c) { return c; } +inline const unsigned char* UCharCast(const signed char* c) { return reinterpret_cast(c); } inline const unsigned char* UCharCast(const std::byte* c) { return reinterpret_cast(c); } // Helper concept for the basic byte types. template