mirror of
				https://git.wownero.com/wownero/wownero.git
				synced 2024-08-15 01:03:23 +00:00 
			
		
		
		
	serialization: fix infinite loops and clean up dispatching
Resolves #8687
This commit is contained in:
		
							parent
							
								
									8eab181fe1
								
							
						
					
					
						commit
						33e3f72d24
					
				
					 9 changed files with 88 additions and 153 deletions
				
			
		| 
						 | 
				
			
			@ -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());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue