20#include <xrpld/overlay/Message.h>
21#include <xrpld/overlay/detail/TrafficCount.h>
28 ::google::protobuf::Message
const& message,
29 protocol::MessageType type,
31 : category_(
TrafficCount::categorize(message, type, false))
32 , validatorKey_(validator)
39 messageBytes,
"ripple::Message::Message : non-empty message input");
45 if (messageBytes != 0)
46 message.SerializeToArray(
buffer_.
data() + headerBytes, messageBytes);
50 "ripple::Message::Message : message size matches the buffer");
57#if defined(GOOGLE_PROTOBUF_VERSION) && (GOOGLE_PROTOBUF_VERSION >= 3011000)
58 return message.ByteSizeLong();
60 return message.ByteSize();
75 auto const messageBytes =
buffer_.
size() - headerBytes;
79 bool const compressible = [&] {
80 if (messageBytes <= 70)
84 case protocol::mtMANIFESTS:
85 case protocol::mtENDPOINTS:
86 case protocol::mtTRANSACTION:
87 case protocol::mtGET_LEDGER:
88 case protocol::mtLEDGER_DATA:
89 case protocol::mtGET_OBJECTS:
90 case protocol::mtVALIDATORLIST:
91 case protocol::mtVALIDATORLISTCOLLECTION:
92 case protocol::mtREPLAY_DELTA_RESPONSE:
93 case protocol::mtTRANSACTIONS:
95 case protocol::mtPING:
96 case protocol::mtCLUSTER:
97 case protocol::mtPROPOSE_LEDGER:
98 case protocol::mtSTATUS_CHANGE:
99 case protocol::mtHAVE_SET:
100 case protocol::mtVALIDATION:
101 case protocol::mtPROOF_PATH_REQ:
102 case protocol::mtPROOF_PATH_RESPONSE:
103 case protocol::mtREPLAY_DELTA_REQ:
104 case protocol::mtHAVE_TRANSACTIONS:
112 auto payload =
static_cast<void const*
>(
buffer_.
data() + headerBytes);
123 (messageBytes - (headerBytesCompressed - headerBytes)))
185 (size >> 24) & 0x0F);
191 pack(
in, payloadBytes);
196 if (compression != Algorithm::None)
198 pack(
in, uncompressedBytes);
212 if (tryCompressed == Compressed::Off)
226 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.