diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-07-10 20:16:58 +0200 |
---|---|---|
committer | Pieter Wuille <sipa@ulyssis.org> | 2014-07-16 21:14:26 +0200 |
commit | b069750d3f27c96a83700a08a2bb819902268857 (patch) | |
tree | d427feef71fdc1b5a6b336eadaaab940e81f9400 /src/serialize.h | |
parent | 87e40799fdebb9f4c3c9d8cc7d071408a4ea768e (diff) |
Break up CAddrMan's IMPLEMENT_SERIALIZE
Diffstat (limited to 'src/serialize.h')
-rw-r--r-- | src/serialize.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/serialize.h b/src/serialize.h index 5ac85554c6..f876efd9b5 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -830,6 +830,35 @@ struct ser_streamplaceholder typedef std::vector<char, zero_after_free_allocator<char> > CSerializeData; +class CSizeComputer +{ +protected: + size_t nSize; + +public: + int nType; + int nVersion; + + CSizeComputer(int nTypeIn, int nVersionIn) : nSize(0), nType(nTypeIn), nVersion(nVersionIn) {} + + CSizeComputer& write(const char *psz, int nSize) + { + this->nSize += nSize; + return *this; + } + + template<typename T> + CSizeComputer& operator<<(const T& obj) + { + ::Serialize(*this, obj, nType, nVersion); + return (*this); + } + + size_t size() const { + return nSize; + } +}; + /** Double ended buffer combining vector and stream-like interfaces. * * >> and << read and write unformatted data using the above serialization templates. |