Skip to content

Commit 5246a86

Browse files
committed
partial bitcoin#8149: import OverrideStream from "BIP144: Serialization, hashes, relay (sender side)"
1 parent 9310dac commit 5246a86

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/streams.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ class VectorReader
168168
}
169169
}
170170
};
171+
template<typename Stream>
172+
class OverrideStream
173+
{
174+
Stream* stream;
175+
public:
176+
const int nType;
177+
const int nVersion;
178+
179+
OverrideStream(Stream* stream_, int nType_, int nVersion_) : stream(stream_), nType(nType_), nVersion(nVersion_) {}
180+
181+
template<typename T>
182+
OverrideStream<Stream>& operator<<(const T& obj)
183+
{
184+
// Serialize to this stream
185+
::Serialize(*this->stream, obj);
186+
return (*this);
187+
}
188+
189+
template<typename T>
190+
OverrideStream<Stream>& operator>>(T& obj)
191+
{
192+
// Unserialize from this stream
193+
::Unserialize(*this->stream, obj);
194+
return (*this);
195+
}
196+
};
197+
198+
template<typename S>
199+
OverrideStream<S> WithOrVersion(S* s, int nVersionFlag)
200+
{
201+
return OverrideStream<S>(s, s->GetType(), s->GetVersion() | nVersionFlag);
202+
}
203+
171204

172205
/** Double ended buffer combining vector and stream-like interfaces.
173206
*

0 commit comments

Comments
 (0)