Skip to content

Commit

Permalink
partial merge bitcoin#8149: import OverrideStream from "BIP144: Seria…
Browse files Browse the repository at this point in the history
…lization, hashes, relay (sender side)"
  • Loading branch information
kwvg authored and UdjinM6 committed May 27, 2021
1 parent 9310dac commit 05e5ee1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/streams.h
Expand Up @@ -22,6 +22,33 @@
#include <utility>
#include <vector>

template<typename Stream>
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<typename T>
OverrideStream<Stream>& operator<<(const T& obj)
{
// Serialize to this stream
::Serialize(*this->stream, obj);
return (*this);
}

template<typename T>
OverrideStream<Stream>& 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
Expand Down

0 comments on commit 05e5ee1

Please sign in to comment.