rippled
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ripple::Message Class Reference
Inheritance diagram for ripple::Message:
Inheritance graph
[legend]
Collaboration diagram for ripple::Message:
Collaboration graph
[legend]

Public Member Functions

 Message (::google::protobuf::Message const &message, int type)
 Constructor. More...
 
std::vector< uint8_t > const & getBuffer (Compressed tryCompressed)
 Retrieve the packed message data. More...
 
std::size_t getCategory () const
 Get the traffic category. More...
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 

Private Types

using Compressed = compression::Compressed
 
using Algorithm = compression::Algorithm
 

Private Member Functions

void setHeader (std::uint8_t *in, std::uint32_t payloadBytes, int type, Algorithm comprAlgorithm, std::uint32_t uncompressedBytes)
 Set the payload header. More...
 
void compress ()
 Try to compress the payload. More...
 
int getType (std::uint8_t const *in) const
 Get the message type from the payload header. More...
 

Private Attributes

std::vector< uint8_t > buffer_
 
std::vector< uint8_t > bufferCompressed_
 
std::size_t category_
 
std::once_flag once_flag_
 

Detailed Description

Definition at line 49 of file overlay/Message.h.

Member Typedef Documentation

◆ Compressed

Definition at line 51 of file overlay/Message.h.

◆ Algorithm

Definition at line 52 of file overlay/Message.h.

Constructor & Destructor Documentation

◆ Message()

ripple::Message::Message ( ::google::protobuf::Message const &  message,
int  type 
)

Constructor.

Parameters
messageProtocol message to serialize
typeProtocol message type

Definition at line 26 of file Message.cpp.

Member Function Documentation

◆ getBuffer()

std::vector< uint8_t > const & ripple::Message::getBuffer ( Compressed  tryCompressed)

Retrieve the packed message data.

If compressed message is requested but the message is not compressible then the uncompressed buffer is returned.

Parameters
compressedRequest compressed (Compress::On) or uncompressed (Compress::Off) payload buffer
Returns
Payload buffer

Definition at line 153 of file Message.cpp.

◆ getCategory()

std::size_t ripple::Message::getCategory ( ) const

Get the traffic category.

Definition at line 72 of file overlay/Message.h.

◆ setHeader()

void ripple::Message::setHeader ( std::uint8_t in,
std::uint32_t  payloadBytes,
int  type,
Algorithm  comprAlgorithm,
std::uint32_t  uncompressedBytes 
)
private

Set the payload header.

Set payload header Uncompressed message header 47-42 Set to 0 41-16 Payload size 15-0 Message Type Compressed message header 79 Set to 0, indicates the message is compressed 78-76 Compression algorithm, value 1-7.

Parameters
inPointer to the payload
payloadBytesSize of the payload excluding the header size
typeProtocol message type
comprAlgorithmCompression algorithm used in compression, currently LZ4 only. If None then the message is uncompressed.
uncompressedBytesSize of the uncompressed message

Set to 1 to indicate LZ4 compression 75-74 Set to 0 73-48 Payload size 47-32 Message Type 31-0 Uncompressed message size

Definition at line 123 of file Message.cpp.

◆ compress()

void ripple::Message::compress ( )
private

Try to compress the payload.

Can be called concurrently by multiple peers but is compressed once. If the message is not compressible then the serialized buffer_ is used.

Definition at line 48 of file Message.cpp.

◆ getType()

int ripple::Message::getType ( std::uint8_t const *  in) const
private

Get the message type from the payload header.

First four bytes are the compression/algorithm flag and the payload size. Next two bytes are the message type

Parameters
inPayload header pointer
Returns
Message type

Definition at line 167 of file Message.cpp.

Member Data Documentation

◆ buffer_

std::vector<uint8_t> ripple::Message::buffer_
private

Definition at line 78 of file overlay/Message.h.

◆ bufferCompressed_

std::vector<uint8_t> ripple::Message::bufferCompressed_
private

Definition at line 79 of file overlay/Message.h.

◆ category_

std::size_t ripple::Message::category_
private

Definition at line 80 of file overlay/Message.h.

◆ once_flag_

std::once_flag ripple::Message::once_flag_
private

Definition at line 81 of file overlay/Message.h.