]> Git Repo - VerusCoin.git/blob - src/cc/utils.h
Initial assets
[VerusCoin.git] / src / cc / utils.h
1 /******************************************************************************
2  * Copyright © 2014-2018 The SuperNET Developers.                             *
3  *                                                                            *
4  * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at                  *
5  * the top-level directory of this distribution for the individual copyright  *
6  * holder information and the developer policies on copyright and licensing.  *
7  *                                                                            *
8  * Unless otherwise agreed in a custom licensing agreement, no part of the    *
9  * SuperNET software, including this file may be copied, modified, propagated *
10  * or distributed except according to the terms contained in the LICENSE file *
11  *                                                                            *
12  * Removal or modification of this copyright notice is prohibited.            *
13  *                                                                            *
14  ******************************************************************************/
15
16 #ifndef CC_UTILS_H
17 #define CC_UTILS_H
18
19 #include "streams.h"
20 #include "version.h"
21
22
23 /*
24  * Serialisation boilerplate
25  */
26
27 template <class T>
28 std::vector<uint8_t> SerializeF(const T f)
29 {
30     CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
31     f(ss);
32     return std::vector<unsigned char>(ss.begin(), ss.end());
33 }
34
35 template <class T>
36 bool DeserializeF(const std::vector<unsigned char> vIn, T f)
37 {
38     CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION);
39     try {
40          f(ss);
41         if (ss.eof()) return true;
42     } catch(...) {}
43     return false;
44 }
45
46 #define E_MARSHAL(body) SerializeF([&] (CDataStream &ss) {body;})
47 #define E_UNMARSHAL(params, body) DeserializeF(params, [&] (CDataStream &ss) {body;})
48
49 #endif /* CC_UTILS_H */
This page took 0.024755 seconds and 4 git commands to generate.