It was almost faster to make it an enum than to make sure the value did what I guessed it did...
Serialization cleanup: use enum for nType arg. #5443
pull rustyrussell wants to merge 2 commits into bitcoin:master from rustyrussell:serialize-enum-cleanup changing 29 files +231 −230-
rustyrussell commented at 9:53 AM on December 8, 2014: contributor
-
jonasschnelli commented at 12:19 PM on December 8, 2014: contributor
Seems not to work correctly. Check the travis build output. There are many of errors like...
qt/walletmodel.h:81:9: error: no matching function for call to ‘SerReadWrite(CSizeComputer&, std::string&, int&, int&, CSerActionSerialize&)’ -
7128413120
Use enum for serialization type.
nType gets handed through all these because some things serialize differently on disk, for hashing or for networking. But using an int is just lazy and opens up the possibility of order mixup, since nVersion is also an int. For the overloading hack to default to calling a member function, we can (ab)use the nVersion parameter instead.
-
651c1d2bdf
Make SER_* values a normal enum.
commit e754cf4133c (Split off CBlockHeader from CBlock) removed the application-specific flags from the serial type, but left the comment and the weird spacing in the values. Make SER_* a normal enum, and test for (in)equality as expected. I also changed the weird negative in CAddress serialization from: if ((nType & SER_DISK) || (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH))) To the clearer: if ((nType == SER_DISK) || (nVersion >= CADDR_TIME_VERSION && (nType == SER_NETWORK))) -
in src/pubkey.h:None in dea5f7758c outdated
125 | ::WriteCompactSize(s, len); 126 | s.write((char*)vch, len); 127 | } 128 | template <typename Stream> 129 | - void Unserialize(Stream& s, int nType, int nVersion) 130 | + void Unserialize(Stream& s, enum SerializeType nType, int nVersion)
laanwj commented at 4:13 PM on December 8, 2014:In C++ you can leave out the
enumwhen using the type, so just useSerializeType. Interesting observation though, that we never use this bitfield as bitfield.
rustyrussell commented at 10:48 PM on December 8, 2014:Thanks, will rebase (seems I don't have qt libs installed, so missed some files).
Yes, as per the commit msg, it hasn't been a bitfield since: commit e754cf4133c9c97e320ae5dec394e338524e650b Author: Pieter Wuille pieter.wuille@gmail.com Date: Wed Nov 14 22:18:10 2012 +0100
rustyrussell force-pushed on Dec 8, 2014rustyrussell closed this on Dec 8, 2014MarcoFalke locked this on Sep 8, 2021Contributors
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 09:15 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 09:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me