20#include <xrpld/overlay/Message.h>
21#include <xrpld/overlay/detail/TrafficCount.h>
27 ::google::protobuf::Message
const& message,
30 : category_(
TrafficCount::categorize(message, type, false))
31 , validatorKey_(validator)
38 messageBytes,
"ripple::Message::Message : non-empty message input");
44 if (messageBytes != 0)
45 message.SerializeToArray(
buffer_.
data() + headerBytes, messageBytes);
49 "ripple::Message::Message : message size matches the buffer");
56#if defined(GOOGLE_PROTOBUF_VERSION) && (GOOGLE_PROTOBUF_VERSION >= 3011000)
57 return message.ByteSizeLong();
59 return message.ByteSize();
74 auto const messageBytes =
buffer_.
size() - headerBytes;
78 bool const compressible = [&] {
79 if (messageBytes <= 70)
83 case protocol::mtMANIFESTS:
84 case protocol::mtENDPOINTS:
85 case protocol::mtTRANSACTION:
86 case protocol::mtGET_LEDGER:
87 case protocol::mtLEDGER_DATA:
88 case protocol::mtGET_OBJECTS:
89 case protocol::mtVALIDATORLIST:
90 case protocol::mtVALIDATORLISTCOLLECTION:
91 case protocol::mtREPLAY_DELTA_RESPONSE:
92 case protocol::mtTRANSACTIONS:
94 case protocol::mtPING:
95 case protocol::mtCLUSTER:
96 case protocol::mtPROPOSE_LEDGER:
97 case protocol::mtSTATUS_CHANGE:
98 case protocol::mtHAVE_SET:
99 case protocol::mtVALIDATION:
100 case protocol::mtPROOF_PATH_REQ:
101 case protocol::mtPROOF_PATH_RESPONSE:
102 case protocol::mtREPLAY_DELTA_REQ:
103 case protocol::mtHAVE_TRANSACTIONS:
111 auto payload =
static_cast<void const*
>(
buffer_.
data() + headerBytes);
122 (messageBytes - (headerBytesCompressed - headerBytes)))
184 (size >> 24) & 0x0F);
190 pack(
in, payloadBytes);
195 if (compression != Algorithm::None)
197 pack(
in, uncompressedBytes);
211 if (tryCompressed == Compressed::Off)
225 int type = (
static_cast<int>(*(
in + 4)) << 8) + *(
in + 5);
std::once_flag once_flag_
Message(::google::protobuf::Message const &message, int type, std::optional< PublicKey > const &validator={})
Constructor.
void setHeader(std::uint8_t *in, std::uint32_t payloadBytes, int type, Algorithm compression, std::uint32_t uncompressedBytes)
Set the payload header.
std::vector< uint8_t > const & getBuffer(Compressed tryCompressed)
Retrieve the packed message data.
std::size_t getBufferSize()
Retrieve the size of the packed but uncompressed message data.
static std::size_t totalSize(::google::protobuf::Message const &message)
std::vector< uint8_t > buffer_
std::vector< uint8_t > bufferCompressed_
int getType(std::uint8_t const *in) const
Get the message type from the payload header.
void compress()
Try to compress the payload.
static std::size_t messageSize(::google::protobuf::Message const &message)
std::size_t constexpr headerBytes
std::size_t compress(void const *in, std::size_t inSize, BufferFactory &&bf, Algorithm algorithm=Algorithm::LZ4)
Compress input data.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.