mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-05 18:23:03 +01:00
BIP144: Serialization, hashes, relay (sender side)
Contains refactorings by Eric Lombrozo. Contains fixup by Nicolas Dorier. Contains cleanup of CInv::GetCommand by Alex Morcos
This commit is contained in:
@@ -22,6 +22,39 @@
|
||||
#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, nType, nVersion);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
OverrideStream<Stream>& operator>>(T& obj)
|
||||
{
|
||||
// Unserialize from this stream
|
||||
::Unserialize(*this->stream, obj, nType, nVersion);
|
||||
return (*this);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S>
|
||||
OverrideStream<S> WithOrVersion(S* s, int nVersionFlag)
|
||||
{
|
||||
return OverrideStream<S>(s, s->GetType(), s->GetVersion() | nVersionFlag);
|
||||
}
|
||||
|
||||
/** Double ended buffer combining vector and stream-like interfaces.
|
||||
*
|
||||
* >> and << read and write unformatted data using the above serialization templates.
|
||||
|
||||
Reference in New Issue
Block a user