forked from lthn/blockchain
implemented boost::optional serialization
This commit is contained in:
parent
f3eb63d25c
commit
b5ad2ffcdc
3 changed files with 68 additions and 7 deletions
|
|
@ -30,6 +30,7 @@
|
|||
#include "serialization/stl_containers.h"
|
||||
#include "serialization/serialization.h"
|
||||
#include "serialization/variant.h"
|
||||
#include "serialization/boost_types.h"
|
||||
#include "serialization/json_archive.h"
|
||||
#include "serialization/debug_archive.h"
|
||||
#include "serialization/keyvalue_serialization.h" // epee key-value serialization
|
||||
|
|
@ -836,13 +837,13 @@ namespace currency
|
|||
BEGIN_VERSIONED_SERIALIZE()
|
||||
FIELD(operation_type)
|
||||
FIELD(descriptor)
|
||||
//FIELD(opt_amount_commitment)
|
||||
FIELD(opt_amount_commitment)
|
||||
END_SERIALIZE()
|
||||
|
||||
BEGIN_BOOST_SERIALIZATION()
|
||||
BOOST_SERIALIZE(operation_type)
|
||||
BOOST_SERIALIZE(descriptor)
|
||||
//BOOST_SERIALIZE(opt_amount_commitment)
|
||||
BOOST_SERIALIZE(opt_amount_commitment)
|
||||
END_BOOST_SERIALIZATION()
|
||||
};
|
||||
|
||||
|
|
@ -853,13 +854,13 @@ namespace currency
|
|||
boost::optional<crypto::signature> opt_amount_commitment_g_proof; // for non-hidden supply, proofs that amount_commitment - supply * asset_id = lin(G)
|
||||
|
||||
BEGIN_VERSIONED_SERIALIZE()
|
||||
//FIELD(opt_amount_commitment_composition_proof)
|
||||
//FIELD(opt_amount_commitment_g_proof)
|
||||
FIELD(opt_amount_commitment_composition_proof)
|
||||
FIELD(opt_amount_commitment_g_proof)
|
||||
END_SERIALIZE()
|
||||
|
||||
BEGIN_BOOST_SERIALIZATION()
|
||||
//BOOST_SERIALIZE(opt_amount_commitment_composition_proof)
|
||||
//BOOST_SERIALIZE(opt_amount_commitment_g_proof)
|
||||
BOOST_SERIALIZE(opt_amount_commitment_composition_proof)
|
||||
BOOST_SERIALIZE(opt_amount_commitment_g_proof)
|
||||
END_BOOST_SERIALIZATION()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit f8d6ed1bbe38d48d7e762154ea9ccbdb33d88424
|
||||
Subproject commit b45d5a82285a8804c859e9d3548fae693716cd6a
|
||||
60
src/serialization/boost_types.h
Normal file
60
src/serialization/boost_types.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2014-2017 The The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/serialization/optional.hpp>
|
||||
|
||||
|
||||
template <template <bool> class Archive, class T>
|
||||
bool do_serialize(Archive<false> &ar, boost::optional<T> &o)
|
||||
{
|
||||
//reading flag
|
||||
bool is_none = false;
|
||||
if (!::do_serialize(ar, is_none))
|
||||
{
|
||||
ar.stream().setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
if (is_none)
|
||||
{
|
||||
o.reset();
|
||||
return true;
|
||||
}
|
||||
o = T();
|
||||
T& rval = o.value();
|
||||
//reading value
|
||||
if (!::do_serialize(ar, rval))
|
||||
{
|
||||
ar.stream().setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <template <bool> class Archive, class T>
|
||||
bool do_serialize(Archive<true> &ar, boost::optional<T> &v)
|
||||
{
|
||||
//writing flag
|
||||
bool is_none = !v.has_value();
|
||||
if (!::do_serialize(ar, is_none))
|
||||
{
|
||||
ar.stream().setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
if (is_none)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!::do_serialize(ar, v.value()))
|
||||
{
|
||||
ar.stream().setstate(std::ios::failbit);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue