From cb9a96755df4ecae681db4669ad2aecef9c13671 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 3 Apr 2019 18:04:00 +0200 Subject: [PATCH] Add proper serialization for boost::endian::endian_buffer --- include/fc/io/raw.hpp | 12 ++++++++++++ include/fc/io/raw_fwd.hpp | 5 +++++ include/fc/variant.hpp | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 9b686f7..5b3bfc6 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -676,6 +676,18 @@ namespace fc { } } + template + void pack( Stream& s, const boost::endian::endian_buffer& v, uint32_t _max_depth ) + { + FC_ASSERT( _max_depth > 0 ); + s.write( v.data(), sizeof(v) ); + } + template + void unpack( Stream& s, boost::endian::endian_buffer& v, uint32_t _max_depth ) + { + FC_ASSERT( _max_depth > 0 ); + s.read( v.data(), sizeof(v) ); + } template diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index c1c1442..f8cf921 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -117,6 +118,10 @@ namespace fc { template inline void pack( Stream& s, const char* v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void pack( Stream& s, const std::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, std::vector& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template + inline void pack( Stream& s, const boost::endian::endian_buffer& v, uint32_t _max_depth ); + template + inline void unpack( Stream& s, boost::endian::endian_buffer& v, uint32_t _max_depth ); template inline void pack( Stream& s, const fc::array& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, fc::array& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH); diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index c98e796..8da0b2a 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #ifdef FC_ASSERT @@ -165,6 +166,19 @@ namespace fc template void from_variant( const variant& v, std::pair& p, uint32_t max_depth ); + template + void to_variant( const boost::endian::endian_buffer& var, variant& vo, uint32_t max_depth ) + { + to_variant( var.value(), vo, max_depth ); + } + template + void from_variant( const variant& var, boost::endian::endian_buffer& vo, uint32_t max_depth ) + { + T tmp; + from_variant( var, tmp, max_depth ); + vo = tmp; + } + /** * @brief stores null, int64, uint64, double, bool, string, std::vector, * and variant_object's.