diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-09-01 21:00:32 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-09-01 21:23:01 +0200 |
commit | 2e731f24b5a5c894e013a6d752f1cd409303e916 (patch) | |
tree | 94ba6f1e3ab9ecb5ac1696b48b1aabc859aa8365 /src/core.h | |
parent | f6a81050372810d8eebc15523bde28e91d045314 (diff) | |
parent | 31e9a8384a77947f6777d035992f4734618ed206 (diff) |
Merge pull request #4737
31e9a83 Use CSizeComputer to avoid counting sizes in SerializationOp (Pieter Wuille)
84881f8 rework overhauled serialization methods to non-static (Kamil Domanski)
5d96b4a remove fields of ser_streamplaceholder (Kamil Domanski)
3d796f8 overhaul serialization code (Kamil Domanski)
Diffstat (limited to 'src/core.h')
-rw-r--r-- | src/core.h | 87 |
1 files changed, 62 insertions, 25 deletions
diff --git a/src/core.h b/src/core.h index a3ec2346e2..34c00c4142 100644 --- a/src/core.h +++ b/src/core.h @@ -30,7 +30,14 @@ public: COutPoint() { SetNull(); } COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; } - IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); ) + + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(FLATDATA(*this)); + } + void SetNull() { hash = 0; n = (uint32_t) -1; } bool IsNull() const { return (hash == 0 && n == (uint32_t) -1); } @@ -84,12 +91,14 @@ public: explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max()); CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max()); - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(prevout); READWRITE(scriptSig); READWRITE(nSequence); - ) + } bool IsFinal() const { @@ -136,7 +145,12 @@ public: friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; } std::string ToString() const; - IMPLEMENT_SERIALIZE( READWRITE(nSatoshisPerK); ) + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(nSatoshisPerK); + } }; @@ -156,11 +170,13 @@ public: CTxOut(int64_t nValueIn, CScript scriptPubKeyIn); - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(nValue); READWRITE(scriptPubKey); - ) + } void SetNull() { @@ -237,7 +253,12 @@ public: CTransaction& operator=(const CTransaction& tx); - IMPLEMENT_SERIALIZE( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + bool fRead = ser_action.ForRead(); + READWRITE(*const_cast<int32_t*>(&this->nVersion)); nVersion = this->nVersion; READWRITE(*const_cast<std::vector<CTxIn>*>(&vin)); @@ -245,7 +266,7 @@ public: READWRITE(*const_cast<uint32_t*>(&nLockTime)); if (fRead) UpdateHash(); - ) + } bool IsNull() const { return vin.empty() && vout.empty(); @@ -292,13 +313,16 @@ struct CMutableTransaction CMutableTransaction(); CMutableTransaction(const CTransaction& tx); - IMPLEMENT_SERIALIZE( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(this->nVersion); nVersion = this->nVersion; READWRITE(vin); READWRITE(vout); READWRITE(nLockTime); - ) + } /** Compute the hash of this CMutableTransaction. This is computed on the * fly, as opposed to GetHash() in CTransaction, which uses a cached result. @@ -318,7 +342,11 @@ public: CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { } - IMPLEMENT_SERIALIZE(({ + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + bool fRead = ser_action.ForRead(); if (!fRead) { uint64_t nVal = CompressAmount(txout.nValue); READWRITE(VARINT(nVal)); @@ -329,7 +357,7 @@ public: } CScriptCompressor cscript(REF(txout.scriptPubKey)); READWRITE(cscript); - });) + } }; /** Undo information for a CTxIn @@ -382,9 +410,12 @@ public: // undo information for all txins std::vector<CTxInUndo> vprevout; - IMPLEMENT_SERIALIZE( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(vprevout); - ) + } }; @@ -412,8 +443,10 @@ public: SetNull(); } - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(this->nVersion); nVersion = this->nVersion; READWRITE(hashPrevBlock); @@ -421,7 +454,7 @@ public: READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); - ) + } void SetNull() { @@ -467,11 +500,13 @@ public: *((CBlockHeader*)this) = header; } - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(*(CBlockHeader*)this); READWRITE(vtx); - ) + } void SetNull() { @@ -515,12 +550,14 @@ struct CBlockLocator vHave = vHaveIn; } - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { if (!(nType & SER_GETHASH)) READWRITE(nVersion); READWRITE(vHave); - ) + } void SetNull() { |