diff --git a/src/serialize.h b/src/serialize.h index f6c530a2b8..68296e896e 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -723,14 +723,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); @@ -833,10 +831,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)); } @@ -846,7 +843,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); @@ -869,10 +866,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& @@ -890,7 +886,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 2c27a54fc7..c974c265ce 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