Add HashWriter without ser-type and ser-version

The moved parts can be reviewed with "--color-moved=dimmed-zebra".
This commit is contained in:
MacroFake 2022-06-10 10:39:44 +02:00
parent 1eedde157f
commit faa5425629
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548
1 changed files with 21 additions and 9 deletions

View File

@ -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