Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto 2 : // Copyright (c) 2009-2020 The Bitcoin Core developers 3 : // Distributed under the MIT software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #ifndef BITCOIN_NETMESSAGEMAKER_H 7 : #define BITCOIN_NETMESSAGEMAKER_H 8 : 9 : #include <net.h> 10 : #include <serialize.h> 11 : 12 : class CNetMsgMaker 13 : { 14 : public: 15 13963792 : explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){} 16 : 17 : template <typename... Args> 18 747929 : CSerializedNetMsg Make(int nFlags, std::string msg_type, Args&&... args) const 19 : { 20 747929 : CSerializedNetMsg msg; 21 747929 : msg.m_type = std::move(msg_type); 22 747929 : msg.data.reserve(4 * 1024); 23 747929 : CVectorWriter{ SER_NETWORK, nFlags | nVersion, msg.data, 0, std::forward<Args>(args)... }; 24 747929 : msg.data.shrink_to_fit(); 25 747929 : return msg; 26 747929 : } 27 : 28 : template <typename... Args> 29 747724 : CSerializedNetMsg Make(std::string msg_type, Args&&... args) const 30 : { 31 747724 : return Make(0, std::move(msg_type), std::forward<Args>(args)...); 32 0 : } 33 : 34 : private: 35 : const int nVersion; 36 : }; 37 : 38 : #endif // BITCOIN_NETMESSAGEMAKER_H