Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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) {
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
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
const Config & GetConfig()
Definition config.cpp:40
static void WriteMessage(CDataStream &stream, std::string command, Args &&...args)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
Span< const std::byte > MakeByteSpan(V &&v) noexcept
Definition span.h:301