mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-18 16:42:54 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user