2016-11-10 19:05:23 -03:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2020-12-31 05:48:25 -03:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2016-11-10 19:05:23 -03: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-09 21:57:53 -03:00
|
|
|
#include <net.h>
|
|
|
|
#include <serialize.h>
|
2016-11-10 19:05:23 -03:00
|
|
|
|
|
|
|
class CNetMsgMaker
|
|
|
|
{
|
|
|
|
public:
|
2017-08-01 06:22:41 -04:00
|
|
|
explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}
|
2016-11-10 19:05:23 -03:00
|
|
|
|
|
|
|
template <typename... Args>
|
2020-05-10 13:48:11 -04:00
|
|
|
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args&&... args) const
|
2016-11-10 19:05:23 -03:00
|
|
|
{
|
|
|
|
CSerializedNetMsg msg;
|
2020-05-10 13:48:11 -04:00
|
|
|
msg.m_type = std::move(msg_type);
|
2023-09-11 11:58:22 -03:00
|
|
|
CVectorWriter{nFlags | nVersion, msg.data, 0, std::forward<Args>(args)...};
|
2016-11-10 19:05:23 -03:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
2020-05-10 13:48:11 -04:00
|
|
|
CSerializedNetMsg Make(std::string msg_type, Args&&... args) const
|
2016-11-10 19:05:23 -03:00
|
|
|
{
|
2020-05-10 13:48:11 -04:00
|
|
|
return Make(0, std::move(msg_type), std::forward<Args>(args)...);
|
2016-11-10 19:05:23 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int nVersion;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_NETMESSAGEMAKER_H
|