Split up and sanitize CAccountingEntry serialization
This commit is contained in:
parent
029ecac1bc
commit
42343c748c
1 changed files with 36 additions and 35 deletions
|
@ -602,48 +602,49 @@ public:
|
||||||
nEntryNo = 0;
|
nEntryNo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
template <typename Stream>
|
||||||
|
void Serialize(Stream& s) const {
|
||||||
template <typename Stream, typename Operation>
|
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
||||||
int nVersion = s.GetVersion();
|
int nVersion = s.GetVersion();
|
||||||
if (!(s.GetType() & SER_GETHASH))
|
if (!(s.GetType() & SER_GETHASH)) {
|
||||||
READWRITE(nVersion);
|
s << nVersion;
|
||||||
//! Note: strAccount is serialized as part of the key, not here.
|
|
||||||
READWRITE(nCreditDebit);
|
|
||||||
READWRITE(nTime);
|
|
||||||
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
|
|
||||||
|
|
||||||
if (!ser_action.ForRead())
|
|
||||||
{
|
|
||||||
WriteOrderPos(nOrderPos, mapValue);
|
|
||||||
|
|
||||||
if (!(mapValue.empty() && _ssExtra.empty()))
|
|
||||||
{
|
|
||||||
CDataStream ss(s.GetType(), s.GetVersion());
|
|
||||||
ss.insert(ss.begin(), '\0');
|
|
||||||
ss << mapValue;
|
|
||||||
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
|
|
||||||
strComment.append(ss.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//! Note: strAccount is serialized as part of the key, not here.
|
||||||
|
s << nCreditDebit << nTime << strOtherAccount;
|
||||||
|
|
||||||
READWRITE(LIMITED_STRING(strComment, 65536));
|
mapValue_t mapValueCopy = mapValue;
|
||||||
|
WriteOrderPos(nOrderPos, mapValueCopy);
|
||||||
|
|
||||||
|
std::string strCommentCopy = strComment;
|
||||||
|
if (!mapValueCopy.empty() || !_ssExtra.empty()) {
|
||||||
|
CDataStream ss(s.GetType(), s.GetVersion());
|
||||||
|
ss.insert(ss.begin(), '\0');
|
||||||
|
ss << mapValueCopy;
|
||||||
|
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
|
||||||
|
strCommentCopy.append(ss.str());
|
||||||
|
}
|
||||||
|
s << strCommentCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
void Unserialize(Stream& s) {
|
||||||
|
int nVersion = s.GetVersion();
|
||||||
|
if (!(s.GetType() & SER_GETHASH)) {
|
||||||
|
s >> nVersion;
|
||||||
|
}
|
||||||
|
//! Note: strAccount is serialized as part of the key, not here.
|
||||||
|
s >> nCreditDebit >> nTime >> LIMITED_STRING(strOtherAccount, 65536) >> LIMITED_STRING(strComment, 65536);
|
||||||
|
|
||||||
size_t nSepPos = strComment.find("\0", 0, 1);
|
size_t nSepPos = strComment.find("\0", 0, 1);
|
||||||
if (ser_action.ForRead())
|
mapValue.clear();
|
||||||
{
|
if (std::string::npos != nSepPos) {
|
||||||
mapValue.clear();
|
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
|
||||||
if (std::string::npos != nSepPos)
|
ss >> mapValue;
|
||||||
{
|
_ssExtra = std::vector<char>(ss.begin(), ss.end());
|
||||||
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
|
|
||||||
ss >> mapValue;
|
|
||||||
_ssExtra = std::vector<char>(ss.begin(), ss.end());
|
|
||||||
}
|
|
||||||
ReadOrderPos(nOrderPos, mapValue);
|
|
||||||
}
|
}
|
||||||
if (std::string::npos != nSepPos)
|
ReadOrderPos(nOrderPos, mapValue);
|
||||||
|
if (std::string::npos != nSepPos) {
|
||||||
strComment.erase(nSepPos);
|
strComment.erase(nSepPos);
|
||||||
|
}
|
||||||
|
|
||||||
mapValue.erase("n");
|
mapValue.erase("n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue