mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge #12731: Support serialization as another type without casting
818dc74 Support serialization as another type without casting (Pieter Wuille)
Pull request description:
This adds a `READWRITEAS(type, obj)` macro which serializes `obj` as if it were converted to `const type&` when `const`, and to `type&` when non-`const`. No actual cast is involved, so this only works when this conversion can be done automatically.
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 is a redo of #12712, using a slightly different interface.
Tree-SHA512: 262f0257284ff99b5ffaec9b997c194e221522ba35c3ac8eaa9bb344449d7ea0a314de254dc77449fa7aaa600f8cd9a24da65aade8c1ec6aa80c6e9a7bba5ca7
This commit is contained in:
@@ -349,7 +349,7 @@ public:
|
||||
uint64_t nServicesInt = nServices;
|
||||
READWRITE(nServicesInt);
|
||||
nServices = static_cast<ServiceFlags>(nServicesInt);
|
||||
READWRITE(*static_cast<CService*>(this));
|
||||
READWRITEAS(CService, *this);
|
||||
}
|
||||
|
||||
// TODO: make private (improves encapsulation)
|
||||
|
||||
Reference in New Issue
Block a user