Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization #20

Merged
merged 3 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions include/fc/container/flat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,69 @@ namespace fc {
template<typename Stream, typename T>
inline void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::pack( s, *itr, _max_depth - 1 );
fc::raw::pack( s, *itr, _max_depth );
++itr;
}
}
template<typename Stream, typename T>
inline void unpack( Stream& s, flat_set<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
unsigned_int size; unpack( s, size, _max_depth - 1 );
--_max_depth;
unsigned_int size; unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
for( uint32_t i = 0; i < size.value; ++i )
{
T tmp;
fc::raw::unpack( s, tmp, _max_depth - 1 );
fc::raw::unpack( s, tmp, _max_depth );
value.insert( std::move(tmp) );
}
}
template<typename Stream, typename K, typename... V>
inline void pack( Stream& s, const flat_map<K,V...>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::pack( s, *itr, _max_depth - 1 );
fc::raw::pack( s, *itr, _max_depth );
++itr;
}
}
template<typename Stream, typename K, typename V, typename... A>
inline void unpack( Stream& s, flat_map<K,V,A...>& value, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
unsigned_int size; unpack( s, size, _max_depth - 1 );
--_max_depth;
unsigned_int size; unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
for( uint32_t i = 0; i < size.value; ++i )
{
std::pair<K,V> tmp;
fc::raw::unpack( s, tmp, _max_depth - 1 );
fc::raw::unpack( s, tmp, _max_depth );
value.insert( std::move(tmp) );
}
}

template<typename Stream, typename T, typename A>
void pack( Stream& s, const bip::vector<T,A>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
if( !std::is_fundamental<T>::value ) {
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::pack( s, *itr, _max_depth - 1 );
fc::raw::pack( s, *itr, _max_depth );
++itr;
}
} else {
Expand All @@ -78,12 +83,13 @@ namespace fc {
template<typename Stream, typename T, typename A>
void unpack( Stream& s, bip::vector<T,A>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size;
unpack( s, size, _max_depth - 1 );
unpack( s, size, _max_depth );
value.resize( size );
if( !std::is_fundamental<T>::value ) {
for( auto& item : value )
unpack( s, item, _max_depth - 1 );
unpack( s, item, _max_depth );
} else {
s.read( (char*)value.data(), value.size() );
}
Expand Down
10 changes: 6 additions & 4 deletions include/fc/interprocess/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,24 @@ namespace fc {
template<typename Stream, typename T, typename... A>
inline void pack( Stream& s, const bip::vector<T,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::pack( s, *itr, _max_depth - 1 );
fc::raw::pack( s, *itr, _max_depth );
++itr;
}
}
template<typename Stream, typename T, typename... A>
inline void unpack( Stream& s, bip::vector<T,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size;
unpack( s, size, _max_depth - 1 );
unpack( s, size, _max_depth );
value.clear(); value.resize(size);
for( auto& item : value )
fc::raw::unpack( s, item, _max_depth - 1 );
fc::raw::unpack( s, item, _max_depth );
}
}
}
Loading