Fawkes API
Fawkes Development Version
|
Register to map msg type numbers to Protobuf messages. More...
#include <>>
Public Types | |
typedef std::multimap< std::string, std::string > | LoadFailMap |
Mapping from message type to load error message. More... | |
Public Member Functions | |
MessageRegister () | |
Constructor. More... | |
MessageRegister (std::vector< std::string > &proto_path) | |
Constructor. More... | |
~MessageRegister () | |
Destructor. More... | |
void | add_message_type (std::string msg_type) |
Add a message type from generated pool. More... | |
template<class MT > | |
std::enable_if< std::is_base_of< google::protobuf::Message, MT >::value, void >::type | add_message_type (uint16_t component_id, uint16_t msg_type) |
Add a new message type. More... | |
template<class MT > | |
std::enable_if< std::is_base_of< google::protobuf::Message, MT >::value, void >::type | add_message_type () |
Add a new message type. More... | |
void | remove_message_type (uint16_t component_id, uint16_t msg_type) |
Remove the given message type. More... | |
std::shared_ptr< google::protobuf::Message > | new_message_for (uint16_t component_id, uint16_t msg_type) |
Create a new message instance. More... | |
std::shared_ptr< google::protobuf::Message > | new_message_for (std::string &full_name) |
Create a new message instance. More... | |
void | serialize (uint16_t component_id, uint16_t msg_type, google::protobuf::Message &msg, frame_header_t &frame_header, message_header_t &message_header, std::string &data) |
Serialize a message. More... | |
std::shared_ptr< google::protobuf::Message > | deserialize (frame_header_t &frame_header, message_header_t &message_header, void *data) |
Deserialize message. More... | |
const LoadFailMap & | load_failures () const |
Get failure messages from loading. More... | |
Register to map msg type numbers to Protobuf messages.
The register is used to automatically parse incoming messages to the appropriate type. In your application, you need to register any message you want to read. All unknown messages are silently dropped.
Definition at line 69 of file message_register.h.
typedef std::multimap<std::string, std::string> protobuf_comm::MessageRegister::LoadFailMap |
Mapping from message type to load error message.
Definition at line 149 of file message_register.h.
protobuf_comm::MessageRegister::MessageRegister | ( | ) |
Constructor.
Definition at line 61 of file message_register.cpp.
protobuf_comm::MessageRegister::MessageRegister | ( | std::vector< std::string > & | proto_path | ) |
Constructor.
proto_path | file paths to search for proto files. All message types within these files will automatically be registered and available for dynamic message creation. |
Definition at line 74 of file message_register.cpp.
References add_message_type().
protobuf_comm::MessageRegister::~MessageRegister | ( | ) |
Destructor.
Definition at line 112 of file message_register.cpp.
void protobuf_comm::MessageRegister::add_message_type | ( | std::string | msg_type | ) |
Add a message type from generated pool.
This will check all message libraries for a type of the given name and if found registers it.
msg_type | the full name of the message type to add, i.e. including a package name if the message type has one. The message must have been registered with either the generated messages pool or with the pool associated with the proto paths passed to the constructor. |
Definition at line 156 of file message_register.cpp.
Referenced by protobuf_clips::ClipsProtobufCommunicator::disable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_pb_register_type().
|
inline |
Add a new message type.
The template parameter must be a sub-class of google::protobuf::Message. An instance is spawned and kept internally to spawn more on incoming messages.
component_id | ID of component this message type belongs to |
msg_type | message type |
Definition at line 86 of file message_register.h.
|
inline |
Add a new message type.
The template parameter must be a sub-class of google::protobuf::Message. An instance is spawned and kept internally to spawn more on incoming messages.
Definition at line 110 of file message_register.h.
Referenced by MessageRegister().
std::shared_ptr< google::protobuf::Message > protobuf_comm::MessageRegister::deserialize | ( | frame_header_t & | frame_header, |
message_header_t & | message_header, | ||
void * | data | ||
) |
Deserialize message.
frame_header | incoming message's frame header |
message_header | incoming message's message header |
data | incoming message's data buffer |
std::runtime_error | thrown if anything goes wrong when deserializing the message, e.g. if no protobuf message has been registered for the given component ID and message type. |
Definition at line 326 of file message_register.cpp.
References protobuf_comm::message_header_t::component_id, protobuf_comm::message_header_t::msg_type, new_message_for(), and protobuf_comm::frame_header_t::payload_size.
Referenced by protobuf_comm::ProtobufStreamClient::disconnect(), and protobuf_comm::ProtobufBroadcastPeer::set_filter_self().
|
inline |
Get failure messages from loading.
If the proto path constructor is used this function returns a list of loading errors after construction.
Definition at line 156 of file message_register.h.
std::shared_ptr< google::protobuf::Message > protobuf_comm::MessageRegister::new_message_for | ( | uint16_t | component_id, |
uint16_t | msg_type | ||
) |
Create a new message instance.
component_id | ID of component this message type belongs to |
msg_type | message type |
Definition at line 229 of file message_register.cpp.
Referenced by deserialize(), protobuf_clips::ClipsProtobufCommunicator::disable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_create_msg().
std::shared_ptr< google::protobuf::Message > protobuf_comm::MessageRegister::new_message_for | ( | std::string & | full_name | ) |
Create a new message instance.
full_name | full message type name, i.e. the message type name possibly with a package name prefix. |
Definition at line 257 of file message_register.cpp.
void protobuf_comm::MessageRegister::remove_message_type | ( | uint16_t | component_id, |
uint16_t | msg_type | ||
) |
Remove the given message type.
component_id | ID of component this message type belongs to |
msg_type | message type |
Definition at line 186 of file message_register.cpp.
void protobuf_comm::MessageRegister::serialize | ( | uint16_t | component_id, |
uint16_t | msg_type, | ||
google::protobuf::Message & | msg, | ||
frame_header_t & | frame_header, | ||
message_header_t & | message_header, | ||
std::string & | data | ||
) |
Serialize a message.
component_id | ID of component this message type belongs to |
msg_type | message type |
msg | message to seialize |
frame_header | upon return, the frame header is filled out according to the given information and message. |
message_header | upon return, the frame header is filled out according to the given information and message. |
data | upon return, contains the serialized message |
Definition at line 285 of file message_register.cpp.
References protobuf_comm::message_header_t::component_id, protobuf_comm::message_header_t::msg_type, and protobuf_comm::frame_header_t::payload_size.
Referenced by protobuf_comm::ProtobufStreamClient::send(), and protobuf_comm::ProtobufBroadcastPeer::send().