mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-09 05:14:22 +01:00
serialize: move ser_action functions out of global namespace
This commit is contained in:
parent
f1a9fd627b
commit
bf147bfffa
1 changed files with 54 additions and 52 deletions
106
src/serialize.h
106
src/serialize.h
|
@ -167,9 +167,9 @@ const Out& AsBase(const In& x)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define READWRITE(...) (::SerReadWriteMany(s, ser_action, __VA_ARGS__))
|
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
|
||||||
#define SER_READ(obj, code) ::SerRead(s, ser_action, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
|
#define SER_READ(obj, code) ser_action.SerRead(s, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
|
||||||
#define SER_WRITE(obj, code) ::SerWrite(s, ser_action, obj, [&](Stream& s, const Type& obj) { code; })
|
#define SER_WRITE(obj, code) ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement the Ser and Unser methods needed for implementing a formatter (see Using below).
|
* Implement the Ser and Unser methods needed for implementing a formatter (see Using below).
|
||||||
|
@ -1006,17 +1006,65 @@ void Unserialize(Stream& is, std::shared_ptr<const T>& p)
|
||||||
p = std::make_shared<const T>(deserialize, is);
|
p = std::make_shared<const T>(deserialize, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Support for (un)serializing many things at once
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <typename Stream, typename... Args>
|
||||||
|
void SerializeMany(Stream& s, const Args&... args)
|
||||||
|
{
|
||||||
|
(::Serialize(s, args), ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Stream, typename... Args>
|
||||||
|
inline void UnserializeMany(Stream& s, Args&&... args)
|
||||||
|
{
|
||||||
|
(::Unserialize(s, args), ...);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for all macros providing or using the ser_action parameter of the SerializationOps method.
|
* Support for all macros providing or using the ser_action parameter of the SerializationOps method.
|
||||||
*/
|
*/
|
||||||
struct ActionSerialize {
|
struct ActionSerialize {
|
||||||
constexpr bool ForRead() const { return false; }
|
static constexpr bool ForRead() { return false; }
|
||||||
|
|
||||||
|
template<typename Stream, typename... Args>
|
||||||
|
static void SerReadWriteMany(Stream& s, const Args&... args)
|
||||||
|
{
|
||||||
|
::SerializeMany(s, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream, typename Type, typename Fn>
|
||||||
|
static void SerRead(Stream& s, Type&&, Fn&&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream, typename Type, typename Fn>
|
||||||
|
static void SerWrite(Stream& s, Type&& obj, Fn&& fn)
|
||||||
|
{
|
||||||
|
fn(s, std::forward<Type>(obj));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct ActionUnserialize {
|
struct ActionUnserialize {
|
||||||
constexpr bool ForRead() const { return true; }
|
static constexpr bool ForRead() { return true; }
|
||||||
};
|
|
||||||
|
|
||||||
|
template<typename Stream, typename... Args>
|
||||||
|
static void SerReadWriteMany(Stream& s, Args&&... args)
|
||||||
|
{
|
||||||
|
::UnserializeMany(s, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream, typename Type, typename Fn>
|
||||||
|
static void SerRead(Stream& s, Type&& obj, Fn&& fn)
|
||||||
|
{
|
||||||
|
fn(s, std::forward<Type>(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream, typename Type, typename Fn>
|
||||||
|
static void SerWrite(Stream& s, Type&&, Fn&&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* ::GetSerializeSize implementations
|
/* ::GetSerializeSize implementations
|
||||||
*
|
*
|
||||||
|
@ -1063,52 +1111,6 @@ public:
|
||||||
int GetVersion() const { return nVersion; }
|
int GetVersion() const { return nVersion; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Stream, typename... Args>
|
|
||||||
void SerializeMany(Stream& s, const Args&... args)
|
|
||||||
{
|
|
||||||
(::Serialize(s, args), ...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Stream, typename... Args>
|
|
||||||
inline void UnserializeMany(Stream& s, Args&&... args)
|
|
||||||
{
|
|
||||||
(::Unserialize(s, args), ...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename... Args>
|
|
||||||
inline void SerReadWriteMany(Stream& s, ActionSerialize ser_action, const Args&... args)
|
|
||||||
{
|
|
||||||
::SerializeMany(s, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename... Args>
|
|
||||||
inline void SerReadWriteMany(Stream& s, ActionUnserialize ser_action, Args&&... args)
|
|
||||||
{
|
|
||||||
::UnserializeMany(s, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename Type, typename Fn>
|
|
||||||
inline void SerRead(Stream& s, ActionSerialize ser_action, Type&&, Fn&&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename Type, typename Fn>
|
|
||||||
inline void SerRead(Stream& s, ActionUnserialize ser_action, Type&& obj, Fn&& fn)
|
|
||||||
{
|
|
||||||
fn(s, std::forward<Type>(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename Type, typename Fn>
|
|
||||||
inline void SerWrite(Stream& s, ActionSerialize ser_action, Type&& obj, Fn&& fn)
|
|
||||||
{
|
|
||||||
fn(s, std::forward<Type>(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Stream, typename Type, typename Fn>
|
|
||||||
inline void SerWrite(Stream& s, ActionUnserialize ser_action, Type&&, Fn&&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename I>
|
template<typename I>
|
||||||
inline void WriteVarInt(CSizeComputer &s, I n)
|
inline void WriteVarInt(CSizeComputer &s, I n)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue