mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Merge ecbf4bae9c into merged_master (Bitcoin PR bitcoin/bitcoin#29114)
This commit is contained in:
commit
9fe297ebfb
2 changed files with 8 additions and 10 deletions
|
|
@ -723,14 +723,12 @@ template<typename Stream, typename C> 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<typename Stream, unsigned int N, typename T> inline void Serialize(Stream& os, const prevector<N, T>& v);
|
||||
template<typename Stream, unsigned int N, typename T> inline void Unserialize(Stream& is, prevector<N, T>& v);
|
||||
|
||||
/**
|
||||
* vector
|
||||
* vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob.
|
||||
*/
|
||||
template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v);
|
||||
template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v);
|
||||
|
|
@ -833,10 +831,9 @@ void Unserialize(Stream& is, std::basic_string<C>& str)
|
|||
template <typename Stream, unsigned int N, typename T>
|
||||
void Serialize(Stream& os, const prevector<N, T>& v)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
if constexpr (BasicByte<T>) { // 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<VectorFormatter<DefaultFormatter>>(v));
|
||||
}
|
||||
|
|
@ -846,7 +843,7 @@ void Serialize(Stream& os, const prevector<N, T>& v)
|
|||
template <typename Stream, unsigned int N, typename T>
|
||||
void Unserialize(Stream& is, prevector<N, T>& v)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
if constexpr (BasicByte<T>) { // 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<N, T>& v)
|
|||
template <typename Stream, typename T, typename A>
|
||||
void Serialize(Stream& os, const std::vector<T, A>& v)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
if constexpr (BasicByte<T>) { // 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<T, bool>) {
|
||||
// A special case for std::vector<bool>, as dereferencing
|
||||
// std::vector<bool>::const_iterator does not result in a const bool&
|
||||
|
|
@ -890,7 +886,7 @@ void Serialize(Stream& os, const std::vector<T, A>& v)
|
|||
template <typename Stream, typename T, typename A>
|
||||
void Unserialize(Stream& is, std::vector<T, A>& v)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, unsigned char>) {
|
||||
if constexpr (BasicByte<T>) { // 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);
|
||||
|
|
|
|||
|
|
@ -287,9 +287,11 @@ Span<std::byte> 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<unsigned char*>(c); }
|
||||
inline unsigned char* UCharCast(unsigned char* c) { return c; }
|
||||
inline unsigned char* UCharCast(signed char* c) { return reinterpret_cast<unsigned char*>(c); }
|
||||
inline unsigned char* UCharCast(std::byte* c) { return reinterpret_cast<unsigned char*>(c); }
|
||||
inline const unsigned char* UCharCast(const char* c) { return reinterpret_cast<const unsigned char*>(c); }
|
||||
inline const unsigned char* UCharCast(const unsigned char* c) { return c; }
|
||||
inline const unsigned char* UCharCast(const signed char* c) { return reinterpret_cast<const unsigned char*>(c); }
|
||||
inline const unsigned char* UCharCast(const std::byte* c) { return reinterpret_cast<const unsigned char*>(c); }
|
||||
// Helper concept for the basic byte types.
|
||||
template <typename B>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue