This reply, explains what are SERIALIZE_METHODS and DESERIALIZE_METHODS macros within the Bitcoin Core. They stop duplicate code for implementing the serialization and deserialization logic. However I’ve seen some courses within the Bitcoin Core which do the serialization in a different way. Here is an instance:
/**
* A UTXO entry.
*
* Serialized format:
* - VARINT((coinbase ? 1 : 0) | (top << 1))
* - the non-spent CTxOut (through TxOutCompression)
*/
class Coin
{
...
template<typename Stream>
void Serialize(Stream &s) const {
assert(!IsSpent());
uint32_t code = nHeight * uint32_t{2} + fCoinBase;
::Serialize(s, VARINT(code));
::Serialize(s, Utilizing<TxOutCompression>(out));
}
template<typename Stream>
void Unserialize(Stream &s) {
uint32_t code = 0;
::Unserialize(s, VARINT(code));
nHeight = code >> 1;
fCoinBase = code & 1;
::Unserialize(s, Utilizing<TxOutCompression>(out));
}
So, what is the distinction between these two method of implementing serializing and deserializing strategies?
