// Copyright (c) 2016-2024 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * * holder information and the developer policies on copyright and licensing. * * * * Unless otherwise agreed in a custom licensing agreement, no part of the * * SuperNET software, including this file may be copied, modified, propagated * * or distributed except according to the terms contained in the LICENSE file * * * * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ #ifndef CC_UTILS_H #define CC_UTILS_H #include "streams.h" #include "version.h" // Serialization boilerplate template std::vector SerializeF(const T f) { CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); f(ss); return std::vector(ss.begin(), ss.end()); } template bool DeserializeF(const std::vector vIn, T f) { CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION); try { f(ss); if (ss.eof()) return true; } catch(...) {} return false; } #define E_MARSHAL(body) SerializeF([&] (CDataStream &ss) {body;}) #define E_UNMARSHAL(params, body) DeserializeF(params, [&] (CDataStream &ss) {body;}) #endif /* CC_UTILS_H */