Bitcoin ABC  0.24.7
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 <serialize.h>
10 
11 struct CSerializedNetMsg;
12 class CVectorWriter;
13 
14 class CNetMsgMaker {
15 public:
16  explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn) {}
17 
18  template <typename... Args>
19  CSerializedNetMsg Make(int nFlags, std::string msg_type,
20  Args &&... args) const {
22  msg.m_type = std::move(msg_type);
23  CVectorWriter{SER_NETWORK, nFlags | nVersion, msg.data, 0,
24  std::forward<Args>(args)...};
25  return msg;
26  }
27 
28  template <typename... Args>
29  CSerializedNetMsg Make(std::string msg_type, Args &&... args) const {
30  return Make(0, std::move(msg_type), std::forward<Args>(args)...);
31  }
32 
33 private:
34  const int nVersion;
35 };
36 
37 #endif // BITCOIN_NETMESSAGEMAKER_H
CVectorWriter
Minimal stream for overwriting and/or appending to an existing byte vector.
Definition: streams.h:63
CSerializedNetMsg::m_type
std::string m_type
Definition: net.h:138
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:165
CSerializedNetMsg
Definition: net.h:129
CNetMsgMaker
Definition: netmessagemaker.h:14
CNetMsgMaker::Make
CSerializedNetMsg Make(std::string msg_type, Args &&... args) const
Definition: netmessagemaker.h:29
serialize.h
CSerializedNetMsg::data
std::vector< uint8_t > data
Definition: net.h:137
CNetMsgMaker::nVersion
const int nVersion
Definition: netmessagemaker.h:34
CNetMsgMaker::Make
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args &&... args) const
Definition: netmessagemaker.h:19
CNetMsgMaker::CNetMsgMaker
CNetMsgMaker(int nVersionIn)
Definition: netmessagemaker.h:16