1#include <xrpld/overlay/Message.h>
2#include <xrpld/overlay/detail/TrafficCount.h>
9 ::google::protobuf::Message
const& message,
10 protocol::MessageType type,
12 : category_(
TrafficCount::categorize(message, type, false))
13 , validatorKey_(validator)
20 messageBytes,
"ripple::Message::Message : non-empty message input");
26 if (messageBytes != 0)
27 message.SerializeToArray(
buffer_.
data() + headerBytes, messageBytes);
31 "ripple::Message::Message : message size matches the buffer");
38#if defined(GOOGLE_PROTOBUF_VERSION) && (GOOGLE_PROTOBUF_VERSION >= 3011000)
39 return message.ByteSizeLong();
41 return message.ByteSize();
56 auto const messageBytes =
buffer_.
size() - headerBytes;
60 bool const compressible = [&] {
61 if (messageBytes <= 70)
65 case protocol::mtMANIFESTS:
66 case protocol::mtENDPOINTS:
67 case protocol::mtTRANSACTION:
68 case protocol::mtGET_LEDGER:
69 case protocol::mtLEDGER_DATA:
70 case protocol::mtGET_OBJECTS:
71 case protocol::mtVALIDATORLIST:
72 case protocol::mtVALIDATORLISTCOLLECTION:
73 case protocol::mtREPLAY_DELTA_RESPONSE:
74 case protocol::mtTRANSACTIONS:
76 case protocol::mtPING:
77 case protocol::mtCLUSTER:
78 case protocol::mtPROPOSE_LEDGER:
79 case protocol::mtSTATUS_CHANGE:
80 case protocol::mtHAVE_SET:
81 case protocol::mtVALIDATION:
82 case protocol::mtPROOF_PATH_REQ:
83 case protocol::mtPROOF_PATH_RESPONSE:
84 case protocol::mtREPLAY_DELTA_REQ:
85 case protocol::mtHAVE_TRANSACTIONS:
93 auto payload =
static_cast<void const*
>(
buffer_.
data() + headerBytes);
104 (messageBytes - (headerBytesCompressed - headerBytes)))
166 (size >> 24) & 0x0F);
172 pack(
in, payloadBytes);
177 if (compression != Algorithm::None)
179 pack(
in, uncompressedBytes);
193 if (tryCompressed == Compressed::Off)
207 int type = (
static_cast<int>(*(
in + 4)) << 8) + *(
in + 5);
std::once_flag once_flag_
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)
Message(::google::protobuf::Message const &message, protocol::MessageType type, std::optional< PublicKey > const &validator={})
Constructor.
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)
TrafficCount is used to count ingress and egress wire bytes and number of messages.
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.