#include <ros_introspection.hpp>
Classes | |
struct | RulesCache |
Public Types | |
typedef std::function< void(const ROSType &, absl::Span< uint8_t > &)> | VisitingCallback |
Public Member Functions | |
void | applyNameTransform (const std::string &msg_identifier, const FlatMessage &container, RenamedValues *renamed_value) |
applyNameTransform is used to create a vector of type RenamedValues from the vector FlatMessage::value. Additionally, it apply the renaming rules previously registred using registerRenamingRules. More... | |
void | applyVisitorToBuffer (const std::string &msg_identifier, const ROSType &monitored_type, absl::Span< uint8_t > &buffer, VisitingCallback callback) const |
applyVisitorToBuffer is used to pass a callback that is invoked every time a chunk of memory storing an instance of ROSType = monitored_type is reached. Note that the VisitingCallback can modify the original message, but can NOT change its size. This means that strings and vectors can not be change their length. More... | |
bool | deserializeIntoFlatContainer (const std::string &msg_identifier, absl::Span< uint8_t > buffer, FlatMessage *flat_container_output, const uint32_t max_array_size) const |
deserializeIntoFlatContainer takes a raw buffer of memory and extract information from it. This data is stored in two key/value vectors, FlatMessage::value and FlatMessage::name. It must be noted that the key type is StringTreeLeaf. this type is not particularly user-friendly, but allows a much faster post-processing. More... | |
template<typename T > | |
T | extractField (const std::string &msg_identifier, const absl::Span< uint8_t > &buffer) |
const ROSMessage * | getMessageByType (const ROSType &type, const ROSMessageInfo &info) const |
getMessageByType provides a pointer to a ROSMessage stored in ROSMessageInfo. More... | |
const ROSMessageInfo * | getMessageInfo (const std::string &msg_identifier) const |
getMessageInfo provides some metadata amout a registered ROSMessage. More... | |
Parser () | |
void | registerMessageDefinition (const std::string &message_identifier, const ROSType &main_type, const std::string &definition) |
A single message definition will (most probably) generate myltiple ROSMessage(s). In fact the "child" ROSTypes are parsed as well in a recursive and hierarchical way. To make an example, given as input the geometry_msgs/Pose the result will be a ROSTypeList containing Pose, Point and Quaternion. More... | |
void | registerRenamingRules (const ROSType &type, const std::vector< SubstitutionRule > &rules) |
registerRenamingRules is used to register the renaming rules. You MUST use registerMessageDefinition first. More... | |
void | setMaxArrayPolicy (bool discard_entire_array) |
void | setWarningsStream (std::ostream *output) |
Change where the warning messages are displayed. More... | |
Private Member Functions | |
void | createTrees (ROSMessageInfo &info, const std::string &type_name) const |
void | updateRuleCache () |
Private Attributes | |
std::vector< int > | _alias_array_pos |
bool | _discard_large_array |
std::vector< std::string > | _formatted_string |
std::ostream * | _global_warnings |
std::unordered_map< std::string, ROSMessageInfo > | _registered_messages |
std::unordered_map< ROSType, std::unordered_set< SubstitutionRule > > | _registered_rules |
bool | _rule_cache_dirty |
std::unordered_map< std::string, std::vector< RulesCache > > | _rule_caches |
std::vector< int8_t > | _substituted |
Definition at line 67 of file ros_introspection.hpp.
typedef std::function<void(const ROSType&, absl::Span<uint8_t>&)> RosIntrospection::Parser::VisitingCallback |
Definition at line 172 of file ros_introspection.hpp.
|
inline |
Definition at line 70 of file ros_introspection.hpp.
void RosIntrospection::Parser::applyNameTransform | ( | const std::string & | msg_identifier, |
const FlatMessage & | container, | ||
RenamedValues * | renamed_value | ||
) |
applyNameTransform is used to create a vector of type RenamedValues from the vector FlatMessage::value. Additionally, it apply the renaming rules previously registred using registerRenamingRules.
For example if you apply this to geometry_msgs/Pose the vector renamed_value.value will contain the following pairs (where ... is the number of that field) :
msg_identifier | String ID to identify the registered message (use registerMessageDefinition first). |
container | Source. This instance must be created using deserializeIntoFlatContainer. |
renamed_value | Destination. |
Definition at line 564 of file ros_introspection.cpp.
void RosIntrospection::Parser::applyVisitorToBuffer | ( | const std::string & | msg_identifier, |
const ROSType & | monitored_type, | ||
absl::Span< uint8_t > & | buffer, | ||
Parser::VisitingCallback | callback | ||
) | const |
applyVisitorToBuffer is used to pass a callback that is invoked every time a chunk of memory storing an instance of ROSType = monitored_type is reached. Note that the VisitingCallback can modify the original message, but can NOT change its size. This means that strings and vectors can not be change their length.
msg_identifier | String ID to identify the registered message (use registerMessageDefinition first). |
monitored_type | ROSType that triggers the invokation to the callback |
buffer | Original buffer, passed as mutable since it might be modified. |
callback | The callback. |
Definition at line 257 of file ros_introspection.cpp.
|
private |
Definition at line 47 of file ros_introspection.cpp.
bool RosIntrospection::Parser::deserializeIntoFlatContainer | ( | const std::string & | msg_identifier, |
absl::Span< uint8_t > | buffer, | ||
FlatMessage * | flat_container_output, | ||
const uint32_t | max_array_size | ||
) | const |
deserializeIntoFlatContainer takes a raw buffer of memory and extract information from it. This data is stored in two key/value vectors, FlatMessage::value and FlatMessage::name. It must be noted that the key type is StringTreeLeaf. this type is not particularly user-friendly, but allows a much faster post-processing.
IMPORTANT: this approach is not meant to be used with use arrays such as maps, point clouds and images. It would require a ridicoulous amount of memory and, franckly, make little sense. For this reason the argument max_array_size is used.
This funtion is almost always followed by applyNameTransform, which provide a more human-readable key-value representation.
msg_identifier | String ID to identify the registered message (use registerMessageDefinition first). |
buffer | raw memory to be parsed. |
flat_container_output | output to store the result. It is recommended to reuse the same object multiple times to avoid memory allocations and speed up the parsing. |
max_array_size | Usually we want to avoid special cases like maps and images, which contain very large arrays. max_array_size is used to skip these arrays that are too large. |
return true if the entire message was parsed or false if parts of the message were skipped because an array has (size > max_array_size)
Definition at line 331 of file ros_introspection.cpp.
|
inline |
Definition at line 231 of file ros_introspection.hpp.
const ROSMessage * RosIntrospection::Parser::getMessageByType | ( | const ROSType & | type, |
const ROSMessageInfo & | info | ||
) | const |
getMessageByType provides a pointer to a ROSMessage stored in ROSMessageInfo.
type | ROSType to be found |
info | Instance or ROSMessageInfo that shall contain the ROSType to be found. |
Definition at line 245 of file ros_introspection.cpp.
const ROSMessageInfo * RosIntrospection::Parser::getMessageInfo | ( | const std::string & | msg_identifier | ) | const |
getMessageInfo provides some metadata amout a registered ROSMessage.
msg_identifier | String ID to identify the registered message (use registerMessageDefinition first). |
Definition at line 235 of file ros_introspection.cpp.
void RosIntrospection::Parser::registerMessageDefinition | ( | const std::string & | message_identifier, |
const ROSType & | main_type, | ||
const std::string & | definition | ||
) |
A single message definition will (most probably) generate myltiple ROSMessage(s). In fact the "child" ROSTypes are parsed as well in a recursive and hierarchical way. To make an example, given as input the geometry_msgs/Pose the result will be a ROSTypeList containing Pose, Point and Quaternion.
msg_identifier | name to give to the main type to be extracted. |
msg_definition | text obtained by either:
|
Definition at line 190 of file ros_introspection.cpp.
void RosIntrospection::Parser::registerRenamingRules | ( | const ROSType & | type, |
const std::vector< SubstitutionRule > & | rules | ||
) |
registerRenamingRules is used to register the renaming rules. You MUST use registerMessageDefinition first.
type | The type which must be renamed |
rules | A list of rules to apply to the type. |
Definition at line 136 of file ros_introspection.cpp.
|
inline |
Definition at line 72 of file ros_introspection.hpp.
|
inline |
Change where the warning messages are displayed.
Definition at line 195 of file ros_introspection.hpp.
|
private |
Definition at line 149 of file ros_introspection.cpp.
|
private |
Definition at line 222 of file ros_introspection.hpp.
|
private |
Definition at line 225 of file ros_introspection.hpp.
|
private |
Definition at line 223 of file ros_introspection.hpp.
|
private |
Definition at line 220 of file ros_introspection.hpp.
|
private |
Definition at line 210 of file ros_introspection.hpp.
|
private |
Definition at line 211 of file ros_introspection.hpp.
|
private |
Definition at line 216 of file ros_introspection.hpp.
|
private |
Definition at line 212 of file ros_introspection.hpp.
|
private |
Definition at line 224 of file ros_introspection.hpp.