Bitcoin ABC 0.30.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
12namespace MessageWriter {
13
14template <typename... Args>
15static void WriteMessage(CDataStream &stream, std::string command,
16 Args &&...args) {
17 CSerializedNetMsg payload = CNetMsgMaker(stream.GetVersion())
18 .Make(command, std::forward<Args>(args)...);
19
20 // Serialize header
21 std::vector<uint8_t> serializedHeader;
23 serializer.prepareForTransport(GetConfig(), payload, serializedHeader);
24
25 // Write message header + payload to outgoing stream
26 stream.write(MakeByteSpan(serializedHeader));
27 if (payload.data.size()) {
28 stream.write(MakeByteSpan(payload.data));
29 }
30}
31
32} // namespace MessageWriter
33
34#endif // BITCOIN_SEEDER_MESSAGEWRITER_H
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:177
int GetVersion() const
Definition: streams.h:339
void write(Span< const value_type > src)
Definition: streams.h:379
CSerializedNetMsg Make(int nFlags, std::string msg_type, Args &&...args) const
void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header) override
Definition: net.cpp:830
const Config & GetConfig()
Definition: config.cpp:40
static void WriteMessage(CDataStream &stream, std::string command, Args &&...args)
Definition: messagewriter.h:15
Span< const std::byte > MakeByteSpan(V &&v) noexcept
Definition: span.h:301
std::vector< uint8_t > data
Definition: net.h:131