partial merge #8149: import OverrideStream from "BIP144: Serialization, hashes, relay (sender side)"

This commit is contained in:
Kittywhiskers Van Gogh 2021-05-26 15:04:39 +03:00 committed by UdjinM6
parent 9310daca98
commit 05e5ee1be6
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9

View File

@ -22,6 +22,33 @@
#include <utility> #include <utility>
#include <vector> #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 /* Minimal stream for overwriting and/or appending to an existing byte vector
* *
* The referenced vector will grow as necessary * The referenced vector will grow as necessary