rippled
Loading...
Searching...
No Matches
Message.h
1#pragma once
2
3#include <xrpld/overlay/Compression.h>
4
5#include <xrpl/basics/ByteUtilities.h>
6#include <xrpl/protocol/PublicKey.h>
7#include <xrpl/protocol/messages.h>
8
9#include <algorithm>
10#include <cstdint>
11
12namespace xrpl {
13
15
16// VFALCO NOTE If we forward declare Message and write out shared_ptr
17// instead of using the in-class type alias, we can remove the
18// entire ripple.pb.h from the main headers.
19//
20
21// packaging of messages into length/type-prepended buffers
22// ready for transmission.
23//
24// Message implements simple "packing" of protocol buffers Messages into
25// a string prepended by a header specifying the message length.
26// MessageType should be a Message class generated by the protobuf compiler.
27//
28
30{
33
34public:
41 Message(
42 ::google::protobuf::Message const& message,
43 protocol::MessageType type,
44 std::optional<PublicKey> const& validator = {});
45
49
50 static std::size_t
51 messageSize(::google::protobuf::Message const& message);
52
53 static std::size_t
54 totalSize(::google::protobuf::Message const& message);
55
63 getBuffer(Compressed tryCompressed);
64
68 {
69 return category_;
70 }
71
75 {
76 return validatorKey_;
77 }
78
79private:
85
94 void
97 std::uint32_t payloadBytes,
98 int type,
99 Algorithm compression,
100 std::uint32_t uncompressedBytes);
101
106 void
107 compress();
108
115 int
116 getType(std::uint8_t const* in) const;
117};
118
119} // namespace xrpl
std::size_t getCategory() const
Get the traffic category.
Definition Message.h:67
compression::Compressed Compressed
Definition Message.h:31
int getType(std::uint8_t const *in) const
Get the message type from the payload header.
Definition Message.cpp:194
std::optional< PublicKey > validatorKey_
Definition Message.h:84
std::size_t category_
Definition Message.h:82
std::once_flag once_flag_
Definition Message.h:83
std::optional< PublicKey > const & getValidatorKey() const
Get the validator's key.
Definition Message.h:74
static std::size_t totalSize(::google::protobuf::Message const &message)
Definition Message.cpp:43
std::vector< uint8_t > const & getBuffer(Compressed tryCompressed)
Retrieve the packed message data.
Definition Message.cpp:180
std::vector< uint8_t > buffer_
Definition Message.h:80
void setHeader(std::uint8_t *in, std::uint32_t payloadBytes, int type, Algorithm compression, std::uint32_t uncompressedBytes)
Set the payload header.
Definition Message.cpp:145
void compress()
Try to compress the payload.
Definition Message.cpp:49
static std::size_t messageSize(::google::protobuf::Message const &message)
Definition Message.cpp:32
std::size_t getBufferSize()
Retrieve the size of the packed but uncompressed message data.
Definition Message.cpp:174
std::vector< uint8_t > bufferCompressed_
Definition Message.h:81
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr auto megabytes(T value) noexcept
constexpr std::size_t maximumMessageSize
Definition Message.h:14