Bitcoin ABC  0.24.7
P2P Digital Currency
messagewriter.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SEEDER_MESSAGEWRITER_H
6 #define BITCOIN_SEEDER_MESSAGEWRITER_H
7 
8 #include <config.h>
9 #include <net.h>
10 #include <netmessagemaker.h>
11 
12 namespace MessageWriter {
13 
14 template <typename... Args>
15 static void WriteMessage(CDataStream &stream, std::string command,
16  Args &&... args) {
17  CSerializedNetMsg payload = CNetMsgMaker(stream.GetVersion())
18  .Make(command, std::forward<Args>(args)...);
19  size_t nMessageSize = payload.data.size();
20 
21  // Serialize header
22  std::vector<uint8_t> serializedHeader;
24  serializer.prepareForTransport(GetConfig(), payload, serializedHeader);
25 
26  // Write message header + payload to outgoing stream
27  stream.write(reinterpret_cast<const char *>(serializedHeader.data()),
28  serializedHeader.size());
29  if (nMessageSize) {
30  stream.write(reinterpret_cast<const char *>(payload.data.data()),
31  nMessageSize);
32  }
33 }
34 
35 } // namespace MessageWriter
36 
37 #endif // BITCOIN_SEEDER_MESSAGEWRITER_H
V1TransportSerializer
Definition: net.h:919
MessageWriter::WriteMessage
static void WriteMessage(CDataStream &stream, std::string command, Args &&... args)
Definition: messagewriter.h:15
CDataStream::write
void write(const char *pch, size_t nSize)
Definition: streams.h:427
CSerializedNetMsg
Definition: net.h:129
CNetMsgMaker
Definition: netmessagemaker.h:14
MessageWriter
Definition: messagewriter.h:12
CDataStream::GetVersion
int GetVersion() const
Definition: streams.h:387
netmessagemaker.h
V1TransportSerializer::prepareForTransport
void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header) override
Definition: net.cpp:803
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
config.h
CSerializedNetMsg::data
std::vector< uint8_t > data
Definition: net.h:137
CNetMsgMaker::Make
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args &&... args) const
Definition: netmessagemaker.h:19
net.h
GetConfig
const Config & GetConfig()
Definition: config.cpp:34