35 #include <boost/mpl/vector.hpp> 36 #include <boost/mpl/contains_fwd.hpp> 38 #undef MONERO_DEFAULT_LOG_CATEGORY 39 #define MONERO_DEFAULT_LOG_CATEGORY "serialization" 45 template<
class C>
void hint_resize(C &container,
size_t size) {}
46 template<
class C>
void hint_resize(std::vector<C> &container,
size_t size) { container.reserve(size); }
52 template<
class t_type,
class t_storage>
56 return stg.set_value(pname,
std::move(blob), hparent_section);
59 template<
class t_type,
class t_storage>
63 if(!stg.get_value(pname, blob, hparent_section))
65 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);
66 d = *(
const t_type*)blob.data();
70 template<
class serializible_type,
class t_storage>
73 typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section,
true);
74 CHECK_AND_ASSERT_MES(hchild_section,
false,
"serialize_t_obj: failed to open/create section " << pname);
75 return obj.store(stg, hchild_section);
78 template<
class serializible_type,
class t_storage>
81 typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section,
false);
82 if(!hchild_section)
return false;
83 return obj._load(stg, hchild_section);
86 template<
class stl_container,
class t_storage>
89 using value_type =
typename stl_container::value_type;
91 if(!container.size())
return true;
92 typename stl_container::const_iterator it = container.begin();
93 typename t_storage::harray hval_array = stg.insert_first_value(pname, value_type(*it), hparent_section);
94 CHECK_AND_ASSERT_MES(hval_array,
false,
"failed to insert first value to storage");
96 for(;it!= container.end();it++)
97 stg.insert_next_value(hval_array, value_type(*it));
102 template<
class stl_container,
class t_storage>
106 typename stl_container::value_type exchange_val;
107 typename t_storage::harray hval_array = stg.get_first_value(pname, exchange_val, hparent_section);
108 if(!hval_array)
return false;
109 container.insert(container.end(),
std::move(exchange_val));
110 while(stg.get_next_value(hval_array, exchange_val))
111 container.insert(container.end(),
std::move(exchange_val));
114 template<
class stl_container,
class t_storage>
117 if(!container.size())
return true;
119 mb.resize(
sizeof(
typename stl_container::value_type)*container.size());
120 typename stl_container::value_type* p_elem = (
typename stl_container::value_type*)mb.data();
121 BOOST_FOREACH(
const typename stl_container::value_type& v, container)
126 return stg.set_value(pname,
std::move(mb), hparent_section);
129 template<
class stl_container,
class t_storage>
134 bool res = stg.get_value(pname, buff, hparent_section);
137 size_t loaded_size = buff.size();
138 typename stl_container::value_type* pelem = (
typename stl_container::value_type*)buff.data();
139 CHECK_AND_ASSERT_MES(!(loaded_size%
sizeof(
typename stl_container::value_type)),
141 "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());
142 size_t count = (loaded_size/
sizeof(
typename stl_container::value_type));
143 hint_resize(container,
count);
145 container.insert(container.end(), *(pelem++));
150 template<
class stl_container,
class t_storage>
154 if(!container.size())
return true;
155 typename stl_container::const_iterator it = container.begin();
157 typename t_storage::harray hsec_array = stg.insert_first_section(pname, hchild_section, hparent_section);
158 CHECK_AND_ASSERT_MES(hsec_array && hchild_section,
false,
"failed to insert first section with section name " << pname);
159 res = it->store(stg, hchild_section);
161 for(;it!= container.end();it++)
163 stg.insert_next_section(hsec_array, hchild_section);
164 res |= it->store(stg, hchild_section);
169 template<
class stl_container,
class t_storage>
174 typename stl_container::value_type val =
typename stl_container::value_type();
176 typename t_storage::harray hsec_array = stg.get_first_section(pname, hchild_section, hparent_section);
177 if(!hsec_array || !hchild_section)
return false;
178 res = val._load(stg, hchild_section);
179 container.insert(container.end(), val);
180 while(stg.get_next_section(hsec_array, hchild_section))
182 typename stl_container::value_type val_l =
typename stl_container::value_type();
183 res |= val_l._load(stg, hchild_section);
184 container.insert(container.end(),
std::move(val_l));
195 template<
class t_type,
class t_storage>
198 return stg.set_value(pname, t_type(
d), hparent_section);
201 template<
class t_type,
class t_storage>
204 return stg.get_value(pname,
d, hparent_section);
207 template<
class t_type,
class t_storage>
213 template<
class t_type,
class t_storage>
219 template<
class t_type,
class t_storage>
225 template<
class t_type,
class t_storage>
231 template<
class t_type,
class t_storage>
237 template<
class t_type,
class t_storage>
243 template<
class t_type,
class t_storage>
249 template<
class t_type,
class t_storage>
259 template<
class t_type,
class t_storage>
265 template<
class t_type,
class t_storage>
272 template<
class t_type,
class t_storage>
278 template<
class t_type,
class t_storage>
284 template<
class t_type,
class t_storage>
290 template<
class t_type,
class t_storage>
296 template<
class t_type,
class t_storage>
302 template<
class t_type,
class t_storage>
308 template<
class t_type,
class t_storage>
314 template<
class t_type,
class t_storage>
320 template<
class t_storage>
321 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 328 template<
class t_type,
class t_storage>
334 template<
class t_type,
class t_storage>
340 template<
class t_type,
class t_storage>
351 template<
class t_type,
class t_storage>
356 template<
class t_type,
class t_storage>
362 template<
class t_type,
class t_storage>
369 template<
class t_type,
class t_storage>
375 template<
class t_type,
class t_storage>
381 template<
class t_type,
class t_storage>
387 template<
class t_type,
class t_storage>
393 template<
class t_type,
class t_storage>
399 template<
class t_type,
class t_storage>
405 template<
class t_type,
class t_storage>
411 template<
class t_type,
class t_storage>
417 template<
class t_type,
class t_storage>
423 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:190
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:303
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:232
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:370
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:285
::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:329
int type
Definition: superscalar.cpp:50
Definition: keyvalue_serialization_overloads.h:321
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:53
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:238
bool kv_unserialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:376
Definition: keyvalue_serialization_overloads.h:324
static bool serialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:352
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:291
static bool kv_unserialize(t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:266
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:226
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:60
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:79
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:260
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:130
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:297
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:315
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:103
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:335
#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:115
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:357
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:170
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:309
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:250
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:279
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:151
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:196
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:71
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:220
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:341
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:202
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:244
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:87
#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:363
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:273
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:208
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:214