Fawkes API
Fawkes Development Version
|
#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 (const 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 (const std::string &full_name) |
Create a new message instance. More... | |
void | serialize (uint16_t component_id, uint16_t msg_type, const 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 65 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 143 of file message_register.h.
protobuf_comm::MessageRegister::MessageRegister | ( | ) |
Constructor.
Definition at line 62 of file message_register.cpp.
protobuf_comm::MessageRegister::MessageRegister | ( | const 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.
protobuf_comm::MessageRegister::~MessageRegister | ( | ) |
Destructor.
Definition at line 112 of file message_register.cpp.
|
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 106 of file message_register.h.
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 153 of file message_register.cpp.
|
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 82 of file message_register.h.
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 316 of file message_register.cpp.
|
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 151 of file message_register.h.
std::shared_ptr< google::protobuf::Message > protobuf_comm::MessageRegister::new_message_for | ( | const 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 249 of file message_register.cpp.
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 222 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 182 of file message_register.cpp.
void protobuf_comm::MessageRegister::serialize | ( | uint16_t | component_id, |
uint16_t | msg_type, | ||
const 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 276 of file message_register.cpp.
Referenced by protobuf_comm::ProtobufStreamClient::send(), and protobuf_comm::ProtobufBroadcastPeer::send().