[backport#17850] Introduce new serialization macros without casts
Summary:
This new approach uses a static method which takes the object as
a argument. This has the advantage that its constness can be a
template parameter, allowing a single implementation that sees the
object as const for serialization and non-const for deserialization,
without casts.More boilerplate is included in the new macro as well.
This is a backport of Core PR17850 [1/2]
Commit https://github.com/bitcoin/bitcoin/pull/17850/commits/ca33451535dc29f64d37c49af8b22142d7716d0d
Test Plan: ninja
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D8391