partial bitcoin#25331: Add HashWriter without ser-type and ser-version

includes:
- faa5425629d35708326b255570c51139aef0c8c4
This commit is contained in:
Kittywhiskers Van Gogh 2022-06-10 10:39:44 +02:00
parent 96685be685
commit 2d99be0aea
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD

View File

@ -110,20 +110,12 @@ inline uint160 Hash160(const T1& in1)
} }
/** A writer stream (for serialization) that computes a 256-bit hash. */ /** A writer stream (for serialization) that computes a 256-bit hash. */
class CHashWriter class HashWriter
{ {
private: private:
CSHA256 ctx; CSHA256 ctx;
const int nType;
const int nVersion;
public: 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) void write(Span<const std::byte> src)
{ {
ctx.Write(UCharCast(src.data()), src.size()); ctx.Write(UCharCast(src.data()), src.size());
@ -158,6 +150,26 @@ public:
return ReadLE64(result.begin()); 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> template<typename T>
CHashWriter& operator<<(const T& obj) { CHashWriter& operator<<(const T& obj) {
// Serialize to this stream // Serialize to this stream