Changeset View
Changeset View
Standalone View
Standalone View
src/netmessagemaker.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_NETMESSAGEMAKER_H | #ifndef BITCOIN_NETMESSAGEMAKER_H | ||||
#define BITCOIN_NETMESSAGEMAKER_H | #define BITCOIN_NETMESSAGEMAKER_H | ||||
#include <net.h> | #include <net.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
class CNetMsgMaker { | class CNetMsgMaker { | ||||
public: | public: | ||||
explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn) {} | explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn) {} | ||||
template <typename... Args> | template <typename... Args> | ||||
CSerializedNetMsg Make(int nFlags, std::string sCommand, | CSerializedNetMsg Make(int nFlags, std::string msg_type, | ||||
Args &&... args) const { | Args &&... args) const { | ||||
CSerializedNetMsg msg; | CSerializedNetMsg msg; | ||||
msg.command = std::move(sCommand); | msg.m_type = std::move(msg_type); | ||||
CVectorWriter{SER_NETWORK, nFlags | nVersion, msg.data, 0, | CVectorWriter{SER_NETWORK, nFlags | nVersion, msg.data, 0, | ||||
std::forward<Args>(args)...}; | std::forward<Args>(args)...}; | ||||
return msg; | return msg; | ||||
} | } | ||||
template <typename... Args> | template <typename... Args> | ||||
CSerializedNetMsg Make(std::string sCommand, Args &&... args) const { | CSerializedNetMsg Make(std::string msg_type, Args &&... args) const { | ||||
return Make(0, std::move(sCommand), std::forward<Args>(args)...); | return Make(0, std::move(msg_type), std::forward<Args>(args)...); | ||||
} | } | ||||
private: | private: | ||||
const int nVersion; | const int nVersion; | ||||
}; | }; | ||||
#endif // BITCOIN_NETMESSAGEMAKER_H | #endif // BITCOIN_NETMESSAGEMAKER_H |