mirror of
https://github.com/monero-project/monero.git
synced 2025-12-10 07:22:34 +01:00
Merge pull request #9069
a11e03a serialization: fix infinite loops and clean up dispatching (jeffro256)
This commit is contained in:
@@ -59,9 +59,7 @@ struct Struct
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
struct serializer<Archive, Struct>
|
||||
{
|
||||
static bool serialize(Archive &ar, Struct &s) {
|
||||
static bool do_serialize(Archive &ar, Struct &s) {
|
||||
ar.begin_object();
|
||||
ar.tag("a");
|
||||
ar.serialize_int(s.a);
|
||||
@@ -71,8 +69,7 @@ struct serializer<Archive, Struct>
|
||||
ar.serialize_blob(s.blob, sizeof(s.blob));
|
||||
ar.end_object();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct Struct1
|
||||
{
|
||||
@@ -122,6 +119,23 @@ bool try_parse(const string &blob)
|
||||
return serialization::parse_binary(blob, s1);
|
||||
}
|
||||
|
||||
namespace example_namespace
|
||||
{
|
||||
struct ADLExampleStruct
|
||||
{
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
static bool do_serialize(Archive &ar, ADLExampleStruct &aes)
|
||||
{
|
||||
ar.begin_object();
|
||||
FIELD_N("custom_fieldname", aes.msg);
|
||||
ar.end_object();
|
||||
return ar.good();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Serialization, BinaryArchiveInts) {
|
||||
uint64_t x = 0xff00000000, x1;
|
||||
|
||||
@@ -1178,3 +1192,18 @@ TEST(Serialization, difficulty_type)
|
||||
|
||||
ASSERT_EQ(v_original, v_unserialized);
|
||||
}
|
||||
|
||||
TEST(Serialization, adl_free_function)
|
||||
{
|
||||
std::stringstream ss;
|
||||
json_archive<true> ar(ss);
|
||||
|
||||
const std::string msg = "Howdy, World!";
|
||||
example_namespace::ADLExampleStruct aes{msg};
|
||||
|
||||
ASSERT_TRUE(serialization::serialize(ar, aes));
|
||||
|
||||
// VVVVVVVVVVVVVVVVVVVVVVVVVV weird string serialization artifact
|
||||
const std::string expected = "{\"custom_fieldname\": " + std::to_string(msg.size()) + '"' + epee::string_tools::buff_to_hex_nodelimer(msg) + "\"}";
|
||||
EXPECT_EQ(expected, ss.str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user