Get rid of nType and nVersion

Remove the nType and nVersion as parameters to all serialization methods
and functions. There is only one place where it's read and has an impact
(in CAddress), and even there it does not impact any of the recursively
invoked serializers.

Instead, the few places that need nType or nVersion are changed to read
it directly from the stream object, through GetType() and GetVersion()
methods which are added to all stream classes.
This commit is contained in:
Pieter Wuille
2016-10-28 16:29:17 -07:00
parent 657e05ab2e
commit 528472111b
36 changed files with 304 additions and 280 deletions

View File

@@ -37,7 +37,7 @@ public:
OverrideStream<Stream>& operator<<(const T& obj)
{
// Serialize to this stream
::Serialize(*this->stream, obj, nType, nVersion);
::Serialize(*this, obj);
return (*this);
}
@@ -45,9 +45,22 @@ public:
OverrideStream<Stream>& operator>>(T& obj)
{
// Unserialize from this stream
::Unserialize(*this->stream, obj, nType, nVersion);
::Unserialize(*this, obj);
return (*this);
}
void write(const char* pch, size_t nSize)
{
stream->write(pch, nSize);
}
void read(char* pch, size_t nSize)
{
stream->read(pch, nSize);
}
int GetVersion() const { return nVersion; }
int GetType() const { return nType; }
};
template<typename S>
@@ -118,7 +131,7 @@ public:
CDataStream(int nTypeIn, int nVersionIn, Args&&... args)
{
Init(nTypeIn, nVersionIn);
::SerializeMany(*this, nType, nVersion, std::forward<Args>(args)...);
::SerializeMany(*this, std::forward<Args>(args)...);
}
void Init(int nTypeIn, int nVersionIn)
@@ -301,7 +314,7 @@ public:
}
template<typename Stream>
void Serialize(Stream& s, int nType, int nVersion) const
void Serialize(Stream& s) const
{
// Special case: stream << stream concatenates like stream += stream
if (!vch.empty())
@@ -312,7 +325,7 @@ public:
CDataStream& operator<<(const T& obj)
{
// Serialize to this stream
::Serialize(*this, obj, nType, nVersion);
::Serialize(*this, obj);
return (*this);
}
@@ -320,7 +333,7 @@ public:
CDataStream& operator>>(T& obj)
{
// Unserialize from this stream
::Unserialize(*this, obj, nType, nVersion);
::Unserialize(*this, obj);
return (*this);
}
@@ -456,7 +469,7 @@ public:
// Serialize to this stream
if (!file)
throw std::ios_base::failure("CAutoFile::operator<<: file handle is NULL");
::Serialize(*this, obj, nType, nVersion);
::Serialize(*this, obj);
return (*this);
}
@@ -466,7 +479,7 @@ public:
// Unserialize from this stream
if (!file)
throw std::ios_base::failure("CAutoFile::operator>>: file handle is NULL");
::Unserialize(*this, obj, nType, nVersion);
::Unserialize(*this, obj);
return (*this);
}
};
@@ -525,6 +538,9 @@ public:
fclose();
}
int GetVersion() const { return nVersion; }
int GetType() const { return nType; }
void fclose()
{
if (src) {
@@ -603,7 +619,7 @@ public:
template<typename T>
CBufferedFile& operator>>(T& obj) {
// Unserialize from this stream
::Unserialize(*this, obj, nType, nVersion);
::Unserialize(*this, obj);
return (*this);
}