Merge pull request #10170

ece0342 epee: align container pod as blob serialization (jeffro256)
This commit is contained in:
tobtoht 2025-11-26 19:39:45 +00:00
commit b3614d6b3f
No known key found for this signature in database
GPG Key ID: E45B10DD027D2472

View File

@ -117,11 +117,11 @@ namespace epee
if(!container.size()) return true; if(!container.size()) return true;
std::string mb; std::string mb;
mb.resize(sizeof(typename stl_container::value_type)*container.size()); mb.resize(sizeof(typename stl_container::value_type)*container.size());
typename stl_container::value_type* p_elem = (typename stl_container::value_type*)mb.data(); char *p_elem = mb.data();
BOOST_FOREACH(const typename stl_container::value_type& v, container) BOOST_FOREACH(const typename stl_container::value_type& v, container)
{ {
*p_elem = v; memcpy(p_elem, std::addressof(v), sizeof(typename stl_container::value_type));
p_elem++; p_elem += sizeof(typename stl_container::value_type);
} }
return stg.set_value(pname, std::move(mb), hparent_section); return stg.set_value(pname, std::move(mb), hparent_section);
} }
@ -135,14 +135,19 @@ namespace epee
if(res) if(res)
{ {
size_t loaded_size = buff.size(); size_t loaded_size = buff.size();
typename stl_container::value_type* pelem = (typename stl_container::value_type*)buff.data(); char *pelem = buff.data();
CHECK_AND_ASSERT_MES(!(loaded_size%sizeof(typename stl_container::value_type)), CHECK_AND_ASSERT_MES(!(loaded_size%sizeof(typename stl_container::value_type)),
false, false,
"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()); "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());
size_t count = (loaded_size/sizeof(typename stl_container::value_type)); size_t count = (loaded_size/sizeof(typename stl_container::value_type));
hint_resize(container, count); hint_resize(container, count);
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
container.insert(container.end(), *(pelem++)); {
typename stl_container::value_type v;
memcpy(std::addressof(v), pelem, sizeof(v));
container.insert(container.end(), v);
pelem += sizeof(v);
}
} }
return res; return res;
} }