Add from/to variant for bip::vector<char, A...>
This commit is contained in:
parent
962a816d17
commit
929d42fe02
1 changed files with 24 additions and 1 deletions
|
|
@ -7,9 +7,9 @@
|
||||||
#include <boost/interprocess/containers/map.hpp>
|
#include <boost/interprocess/containers/map.hpp>
|
||||||
#include <boost/interprocess/containers/flat_map.hpp>
|
#include <boost/interprocess/containers/flat_map.hpp>
|
||||||
#include <boost/interprocess/containers/deque.hpp>
|
#include <boost/interprocess/containers/deque.hpp>
|
||||||
|
#include <fc/crypto/hex.hpp>
|
||||||
#include <fc/io/raw_fwd.hpp>
|
#include <fc/io/raw_fwd.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
||||||
namespace bip = boost::interprocess;
|
namespace bip = boost::interprocess;
|
||||||
|
|
@ -72,6 +72,29 @@ namespace fc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename... A>
|
||||||
|
void to_variant( const bip::vector<char, A...>& t, fc::variant& v )
|
||||||
|
{
|
||||||
|
if( t.size() )
|
||||||
|
v = variant(fc::to_hex(t.data(), t.size()));
|
||||||
|
else
|
||||||
|
v = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... A>
|
||||||
|
void from_variant( const fc::variant& v, bip::vector<char, A...>& d )
|
||||||
|
{
|
||||||
|
auto str = v.as_string();
|
||||||
|
d.resize( str.size() / 2 );
|
||||||
|
if( d.size() )
|
||||||
|
{
|
||||||
|
size_t r = fc::from_hex( str, d.data(), d.size() );
|
||||||
|
FC_ASSERT( r == d.size() );
|
||||||
|
}
|
||||||
|
// std::string b64 = base64_decode( var.as_string() );
|
||||||
|
// vo = std::vector<char>( b64.c_str(), b64.c_str() + b64.size() );
|
||||||
|
}
|
||||||
|
|
||||||
namespace raw {
|
namespace raw {
|
||||||
namespace bip = boost::interprocess;
|
namespace bip = boost::interprocess;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue