Skip to content

Commit 961c4a0

Browse files
committed
Merge pull request bitcoin#4808
3f6540a Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS (Pieter Wuille) 47eb765 Serializer simplifications after IMPLEMENT_SERIALIZE overhaul (Pieter Wuille)
2 parents 52c1deb + 3f6540a commit 961c4a0

File tree

13 files changed

+84
-107
lines changed

13 files changed

+84
-107
lines changed

src/addrman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CAddrInfo : public CAddress
4646

4747
public:
4848

49-
IMPLEMENT_SERIALIZE;
49+
ADD_SERIALIZE_METHODS;
5050

5151
template <typename Stream, typename Operation>
5252
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -268,7 +268,7 @@ class CAddrMan
268268
// This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
269269
// changes to the ADDRMAN_ parameters without breaking the on-disk structure.
270270
//
271-
// We don't use IMPLEMENT_SERIALIZE since the serialization and deserialization code has
271+
// We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has
272272
// very little in common.
273273
template<typename Stream>
274274
void Serialize(Stream &s, int nType, int nVersionDummy) const

src/alert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CUnsignedAlert
4646
std::string strStatusBar;
4747
std::string strReserved;
4848

49-
IMPLEMENT_SERIALIZE;
49+
ADD_SERIALIZE_METHODS;
5050

5151
template <typename Stream, typename Operation>
5252
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -84,7 +84,7 @@ class CAlert : public CUnsignedAlert
8484
SetNull();
8585
}
8686

87-
IMPLEMENT_SERIALIZE;
87+
ADD_SERIALIZE_METHODS;
8888

8989
template <typename Stream, typename Operation>
9090
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/bloom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CBloomFilter
6262
CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn);
6363
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}
6464

65-
IMPLEMENT_SERIALIZE;
65+
ADD_SERIALIZE_METHODS;
6666

6767
template <typename Stream, typename Operation>
6868
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/core.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class COutPoint
3131
COutPoint() { SetNull(); }
3232
COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
3333

34-
IMPLEMENT_SERIALIZE;
34+
ADD_SERIALIZE_METHODS;
3535

3636
template <typename Stream, typename Operation>
3737
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -91,7 +91,7 @@ class CTxIn
9191
explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max());
9292
CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());
9393

94-
IMPLEMENT_SERIALIZE;
94+
ADD_SERIALIZE_METHODS;
9595

9696
template <typename Stream, typename Operation>
9797
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -145,7 +145,7 @@ class CFeeRate
145145
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
146146
std::string ToString() const;
147147

148-
IMPLEMENT_SERIALIZE;
148+
ADD_SERIALIZE_METHODS;
149149

150150
template <typename Stream, typename Operation>
151151
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -170,7 +170,7 @@ class CTxOut
170170

171171
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
172172

173-
IMPLEMENT_SERIALIZE;
173+
ADD_SERIALIZE_METHODS;
174174

175175
template <typename Stream, typename Operation>
176176
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -253,18 +253,16 @@ class CTransaction
253253

254254
CTransaction& operator=(const CTransaction& tx);
255255

256-
IMPLEMENT_SERIALIZE;
256+
ADD_SERIALIZE_METHODS;
257257

258258
template <typename Stream, typename Operation>
259259
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
260-
bool fRead = ser_action.ForRead();
261-
262260
READWRITE(*const_cast<int32_t*>(&this->nVersion));
263261
nVersion = this->nVersion;
264262
READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
265263
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
266264
READWRITE(*const_cast<uint32_t*>(&nLockTime));
267-
if (fRead)
265+
if (ser_action.ForRead())
268266
UpdateHash();
269267
}
270268

@@ -313,7 +311,7 @@ struct CMutableTransaction
313311
CMutableTransaction();
314312
CMutableTransaction(const CTransaction& tx);
315313

316-
IMPLEMENT_SERIALIZE;
314+
ADD_SERIALIZE_METHODS;
317315

318316
template <typename Stream, typename Operation>
319317
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -342,12 +340,11 @@ class CTxOutCompressor
342340

343341
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
344342

345-
IMPLEMENT_SERIALIZE;
343+
ADD_SERIALIZE_METHODS;
346344

347345
template <typename Stream, typename Operation>
348346
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
349-
bool fRead = ser_action.ForRead();
350-
if (!fRead) {
347+
if (!ser_action.ForRead()) {
351348
uint64_t nVal = CompressAmount(txout.nValue);
352349
READWRITE(VARINT(nVal));
353350
} else {
@@ -410,7 +407,7 @@ class CTxUndo
410407
// undo information for all txins
411408
std::vector<CTxInUndo> vprevout;
412409

413-
IMPLEMENT_SERIALIZE;
410+
ADD_SERIALIZE_METHODS;
414411

415412
template <typename Stream, typename Operation>
416413
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -443,7 +440,7 @@ class CBlockHeader
443440
SetNull();
444441
}
445442

446-
IMPLEMENT_SERIALIZE;
443+
ADD_SERIALIZE_METHODS;
447444

448445
template <typename Stream, typename Operation>
449446
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -500,7 +497,7 @@ class CBlock : public CBlockHeader
500497
*((CBlockHeader*)this) = header;
501498
}
502499

503-
IMPLEMENT_SERIALIZE;
500+
ADD_SERIALIZE_METHODS;
504501

505502
template <typename Stream, typename Operation>
506503
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -550,7 +547,7 @@ struct CBlockLocator
550547
vHave = vHaveIn;
551548
}
552549

553-
IMPLEMENT_SERIALIZE;
550+
ADD_SERIALIZE_METHODS;
554551

555552
template <typename Stream, typename Operation>
556553
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/crypter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class CMasterKey
4343
// such as the various parameters to scrypt
4444
std::vector<unsigned char> vchOtherDerivationParameters;
4545

46-
IMPLEMENT_SERIALIZE;
46+
ADD_SERIALIZE_METHODS;
4747

4848
template <typename Stream, typename Operation>
4949
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/main.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct CDiskBlockPos
197197
int nFile;
198198
unsigned int nPos;
199199

200-
IMPLEMENT_SERIALIZE;
200+
ADD_SERIALIZE_METHODS;
201201

202202
template <typename Stream, typename Operation>
203203
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -230,7 +230,7 @@ struct CDiskTxPos : public CDiskBlockPos
230230
{
231231
unsigned int nTxOffset; // after header
232232

233-
IMPLEMENT_SERIALIZE;
233+
ADD_SERIALIZE_METHODS;
234234

235235
template <typename Stream, typename Operation>
236236
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -313,7 +313,7 @@ class CBlockUndo
313313
public:
314314
std::vector<CTxUndo> vtxundo; // for all but the coinbase
315315

316-
IMPLEMENT_SERIALIZE;
316+
ADD_SERIALIZE_METHODS;
317317

318318
template <typename Stream, typename Operation>
319319
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -420,16 +420,14 @@ class CPartialMerkleTree
420420
public:
421421

422422
// serialization implementation
423-
IMPLEMENT_SERIALIZE;
423+
ADD_SERIALIZE_METHODS;
424424

425425
template <typename Stream, typename Operation>
426426
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
427-
bool fRead = ser_action.ForRead();
428-
429427
READWRITE(nTransactions);
430428
READWRITE(vHash);
431429
std::vector<unsigned char> vBytes;
432-
if (fRead) {
430+
if (ser_action.ForRead()) {
433431
READWRITE(vBytes);
434432
CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this));
435433
us.vBits.resize(vBytes.size() * 8);
@@ -498,7 +496,7 @@ class CBlockFileInfo
498496
uint64_t nTimeFirst; // earliest time of block in file
499497
uint64_t nTimeLast; // latest time of block in file
500498

501-
IMPLEMENT_SERIALIZE;
499+
ADD_SERIALIZE_METHODS;
502500

503501
template <typename Stream, typename Operation>
504502
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -773,7 +771,7 @@ class CDiskBlockIndex : public CBlockIndex
773771
hashPrev = (pprev ? pprev->GetBlockHash() : 0);
774772
}
775773

776-
IMPLEMENT_SERIALIZE;
774+
ADD_SERIALIZE_METHODS;
777775

778776
template <typename Stream, typename Operation>
779777
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -995,7 +993,7 @@ class CMerkleBlock
995993
// thus the filter will likely be modified.
996994
CMerkleBlock(const CBlock& block, CBloomFilter& filter);
997995

998-
IMPLEMENT_SERIALIZE;
996+
ADD_SERIALIZE_METHODS;
999997

1000998
template <typename Stream, typename Operation>
1001999
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/netbase.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class CNetAddr
8888
friend bool operator!=(const CNetAddr& a, const CNetAddr& b);
8989
friend bool operator<(const CNetAddr& a, const CNetAddr& b);
9090

91-
IMPLEMENT_SERIALIZE;
91+
ADD_SERIALIZE_METHODS;
9292

9393
template <typename Stream, typename Operation>
9494
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -150,15 +150,14 @@ class CService : public CNetAddr
150150
CService(const struct in6_addr& ipv6Addr, unsigned short port);
151151
CService(const struct sockaddr_in6& addr);
152152

153-
IMPLEMENT_SERIALIZE;
153+
ADD_SERIALIZE_METHODS;
154154

155155
template <typename Stream, typename Operation>
156156
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
157-
bool fRead = ser_action.ForRead();
158157
READWRITE(FLATDATA(ip));
159158
unsigned short portN = htons(port);
160159
READWRITE(portN);
161-
if (fRead)
160+
if (ser_action.ForRead())
162161
port = ntohs(portN);
163162
}
164163
};

src/protocol.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CMessageHeader
3535
std::string GetCommand() const;
3636
bool IsValid() const;
3737

38-
IMPLEMENT_SERIALIZE;
38+
ADD_SERIALIZE_METHODS;
3939

4040
template <typename Stream, typename Operation>
4141
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@@ -85,20 +85,17 @@ class CAddress : public CService
8585

8686
void Init();
8787

88-
IMPLEMENT_SERIALIZE;
88+
ADD_SERIALIZE_METHODS;
8989

9090
template <typename Stream, typename Operation>
9191
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
92-
bool fRead = ser_action.ForRead();
93-
94-
CAddress* pthis = const_cast<CAddress*>(this);
95-
if (fRead)
96-
pthis->Init();
92+
if (ser_action.ForRead())
93+
Init();
9794
if (nType & SER_DISK)
9895
READWRITE(nVersion);
9996
if ((nType & SER_DISK) ||
10097
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
101-
READWRITE(nTime);
98+
READWRITE(nTime);
10299
READWRITE(nServices);
103100
READWRITE(*(CService*)this);
104101
}
@@ -122,7 +119,7 @@ class CInv
122119
CInv(int typeIn, const uint256& hashIn);
123120
CInv(const std::string& strType, const uint256& hashIn);
124121

125-
IMPLEMENT_SERIALIZE;
122+
ADD_SERIALIZE_METHODS;
126123

127124
template <typename Stream, typename Operation>
128125
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

src/qt/recentrequeststablemodel.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ class RecentRequestEntry
2424
QDateTime date;
2525
SendCoinsRecipient recipient;
2626

27-
IMPLEMENT_SERIALIZE;
27+
ADD_SERIALIZE_METHODS;
2828

2929
template <typename Stream, typename Operation>
3030
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
31-
bool fRead = ser_action.ForRead();
32-
33-
RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(this);
34-
3531
unsigned int nDate = date.toTime_t();
3632

37-
READWRITE(pthis->nVersion);
38-
nVersion = pthis->nVersion;
33+
READWRITE(this->nVersion);
34+
nVersion = this->nVersion;
3935
READWRITE(id);
4036
READWRITE(nDate);
4137
READWRITE(recipient);
4238

43-
if (fRead)
39+
if (ser_action.ForRead())
4440
date = QDateTime::fromTime_t(nDate);
4541
}
4642
};

src/qt/walletmodel.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,35 @@ class SendCoinsRecipient
5959
static const int CURRENT_VERSION = 1;
6060
int nVersion;
6161

62-
IMPLEMENT_SERIALIZE;
62+
ADD_SERIALIZE_METHODS;
6363

6464
template <typename Stream, typename Operation>
6565
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
66-
bool fRead = ser_action.ForRead();
67-
68-
SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(this);
69-
70-
std::string sAddress = pthis->address.toStdString();
71-
std::string sLabel = pthis->label.toStdString();
72-
std::string sMessage = pthis->message.toStdString();
66+
std::string sAddress = address.toStdString();
67+
std::string sLabel = label.toStdString();
68+
std::string sMessage = message.toStdString();
7369
std::string sPaymentRequest;
74-
if (!fRead && pthis->paymentRequest.IsInitialized())
75-
pthis->paymentRequest.SerializeToString(&sPaymentRequest);
76-
std::string sAuthenticatedMerchant = pthis->authenticatedMerchant.toStdString();
70+
if (!ser_action.ForRead() && paymentRequest.IsInitialized())
71+
paymentRequest.SerializeToString(&sPaymentRequest);
72+
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
7773

78-
READWRITE(pthis->nVersion);
79-
nVersion = pthis->nVersion;
74+
READWRITE(this->nVersion);
75+
nVersion = this->nVersion;
8076
READWRITE(sAddress);
8177
READWRITE(sLabel);
8278
READWRITE(amount);
8379
READWRITE(sMessage);
8480
READWRITE(sPaymentRequest);
8581
READWRITE(sAuthenticatedMerchant);
8682

87-
if (fRead)
83+
if (ser_action.ForRead())
8884
{
89-
pthis->address = QString::fromStdString(sAddress);
90-
pthis->label = QString::fromStdString(sLabel);
91-
pthis->message = QString::fromStdString(sMessage);
85+
address = QString::fromStdString(sAddress);
86+
label = QString::fromStdString(sLabel);
87+
message = QString::fromStdString(sMessage);
9288
if (!sPaymentRequest.empty())
93-
pthis->paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size()));
94-
pthis->authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
89+
paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size()));
90+
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
9591
}
9692
}
9793
};

0 commit comments

Comments
 (0)