Support serialization as another type without casting

This adds a READWRITEAS(type, obj) macro which serializes obj as if it
were casted to (const type&) when const, and to (type&) when non-const.

This makes it usable in serialization code that uses a single
implementation for both serialization and deserializing, which doesn't
know the constness of the object involved.
This commit is contained in:
Pieter Wuille
2017-07-07 16:06:56 -07:00
parent 8ee5c7b747
commit 818dc74ba2
7 changed files with 13 additions and 8 deletions

View File

@@ -59,7 +59,7 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(*static_cast<CAddress*>(this));
READWRITEAS(CAddress, *this);
READWRITE(source);
READWRITE(nLastSuccess);
READWRITE(nAttempts);