33 #include <boost/mpl/vector.hpp> 34 #include <boost/mpl/contains_fwd.hpp> 36 #undef MONERO_DEFAULT_LOG_CATEGORY 37 #define MONERO_DEFAULT_LOG_CATEGORY "serialization" 43 template<
class C>
void hint_resize(C &container,
size_t size) {}
44 template<
class C>
void hint_resize(std::vector<C> &container,
size_t size) { container.reserve(size); }
50 template<
class t_type,
class t_storage>
54 return stg.set_value(pname,
std::move(blob), hparent_section);
57 template<
class t_type,
class t_storage>
61 if(!stg.get_value(pname, blob, hparent_section))
63 CHECK_AND_ASSERT_MES(blob.size() ==
sizeof(
d),
false,
"unserialize_t_val_as_blob: size of " <<
typeid(t_type).name() <<
" = " <<
sizeof(t_type) <<
", but stored blod size = " << blob.size() <<
", value name = " << pname);
64 d = *(
const t_type*)blob.data();
68 template<
class serializible_type,
class t_storage>
71 typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section,
true);
72 CHECK_AND_ASSERT_MES(hchild_section,
false,
"serialize_t_obj: failed to open/create section " << pname);
73 return obj.store(stg, hchild_section);
76 template<
class serializible_type,
class t_storage>
79 typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section,
false);
80 if(!hchild_section)
return false;
81 return obj._load(stg, hchild_section);
84 template<
class stl_container,
class t_storage>
87 using value_type =
typename stl_container::value_type;
89 if(!container.size())
return true;
90 typename stl_container::const_iterator it = container.begin();
91 typename t_storage::harray hval_array = stg.insert_first_value(pname, value_type(*it), hparent_section);
92 CHECK_AND_ASSERT_MES(hval_array,
false,
"failed to insert first value to storage");
94 for(;it!= container.end();it++)
95 stg.insert_next_value(hval_array, value_type(*it));
100 template<
class stl_container,
class t_storage>
104 typename stl_container::value_type exchange_val;
105 typename t_storage::harray hval_array = stg.get_first_value(pname, exchange_val, hparent_section);
106 if(!hval_array)
return false;
107 container.insert(container.end(),
std::move(exchange_val));
108 while(stg.get_next_value(hval_array, exchange_val))
109 container.insert(container.end(),
std::move(exchange_val));
112 template<
class stl_container,
class t_storage>
115 if(!container.size())
return true;
117 mb.resize(
sizeof(
typename stl_container::value_type)*container.size());
118 typename stl_container::value_type* p_elem = (
typename stl_container::value_type*)mb.data();
119 BOOST_FOREACH(
const typename stl_container::value_type& v, container)
124 return stg.set_value(pname,
std::move(mb), hparent_section);
127 template<
class stl_container,
class t_storage>
132 bool res = stg.get_value(pname, buff, hparent_section);
135 size_t loaded_size = buff.size();
136 typename stl_container::value_type* pelem = (
typename stl_container::value_type*)buff.data();
137 CHECK_AND_ASSERT_MES(!(loaded_size%
sizeof(
typename stl_container::value_type)),
139 "size in blob " << loaded_size <<
" not have not zero modulo for sizeof(value_type) = " <<
sizeof(
typename stl_container::value_type) <<
", type " <<
typeid(
typename stl_container::value_type).
name());
140 size_t count = (loaded_size/
sizeof(
typename stl_container::value_type));
141 hint_resize(container,
count);
143 container.insert(container.end(), *(pelem++));
148 template<
class stl_container,
class t_storage>
152 if(!container.size())
return true;
153 typename stl_container::const_iterator it = container.begin();
155 typename t_storage::harray hsec_array = stg.insert_first_section(pname, hchild_section, hparent_section);
156 CHECK_AND_ASSERT_MES(hsec_array && hchild_section,
false,
"failed to insert first section with section name " << pname);
157 res = it->store(stg, hchild_section);
159 for(;it!= container.end();it++)
161 stg.insert_next_section(hsec_array, hchild_section);
162 res |= it->store(stg, hchild_section);
167 template<
class stl_container,
class t_storage>
172 typename stl_container::value_type val =
typename stl_container::value_type();
174 typename t_storage::harray hsec_array = stg.get_first_section(pname, hchild_section, hparent_section);
175 if(!hsec_array || !hchild_section)
return false;
176 res = val._load(stg, hchild_section);
177 container.insert(container.end(), val);
178 while(stg.get_next_section(hsec_array, hchild_section))
180 typename stl_container::value_type val_l =
typename stl_container::value_type();
181 res |= val_l._load(stg, hchild_section);
182 container.insert(container.end(),
std::move(val_l));
193 template<
class t_type,
class t_storage>
196 return stg.set_value(pname, t_type(
d), hparent_section);
199 template<
class t_type,
class t_storage>
202 return stg.get_value(pname,
d, hparent_section);
205 template<
class t_type,
class t_storage>
211 template<
class t_type,
class t_storage>
217 template<
class t_type,
class t_storage>
223 template<
class t_type,
class t_storage>
229 template<
class t_type,
class t_storage>
235 template<
class t_type,
class t_storage>
241 template<
class t_type,
class t_storage>
247 template<
class t_type,
class t_storage>
257 template<
class t_type,
class t_storage>
263 template<
class t_type,
class t_storage>
270 template<
class t_type,
class t_storage>
276 template<
class t_type,
class t_storage>
282 template<
class t_type,
class t_storage>
288 template<
class t_type,
class t_storage>
294 template<
class t_type,
class t_storage>
300 template<
class t_type,
class t_storage>
306 template<
class t_type,
class t_storage>
312 template<
class t_type,
class t_storage>
318 template<
class t_storage>
319 struct base_serializable_types:
public boost::mpl::vector<uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, typename t_storage::meta_entry>
::type 326 template<
class t_type,
class t_storage>
332 template<
class t_type,
class t_storage>
338 template<
class t_type,
class t_storage>
349 template<
class t_type,
class t_storage>
354 template<
class t_type,
class t_storage>
360 template<
class t_type,
class t_storage>
367 template<
class t_type,
class t_storage>
373 template<
class t_type,
class t_storage>
379 template<
class t_type,
class t_storage>
385 template<
class t_type,
class t_storage>
391 template<
class t_type,
class t_storage>
397 template<
class t_type,
class t_storage>
403 template<
class t_type,
class t_storage>
409 template<
class t_type,
class t_storage>
415 template<
class t_type,
class t_storage>
421 template<
class t_type,
class t_storage>
const char * res
Definition: hmac_keccak.cpp:42
Definition: binary_utils.h:36
Definition: keyvalue_serialization_overloads.h:188
static bool kv_unserialize(std::list< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:301
static bool kv_serialize(const std::list< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:230
array_entry * harray
Definition: portable_storage_base.h:175
bool kv_serialize(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:368
int * count
Definition: gmock_stress_test.cc:176
int i
Definition: pymoduletest.py:23
static bool kv_serialize(const std::deque< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:283
::std::string string
Definition: gtest-port.h:1097
static bool serialize(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:327
int type
Definition: superscalar.cpp:50
Definition: keyvalue_serialization_overloads.h:319
static bool serialize_t_val_as_blob(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:51
static bool kv_unserialize(std::list< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:236
bool kv_unserialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:374
Definition: keyvalue_serialization_overloads.h:322
static bool serialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:350
section * hsection
Definition: portable_storage_base.h:174
static bool kv_unserialize(std::deque< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:289
static bool kv_unserialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:264
static bool kv_unserialize(std::deque< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:224
static bool unserialize_t_val_as_blob(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:58
static bool unserialize_t_obj(serializible_type &obj, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:77
static bool kv_serialize(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:258
static bool unserialize_stl_container_pod_val_as_blob(stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:128
static bool kv_serialize(const std::list< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:295
static bool kv_unserialize(std::set< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:313
static bool unserialize_stl_container_t_val(stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:101
static bool serialize_stl_container_pod_val_as_blob(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:333
#define false
Definition: stdbool.h:37
static bool serialize_stl_container_pod_val_as_blob(const stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:113
static bool serialize_stl_container_pod_val_as_blob(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:355
static bool unserialize_stl_container_t_obj(stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:168
TODO: (mj-xmr) This will be reduced in an another PR.
Definition: byte_slice.h:39
static bool kv_serialize(const std::set< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:307
const T & move(const T &t)
Definition: gtest-port.h:1317
static bool kv_unserialize(std::set< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:248
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static bool kv_unserialize(std::vector< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:277
static bool serialize_stl_container_t_obj(const stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:149
static bool kv_serialize(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:194
d
Definition: pymoduletest.py:79
static bool serialize_t_obj(const serializible_type &obj, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:69
static bool kv_serialize(const std::deque< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:218
static bool serialize_t_val_as_blob(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:339
const char * name
Definition: options.c:30
static bool kv_unserialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:200
static bool kv_serialize(const std::set< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:242
static bool serialize_stl_container_t_val(const stl_container &container, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:85
#define true
Definition: stdbool.h:36
static bool serialize_t_val_as_blob(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:361
static bool kv_serialize(const std::vector< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:271
static bool kv_serialize(const std::vector< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:206
static bool kv_unserialize(std::vector< t_type > &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:212