Add a generic approach for (de)serialization of objects using code in other classes
Summary:
PR description:
This introduces a const-correct generic approach for serializing objects using custom
serializers (defined separately from the object being serialized), then converts VARINT
to use that approach, and then converts chain.h to the new framework (including
the new const-correct VARINT macro).
Commit message:
This adds the (internal) Wrapper class, and the Using function that uses it. Given
a class F that implements Ser(stream, const object&) and Unser(stream, object&)
functions, this permits writing e.g. READWRITE(Using<F>(object)).
This is a backport of Core PR17896 [1/3]
https://github.com/bitcoin/bitcoin/pull/17896/commits/ca62563df341786d1d1809a037d8b592924e78c4
Test Plan: ninja
Reviewers: #bitcoin_abc, majcosta
Reviewed By: #bitcoin_abc, majcosta
Differential Revision: https://reviews.bitcoinabc.org/D8626