mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Add native support for serializing char arrays without FLATDATA
Support is added to serialize arrays of type char or unsigned char directly, without any wrappers. All invocations of the FLATDATA wrappers that are obsoleted by this are removed. This includes a patch by Russell Yanofsky to make char casting type safe. The serialization of CSubNet is changed to serialize a bool directly rather than though FLATDATA. This makes the serialization independent of the size of the bool type (and will use 1 byte everywhere).
This commit is contained in:
@@ -19,11 +19,15 @@ protected:
|
||||
int intval;
|
||||
bool boolval;
|
||||
std::string stringval;
|
||||
const char* charstrval;
|
||||
char charstrval[16];
|
||||
CTransactionRef txval;
|
||||
public:
|
||||
CSerializeMethodsTestSingle() = default;
|
||||
CSerializeMethodsTestSingle(int intvalin, bool boolvalin, std::string stringvalin, const char* charstrvalin, CTransaction txvalin) : intval(intvalin), boolval(boolvalin), stringval(std::move(stringvalin)), charstrval(charstrvalin), txval(MakeTransactionRef(txvalin)){}
|
||||
CSerializeMethodsTestSingle(int intvalin, bool boolvalin, std::string stringvalin, const char* charstrvalin, CTransaction txvalin) : intval(intvalin), boolval(boolvalin), stringval(std::move(stringvalin)), txval(MakeTransactionRef(txvalin))
|
||||
{
|
||||
memcpy(charstrval, charstrvalin, sizeof(charstrval));
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
@@ -31,7 +35,7 @@ public:
|
||||
READWRITE(intval);
|
||||
READWRITE(boolval);
|
||||
READWRITE(stringval);
|
||||
READWRITE(FLATDATA(charstrval));
|
||||
READWRITE(charstrval);
|
||||
READWRITE(txval);
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public:
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(intval, boolval, stringval, FLATDATA(charstrval), txval);
|
||||
READWRITE(intval, boolval, stringval, charstrval, txval);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -344,7 +348,7 @@ BOOST_AUTO_TEST_CASE(class_methods)
|
||||
int intval(100);
|
||||
bool boolval(true);
|
||||
std::string stringval("testing");
|
||||
const char* charstrval("testing charstr");
|
||||
const char charstrval[16] = "testing charstr";
|
||||
CMutableTransaction txval;
|
||||
CSerializeMethodsTestSingle methodtest1(intval, boolval, stringval, charstrval, txval);
|
||||
CSerializeMethodsTestMany methodtest2(intval, boolval, stringval, charstrval, txval);
|
||||
@@ -360,7 +364,7 @@ BOOST_AUTO_TEST_CASE(class_methods)
|
||||
BOOST_CHECK(methodtest2 == methodtest3);
|
||||
BOOST_CHECK(methodtest3 == methodtest4);
|
||||
|
||||
CDataStream ss2(SER_DISK, PROTOCOL_VERSION, intval, boolval, stringval, FLATDATA(charstrval), txval);
|
||||
CDataStream ss2(SER_DISK, PROTOCOL_VERSION, intval, boolval, stringval, charstrval, txval);
|
||||
ss2 >> methodtest3;
|
||||
BOOST_CHECK(methodtest3 == methodtest4);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user