rebase to 0.18.3.3 completed

This commit is contained in:
Some Random Crypto Guy
2024-06-05 14:03:44 +01:00
parent e23423c16d
commit d39c20bb2d
160 changed files with 4209 additions and 3394 deletions
+2 -2
View File
@@ -133,7 +133,7 @@ struct binary_archive<false> : public binary_archive_base<false>
good_ &= (len == actual);
std::memcpy(buf, bytes_.data() - actual, actual);
}
template <class T>
void serialize_varint(T &v)
{
@@ -205,7 +205,7 @@ struct binary_archive<true> : public binary_archive_base<true>
{
stream_.write((char *)buf, len);
}
void serialize_readable_string(const char *buf, size_t len, const char *delimiter="\"") {
stream_.write(buf, len);
}
+2 -2
View File
@@ -42,7 +42,7 @@ namespace serialization
typename std::enable_if<!use_container_varint<T>(), bool>::type
serialize_container_element(Archive& ar, T& e)
{
return ::do_serialize(ar, e);
return do_serialize(ar, e);
}
template<typename Archive, typename T>
@@ -52,7 +52,7 @@ namespace serialization
static constexpr const bool previously_varint = std::is_same<uint64_t, T>() || std::is_same<uint32_t, T>();
if (!previously_varint && ar.varint_bug_backward_compatibility_enabled() && !typename Archive::is_saving())
return ::do_serialize(ar, e);
return do_serialize(ar, e);
ar.serialize_varint(e);
return true;
}
+4 -6
View File
@@ -42,14 +42,12 @@ struct debug_archive : public json_archive<W> {
};
template <class T>
struct serializer<debug_archive<true>, T>
static inline bool do_serialize(debug_archive<true> &ar, T &v)
{
static void serialize(debug_archive<true> &ar, T &v)
{
ar.begin_object();
ar.tag(variant_serialization_traits<debug_archive<true>, T>::get_tag());
serializer<json_archive<true>, T>::serialize(ar, v);
do_serialize(static_cast<json_archive<true>&>(ar), v);
ar.end_object();
ar.stream() << std::endl;
}
};
return true;
}
-2
View File
@@ -31,8 +31,6 @@
#include "cryptonote_basic/difficulty.h"
#include "serialization.h"
template<> struct is_basic_type<cryptonote::difficulty_type> { typedef boost::true_type type; };
template <template <bool> class Archive>
inline bool do_serialize(Archive<false>& ar, cryptonote::difficulty_type &diff)
{
+28 -131
View File
@@ -260,28 +260,15 @@ void fromJsonValue(const rapidjson::Value& val, long& i)
to_int64(val, i);
}
void fromJsonValue(const rapidjson::Value& val, cryptonote::transaction_type& type)
{
to_uint(val, type);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::transaction& tx)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, version, tx.version);
INSERT_INTO_JSON_OBJECT(dest, unlock_time, tx.unlock_time);
INSERT_INTO_JSON_OBJECT(dest, inputs, tx.vin);
INSERT_INTO_JSON_OBJECT(dest, outputs, tx.vout);
INSERT_INTO_JSON_OBJECT(dest, extra, tx.extra);
INSERT_INTO_JSON_OBJECT(dest, type, static_cast<uint8_t>(tx.type));
if (tx.type != cryptonote::transaction_type::MINER && tx.type != cryptonote::transaction_type::PROTOCOL) {
INSERT_INTO_JSON_OBJECT(dest, return_address, tx.return_address);
INSERT_INTO_JSON_OBJECT(dest, return_pubkey, tx.return_pubkey);
INSERT_INTO_JSON_OBJECT(dest, source_asset_type, tx.source_asset_type);
INSERT_INTO_JSON_OBJECT(dest, destination_asset_type, tx.destination_asset_type);
INSERT_INTO_JSON_OBJECT(dest, amount_burnt, tx.amount_burnt);
INSERT_INTO_JSON_OBJECT(dest, amount_slippage_limit, tx.amount_slippage_limit);
}
if (!tx.pruned)
{
INSERT_INTO_JSON_OBJECT(dest, signatures, tx.signatures);
@@ -300,18 +287,10 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::transaction& tx)
}
GET_FROM_JSON_OBJECT(val, tx.version, version);
GET_FROM_JSON_OBJECT(val, tx.unlock_time, unlock_time);
GET_FROM_JSON_OBJECT(val, tx.vin, inputs);
GET_FROM_JSON_OBJECT(val, tx.vout, outputs);
GET_FROM_JSON_OBJECT(val, tx.extra, extra);
GET_FROM_JSON_OBJECT(val, tx.type, type);
if (tx.type != cryptonote::transaction_type::MINER && tx.type != cryptonote::transaction_type::PROTOCOL) {
GET_FROM_JSON_OBJECT(val, tx.return_address, return_address);
GET_FROM_JSON_OBJECT(val, tx.return_pubkey, return_pubkey);
GET_FROM_JSON_OBJECT(val, tx.source_asset_type, source_asset_type);
GET_FROM_JSON_OBJECT(val, tx.destination_asset_type, destination_asset_type);
GET_FROM_JSON_OBJECT(val, tx.amount_burnt, amount_burnt);
GET_FROM_JSON_OBJECT(val, tx.amount_slippage_limit, amount_slippage_limit);
}
GET_FROM_JSON_OBJECT(val, tx.rct_signatures, ringct);
const auto& sigs = val.FindMember("signatures");
@@ -334,7 +313,6 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::b
INSERT_INTO_JSON_OBJECT(dest, timestamp, b.timestamp);
INSERT_INTO_JSON_OBJECT(dest, prev_id, b.prev_id);
INSERT_INTO_JSON_OBJECT(dest, nonce, b.nonce);
INSERT_INTO_JSON_OBJECT(dest, pricing_record, b.pricing_record);
INSERT_INTO_JSON_OBJECT(dest, miner_tx, b.miner_tx);
INSERT_INTO_JSON_OBJECT(dest, protocol_tx, b.protocol_tx);
INSERT_INTO_JSON_OBJECT(dest, tx_hashes, b.tx_hashes);
@@ -355,7 +333,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::block& b)
GET_FROM_JSON_OBJECT(val, b.timestamp, timestamp);
GET_FROM_JSON_OBJECT(val, b.prev_id, prev_id);
GET_FROM_JSON_OBJECT(val, b.nonce, nonce);
GET_FROM_JSON_OBJECT(val, b.pricing_record, pricing_record);
GET_FROM_JSON_OBJECT(val, b.miner_tx, miner_tx);
GET_FROM_JSON_OBJECT(val, b.protocol_tx, protocol_tx);
GET_FROM_JSON_OBJECT(val, b.tx_hashes, tx_hashes);
@@ -508,7 +485,6 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::t
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, amount, txin.amount);
INSERT_INTO_JSON_OBJECT(dest, asset_type, txin.asset_type);
INSERT_INTO_JSON_OBJECT(dest, key_offsets, txin.key_offsets);
INSERT_INTO_JSON_OBJECT(dest, key_image, txin.k_image);
@@ -523,7 +499,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_key& txin)
}
GET_FROM_JSON_OBJECT(val, txin.amount, amount);
GET_FROM_JSON_OBJECT(val, txin.asset_type, asset_type);
GET_FROM_JSON_OBJECT(val, txin.key_offsets, key_offsets);
GET_FROM_JSON_OBJECT(val, txin.k_image, key_image);
}
@@ -1108,108 +1083,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::error& error)
GET_FROM_JSON_OBJECT(val, error.error_str, error_str);
GET_FROM_JSON_OBJECT(val, error.message, message);
}
/*
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const std::pair<std::string, std::pair<uint64_t, uint64_t>>& pr_entry)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, asset_type, pr_entry.first);
INSERT_INTO_JSON_OBJECT(dest, spot, pr_entry.second.first);
INSERT_INTO_JSON_OBJECT(dest, ma, pr_entry.second.second);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, std::pair<std::string, std::pair<uint64_t, uint64_t>>& pr_entry)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, boost::lexical_cast<std::string>(pr_entry.first), asset_type);
GET_FROM_JSON_OBJECT(val, pr_entry.second.first, spot);
GET_FROM_JSON_OBJECT(val, pr_entry.second.second, ma);
}
*/
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::supply_data& supply_data)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, sal, supply_data.sal);
INSERT_INTO_JSON_OBJECT(dest, vsd, supply_data.vsd);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, oracle::supply_data& supply_data)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, supply_data.sal, sal);
GET_FROM_JSON_OBJECT(val, supply_data.vsd, vsd);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::asset_data& asset_data)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, asset_type, asset_data.asset_type);
INSERT_INTO_JSON_OBJECT(dest, spot, asset_data.spot_price);
INSERT_INTO_JSON_OBJECT(dest, ma, asset_data.ma_price);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, oracle::asset_data& asset_data)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, asset_data.asset_type, asset_type);
GET_FROM_JSON_OBJECT(val, asset_data.spot_price, spot);
GET_FROM_JSON_OBJECT(val, asset_data.ma_price, ma);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::pricing_record& pricing_record)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, pr_version, pricing_record.pr_version);
INSERT_INTO_JSON_OBJECT(dest, height, pricing_record.height);
INSERT_INTO_JSON_OBJECT(dest, supply, pricing_record.supply);
INSERT_INTO_JSON_OBJECT(dest, assets, pricing_record.assets);
INSERT_INTO_JSON_OBJECT(dest, timestamp, pricing_record.timestamp);
INSERT_INTO_JSON_OBJECT(dest, signature, pricing_record.signature);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, oracle::pricing_record& pricing_record)
{
LOG_ERROR("Oracle::" << __func__ << ":" << __LINE__);
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, pricing_record.pr_version, pr_version);
GET_FROM_JSON_OBJECT(val, pricing_record.height, height);
GET_FROM_JSON_OBJECT(val, pricing_record.supply, supply);
GET_FROM_JSON_OBJECT(val, pricing_record.assets, assets);
GET_FROM_JSON_OBJECT(val, pricing_record.timestamp, timestamp);
std::string sig_hex;
std::ostringstream oss;
for (size_t i=0; i<pricing_record.signature.size(); ++i) {
oss << std::hex << std::setfill('0') << std::setw(2) << std::uppercase << (int)(pricing_record.signature[i]);
}
GET_FROM_JSON_OBJECT(val, oss.str(), signature);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::BlockHeaderResponse& response)
{
@@ -1220,7 +1093,6 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::r
INSERT_INTO_JSON_OBJECT(dest, timestamp, response.timestamp);
INSERT_INTO_JSON_OBJECT(dest, prev_id, response.prev_id);
INSERT_INTO_JSON_OBJECT(dest, nonce, response.nonce);
INSERT_INTO_JSON_OBJECT(dest, pricing_record, response.pricing_record);
INSERT_INTO_JSON_OBJECT(dest, height, response.height);
INSERT_INTO_JSON_OBJECT(dest, depth, response.depth);
INSERT_INTO_JSON_OBJECT(dest, hash, response.hash);
@@ -1242,7 +1114,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResp
GET_FROM_JSON_OBJECT(val, response.timestamp, timestamp);
GET_FROM_JSON_OBJECT(val, response.prev_id, prev_id);
GET_FROM_JSON_OBJECT(val, response.nonce, nonce);
GET_FROM_JSON_OBJECT(val, response.pricing_record, pricing_record);
GET_FROM_JSON_OBJECT(val, response.height, height);
GET_FROM_JSON_OBJECT(val, response.depth, depth);
GET_FROM_JSON_OBJECT(val, response.hash, hash);
@@ -1279,6 +1150,7 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig&
INSERT_INTO_JSON_OBJECT(dest, bulletproofs, sig.p.bulletproofs);
INSERT_INTO_JSON_OBJECT(dest, bulletproofs_plus, sig.p.bulletproofs_plus);
INSERT_INTO_JSON_OBJECT(dest, mlsags, sig.p.MGs);
INSERT_INTO_JSON_OBJECT(dest, clsags, sig.p.CLSAGs);
INSERT_INTO_JSON_OBJECT(dest, pseudo_outs, sig.get_pseudo_outs());
dest.EndObject();
@@ -1314,6 +1186,7 @@ void fromJsonValue(const rapidjson::Value& val, rct::rctSig& sig)
GET_FROM_JSON_OBJECT(prunable->value, sig.p.bulletproofs, bulletproofs);
GET_FROM_JSON_OBJECT(prunable->value, sig.p.bulletproofs_plus, bulletproofs_plus);
GET_FROM_JSON_OBJECT(prunable->value, sig.p.MGs, mlsags);
GET_FROM_JSON_OBJECT(prunable->value, sig.p.CLSAGs, clsags);
GET_FROM_JSON_OBJECT(prunable->value, pseudo_outs, pseudo_outs);
sig.get_pseudo_outs() = std::move(pseudo_outs);
@@ -1324,6 +1197,7 @@ void fromJsonValue(const rapidjson::Value& val, rct::rctSig& sig)
sig.p.bulletproofs.clear();
sig.p.bulletproofs_plus.clear();
sig.p.MGs.clear();
sig.p.CLSAGs.clear();
sig.get_pseudo_outs().clear();
}
}
@@ -1532,6 +1406,29 @@ void fromJsonValue(const rapidjson::Value& val, rct::mgSig& sig)
GET_FROM_JSON_OBJECT(val, sig.cc, cc);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::clsag& sig)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, s, sig.s);
INSERT_INTO_JSON_OBJECT(dest, c1, sig.c1);
INSERT_INTO_JSON_OBJECT(dest, D, sig.D);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, rct::clsag& sig)
{
if (!val.IsObject())
{
throw WRONG_TYPE("key64 (rct::key[64])");
}
GET_FROM_JSON_OBJECT(val, sig.s, s);
GET_FROM_JSON_OBJECT(val, sig.c1, c1);
GET_FROM_JSON_OBJECT(val, sig.D, D);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::DaemonInfo& info)
{
dest.StartObject();
+3 -7
View File
@@ -197,13 +197,6 @@ void fromJsonValue(const rapidjson::Value& val, long& i);
// end integers
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::supply_data& supply_data);
void fromJsonValue(const rapidjson::Value& val, oracle::supply_data& supply_data);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::asset_data& asset_data);
void fromJsonValue(const rapidjson::Value& val, oracle::asset_data& asset_data);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::pricing_record& pricing_record);
void fromJsonValue(const rapidjson::Value& val, oracle::pricing_record& pricing_record);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::transaction& tx);
void fromJsonValue(const rapidjson::Value& val, cryptonote::transaction& tx);
@@ -311,6 +304,9 @@ void fromJsonValue(const rapidjson::Value& val, rct::boroSig& sig);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::mgSig& sig);
void fromJsonValue(const rapidjson::Value& val, rct::mgSig& sig);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::clsag& sig);
void fromJsonValue(const rapidjson::Value& val, rct::clsag& sig);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::DaemonInfo& info);
void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::DaemonInfo& info);
+2 -2
View File
@@ -47,7 +47,7 @@ namespace serialization
typename std::enable_if<!use_pair_varint<T>(), bool>::type
serialize_pair_element(Archive& ar, T& e)
{
return ::do_serialize(ar, e);
return do_serialize(ar, e);
}
template<typename Archive, typename T>
@@ -57,7 +57,7 @@ namespace serialization
static constexpr const bool previously_varint = std::is_same<uint64_t, T>();
if (!previously_varint && ar.varint_bug_backward_compatibility_enabled() && !typename Archive::is_saving())
return ::do_serialize(ar, e);
return do_serialize(ar, e);
ar.serialize_varint(e);
return true;
}
+24 -103
View File
@@ -57,73 +57,30 @@
template <class T>
struct is_blob_type { typedef boost::false_type type; };
/*! \struct has_free_serializer
*
* \brief a descriptor for dispatching serialize
*/
template <class T>
struct has_free_serializer { typedef boost::true_type type; };
/*! \struct is_basic_type
*
* \brief a descriptor for dispatching serialize
*/
template <class T>
struct is_basic_type { typedef boost::false_type type; };
template<typename F, typename S>
struct is_basic_type<std::pair<F,S>> { typedef boost::true_type type; };
template<>
struct is_basic_type<std::string> { typedef boost::true_type type; };
/*! \struct serializer
*
* \brief ... wouldn't a class be better?
*
* \detailed The logic behind serializing data. Places the archive
* data into the supplied parameter. This dispatches based on the
* supplied \a T template parameter's traits of is_blob_type or it is
* an integral (as defined by the is_integral trait). Depends on the
* \a Archive parameter to have overloaded the serialize_blob(T v,
* size_t size) and serialize_int(T v) base on which trait it
* applied. When the class has neither types, it falls to the
* overloaded method do_serialize(Archive ar) in T to do the work.
*/
template <class Archive, class T>
struct serializer{
static bool serialize(Archive &ar, T &v) {
return serialize(ar, v, typename boost::is_integral<T>::type(), typename is_blob_type<T>::type(), typename is_basic_type<T>::type());
}
template<typename A>
static bool serialize(Archive &ar, T &v, boost::false_type, boost::true_type, A a) {
ar.serialize_blob(&v, sizeof(v));
return true;
}
template<typename A>
static bool serialize(Archive &ar, T &v, boost::true_type, boost::false_type, A a) {
ar.serialize_int(v);
return true;
}
static bool serialize(Archive &ar, T &v, boost::false_type, boost::false_type, boost::false_type) {
//serialize_custom(ar, v, typename has_free_serializer<T>::type());
return v.do_serialize(ar);
}
static bool serialize(Archive &ar, T &v, boost::false_type, boost::false_type, boost::true_type) {
//serialize_custom(ar, v, typename has_free_serializer<T>::type());
return do_serialize(ar, v);
}
static void serialize_custom(Archive &ar, T &v, boost::true_type) {
}
};
/*! \fn do_serialize(Archive &ar, T &v)
*
* \brief just calls the serialize function defined for ar and v...
* \brief main function for dispatching serialization for a given pair of archive and value types
*
* Types marked true with is_blob_type<T> will be serialized as a blob, integral types will be
* serialized as integers, and types who have a `member_do_serialize` method will be serialized
* using that method. Booleans are serialized like blobs.
*/
template <class Archive, class T>
inline bool do_serialize(Archive &ar, T &v)
inline std::enable_if_t<is_blob_type<T>::type::value, bool> do_serialize(Archive &ar, T &v)
{
return ::serializer<Archive, T>::serialize(ar, v);
ar.serialize_blob(&v, sizeof(v));
return true;
}
template <class Archive, class T>
inline std::enable_if_t<boost::is_integral<T>::value, bool> do_serialize(Archive &ar, T &v)
{
ar.serialize_int(v);
return true;
}
template <class Archive, class T>
inline auto do_serialize(Archive &ar, T &v) -> decltype(v.member_do_serialize(ar), true)
{
return v.member_do_serialize(ar);
}
template <class Archive>
inline bool do_serialize(Archive &ar, bool &v)
@@ -144,16 +101,6 @@ inline bool do_serialize(Archive &ar, bool &v)
typedef boost::true_type type; \
}
/*! \macro FREE_SERIALIZER
*
* \brief adds the has_free_serializer to the type
*/
#define FREE_SERIALIZER(T) \
template<> \
struct has_free_serializer<T> { \
typedef boost::true_type type; \
}
/*! \macro VARIANT_TAG
*
* \brief Adds the tag \tag to the \a Archive of \a Type
@@ -174,7 +121,7 @@ inline bool do_serialize(Archive &ar, bool &v)
*/
#define BEGIN_SERIALIZE() \
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) {
bool member_do_serialize(Archive<W> &ar) {
/*! \macro BEGIN_SERIALIZE_OBJECT
*
@@ -183,7 +130,7 @@ inline bool do_serialize(Archive &ar, bool &v)
*/
#define BEGIN_SERIALIZE_OBJECT() \
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) { \
bool member_do_serialize(Archive<W> &ar) { \
ar.begin_object(); \
bool r = do_serialize_object(ar); \
ar.end_object(); \
@@ -197,11 +144,6 @@ inline bool do_serialize(Archive &ar, bool &v)
#define PREPARE_CUSTOM_VECTOR_SERIALIZATION(size, vec) \
::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving())
/*! \macro PREPARE_CUSTOM_DEQUE_SERIALIZATION
*/
#define PREPARE_CUSTOM_DEQUE_SERIALIZATION(size, vec) \
::serialization::detail::prepare_custom_deque_serialization(size, vec, typename Archive<W>::is_saving())
/*! \macro END_SERIALIZE
* \brief self-explanatory
*/
@@ -209,16 +151,6 @@ inline bool do_serialize(Archive &ar, bool &v)
return ar.good(); \
}
/*! \macro VALUE(f)
* \brief the same as FIELD(f)
*/
#define VALUE(f) \
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
/*! \macro FIELD_N(t,f)
*
* \brief serializes a field \a f tagged \a t
@@ -226,7 +158,7 @@ inline bool do_serialize(Archive &ar, bool &v)
#define FIELD_N(t, f) \
do { \
ar.tag(t); \
bool r = ::do_serialize(ar, f); \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
@@ -237,7 +169,7 @@ inline bool do_serialize(Archive &ar, bool &v)
#define FIELD(f) \
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
@@ -247,7 +179,7 @@ inline bool do_serialize(Archive &ar, bool &v)
*/
#define FIELDS(f) \
do { \
bool r = ::do_serialize(ar, f); \
bool r = do_serialize(ar, f); \
if (!r || !ar.good()) return false; \
} while(0);
@@ -317,17 +249,6 @@ namespace serialization {
vec.resize(size);
}
template <typename T>
void prepare_custom_deque_serialization(size_t size, std::deque<T>& vec, const boost::mpl::bool_<true>& /*is_saving*/)
{
}
template <typename T>
void prepare_custom_deque_serialization(size_t size, std::deque<T>& vec, const boost::mpl::bool_<false>& /*is_saving*/)
{
vec.resize(size);
}
/*! \fn do_check_stream_state
*
* \brief self explanatory
+1 -1
View File
@@ -39,7 +39,7 @@ namespace serialization
template <typename Archive, class T>
bool serialize_tuple_element(Archive& ar, T& e)
{
return ::do_serialize(ar, e);
return do_serialize(ar, e);
}
template <typename Archive>
+17 -28
View File
@@ -72,7 +72,7 @@ struct variant_reader
{
if(variant_serialization_traits<Archive, current_type>::get_tag() == t) {
current_type x;
if(!::do_serialize(ar, x))
if(!do_serialize(ar, x))
{
ar.set_fail();
return false;
@@ -100,19 +100,13 @@ struct variant_reader<Archive, Variant, TBegin, TBegin>
}
};
template <template <bool> class Archive, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct serializer<Archive<false>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
{
typedef boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> variant_type;
typedef typename Archive<false>::variant_tag_type variant_tag_type;
typedef typename variant_type::types types;
static bool serialize(Archive<false> &ar, variant_type &v) {
variant_tag_type t;
template <template <bool> class Archive, typename... T>
static bool do_serialize(Archive<false> &ar, boost::variant<T...> &v) {
using types = typename boost::variant<T...>::types;
typename Archive<false>::variant_tag_type t;
ar.begin_variant();
ar.read_variant_tag(t);
if(!variant_reader<Archive<false>, variant_type,
if(!variant_reader<Archive<false>, boost::variant<T...>,
typename boost::mpl::begin<types>::type,
typename boost::mpl::end<types>::type>::read(ar, v, t))
{
@@ -121,27 +115,21 @@ struct serializer<Archive<false>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
}
ar.end_variant();
return true;
}
};
}
template <template <bool> class Archive, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct serializer<Archive<true>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
template <template <bool> class Archive>
struct variant_write_visitor : public boost::static_visitor<bool>
{
typedef boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> variant_type;
//typedef typename Archive<true>::variant_tag_type variant_tag_type;
struct visitor : public boost::static_visitor<bool>
{
Archive<true> &ar;
visitor(Archive<true> &a) : ar(a) { }
variant_write_visitor(Archive<true> &a) : ar(a) { }
template <class T>
bool operator ()(T &rv) const
{
ar.begin_variant();
ar.write_variant_tag(variant_serialization_traits<Archive<true>, T>::get_tag());
if(!::do_serialize(ar, rv))
if(!do_serialize(ar, rv))
{
ar.set_fail();
return false;
@@ -149,9 +137,10 @@ struct serializer<Archive<true>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
ar.end_variant();
return true;
}
};
static bool serialize(Archive<true> &ar, variant_type &v) {
return boost::apply_visitor(visitor(ar), v);
}
};
template <template <bool> class Archive, typename... T>
static bool do_serialize(Archive<true> &ar, boost::variant<T...> &v)
{
return boost::apply_visitor(variant_write_visitor<Archive>(ar), v);
}