Support serialization as another type without casting
Summary:
Backport of PR12731 (818dc74)
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.
Test Plan: make check
Reviewers: #bitcoin_abc, deadalnix, Fabien
Reviewed By: #bitcoin_abc, Fabien
Maniphest Tasks: T633
Differential Revision: https://reviews.bitcoinabc.org/D2932