2016-11-10 17:05:23 -05:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2020-12-31 09:48:25 +01:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2016-11-10 17:05:23 -05:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NETMESSAGEMAKER_H
|
|
|
|
#define BITCOIN_NETMESSAGEMAKER_H
|
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <net.h>
|
|
|
|
#include <serialize.h>
|
2016-11-10 17:05:23 -05:00
|
|
|
|
|
|
|
class CNetMsgMaker
|
|
|
|
{
|
|
|
|
public:
|
2017-08-01 12:22:41 +02:00
|
|
|
explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}
|
2016-11-10 17:05:23 -05:00
|
|
|
|
|
|
|
template <typename... Args>
|
2020-05-10 19:48:11 +02:00
|
|
|
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args&&... args) const
|
2016-11-10 17:05:23 -05:00
|
|
|
{
|
|
|
|
CSerializedNetMsg msg;
|
2020-05-10 19:48:11 +02:00
|
|
|
msg.m_type = std::move(msg_type);
|
2016-11-10 17:05:23 -05:00
|
|
|
CVectorWriter{ SER_NETWORK, nFlags | nVersion, msg.data, 0, std::forward<Args>(args)... };
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2020-05-10 19:48:11 +02:00
|
|
|
CSerializedNetMsg Make(std::string msg_type, Args&&... args) const
|
2016-11-10 17:05:23 -05:00
|
|
|
{
|
2020-05-10 19:48:11 +02:00
|
|
|
return Make(0, std::move(msg_type), std::forward<Args>(args)...);
|
2016-11-10 17:05:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int nVersion;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_NETMESSAGEMAKER_H
|