From 05e5ee1be662532e9a93f971d47775e0b87a6ff5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <6098974-kittywhiskers@users.noreply.gitlab.com> Date: Wed, 26 May 2021 15:04:39 +0300 Subject: [PATCH] partial merge #8149: import OverrideStream from "BIP144: Serialization, hashes, relay (sender side)" --- src/streams.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/streams.h b/src/streams.h index 21db4ba6dd537..5d0be5ab9ca0c 100644 --- a/src/streams.h +++ b/src/streams.h @@ -22,6 +22,33 @@ #include #include +template +class OverrideStream +{ + Stream* stream; +public: + const int nType; + const int nVersion; + + OverrideStream(Stream* stream_, int nType_, int nVersion_) : stream(stream_), nType(nType_), nVersion(nVersion_) {} + + template + OverrideStream& operator<<(const T& obj) + { + // Serialize to this stream + ::Serialize(*this->stream, obj); + return (*this); + } + + template + OverrideStream& operator>>(T& obj) + { + // Unserialize from this stream + ::Unserialize(*this->stream, obj); + return (*this); + } +}; + /* Minimal stream for overwriting and/or appending to an existing byte vector * * The referenced vector will grow as necessary