diff options
author | MacroFake <falke.marco@gmail.com> | 2022-06-10 10:39:44 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-20 15:34:34 +0200 |
commit | faa5425629d35708326b255570c51139aef0c8c4 (patch) | |
tree | 76adc342ce01c0c462ba08a0de14fbe2dd9aa1df /src/hash.h | |
parent | 1eedde157f2e475243ad1e0527309d85f423d6bb (diff) |
Add HashWriter without ser-type and ser-version
The moved parts can be reviewed with "--color-moved=dimmed-zebra".
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/hash.h b/src/hash.h index 0ccef2105f..0f0c5d4b2c 100644 --- a/src/hash.h +++ b/src/hash.h @@ -96,20 +96,12 @@ inline uint160 Hash160(const T1& in1) } /** A writer stream (for serialization) that computes a 256-bit hash. */ -class CHashWriter +class HashWriter { private: CSHA256 ctx; - const int nType; - const int nVersion; public: - - CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {} - - int GetType() const { return nType; } - int GetVersion() const { return nVersion; } - void write(Span<const std::byte> src) { ctx.Write(UCharCast(src.data()), src.size()); @@ -144,6 +136,26 @@ public: return ReadLE64(result.begin()); } + template <typename T> + HashWriter& operator<<(const T& obj) + { + ::Serialize(*this, obj); + return *this; + } +}; + +class CHashWriter : public HashWriter +{ +private: + const int nType; + const int nVersion; + +public: + CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {} + + int GetType() const { return nType; } + int GetVersion() const { return nVersion; } + template<typename T> CHashWriter& operator<<(const T& obj) { // Serialize to this stream |