From faa5425629d35708326b255570c51139aef0c8c4 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Fri, 10 Jun 2022 10:39:44 +0200 Subject: Add HashWriter without ser-type and ser-version The moved parts can be reviewed with "--color-moved=dimmed-zebra". --- src/hash.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/hash.h') 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 src) { ctx.Write(UCharCast(src.data()), src.size()); @@ -144,6 +136,26 @@ public: return ReadLE64(result.begin()); } + template + 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 CHashWriter& operator<<(const T& obj) { // Serialize to this stream -- cgit v1.2.3