Bitcoin ABC  0.22.12
P2P Digital Currency
netmessagemaker.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 public:
14  explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn) {}
15 
16  template <typename... Args>
17  CSerializedNetMsg Make(int nFlags, std::string msg_type,
18  Args &&... args) const {
20  msg.m_type = std::move(msg_type);
21  CVectorWriter{SER_NETWORK, nFlags | nVersion, msg.data, 0,
22  std::forward<Args>(args)...};
23  return msg;
24  }
25 
26  template <typename... Args>
27  CSerializedNetMsg Make(std::string msg_type, Args &&... args) const {
28  return Make(0, std::move(msg_type), std::forward<Args>(args)...);
29  }
30 
31 private:
32  const int nVersion;
33 };
34 
35 #endif // BITCOIN_NETMESSAGEMAKER_H
std::string m_type
Definition: net.h:125
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args &&... args) const
CSerializedNetMsg Make(std::string msg_type, Args &&... args) const
const int nVersion
CNetMsgMaker(int nVersionIn)
std::vector< uint8_t > data
Definition: net.h:124
Minimal stream for overwriting and/or appending to an existing byte vector.
Definition: streams.h:62