Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
RosIntrospection::Parser Class Reference

#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 >
extractField (const std::string &msg_identifier, const absl::Span< uint8_t > &buffer)
 
const ROSMessagegetMessageByType (const ROSType &type, const ROSMessageInfo &info) const
 getMessageByType provides a pointer to a ROSMessage stored in ROSMessageInfo. More...
 
const ROSMessageInfogetMessageInfo (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
 

Detailed Description

Definition at line 67 of file ros_introspection.hpp.

Member Typedef Documentation

typedef std::function<void(const ROSType&, absl::Span<uint8_t>&)> RosIntrospection::Parser::VisitingCallback

Definition at line 172 of file ros_introspection.hpp.

Constructor & Destructor Documentation

RosIntrospection::Parser::Parser ( )
inline

Definition at line 70 of file ros_introspection.hpp.

Member Function Documentation

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) :

  • Pose/Point/x = ...
  • Pose/Point/y = ...
  • Pose/Point/z = ...
  • Pose/Quaternion/x = ...
  • Pose/Quaternion/y = ...
  • Pose/Quaternion/z = ...
  • Pose.Quaternion/w = ...
Parameters
msg_identifierString ID to identify the registered message (use registerMessageDefinition first).
containerSource. This instance must be created using deserializeIntoFlatContainer.
renamed_valueDestination.

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.

Parameters
msg_identifierString ID to identify the registered message (use registerMessageDefinition first).
monitored_typeROSType that triggers the invokation to the callback
bufferOriginal buffer, passed as mutable since it might be modified.
callbackThe callback.

Definition at line 257 of file ros_introspection.cpp.

void RosIntrospection::Parser::createTrees ( ROSMessageInfo info,
const std::string &  type_name 
) const
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.

Parameters
msg_identifierString ID to identify the registered message (use registerMessageDefinition first).
bufferraw memory to be parsed.
flat_container_outputoutput 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_sizeUsually 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.

template<typename T >
T RosIntrospection::Parser::extractField ( const std::string &  msg_identifier,
const absl::Span< uint8_t > &  buffer 
)
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.

Parameters
typeROSType to be found
infoInstance or ROSMessageInfo that shall contain the ROSType to be found.
Returns
Pointer to the instance or nullptr if not registered.

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.

Parameters
msg_identifierString ID to identify the registered message (use registerMessageDefinition first).
Returns
Pointer to the instance or nullptr if not registered.

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.

Parameters
msg_identifiername to give to the main type to be extracted.
msg_definitiontext 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.

Parameters
typeThe type which must be renamed
rulesA list of rules to apply to the type.

Definition at line 136 of file ros_introspection.cpp.

void RosIntrospection::Parser::setMaxArrayPolicy ( bool  discard_entire_array)
inline

Definition at line 72 of file ros_introspection.hpp.

void RosIntrospection::Parser::setWarningsStream ( std::ostream *  output)
inline

Change where the warning messages are displayed.

Definition at line 195 of file ros_introspection.hpp.

void RosIntrospection::Parser::updateRuleCache ( )
private

Definition at line 149 of file ros_introspection.cpp.

Member Data Documentation

std::vector<int> RosIntrospection::Parser::_alias_array_pos
private

Definition at line 222 of file ros_introspection.hpp.

bool RosIntrospection::Parser::_discard_large_array
private

Definition at line 225 of file ros_introspection.hpp.

std::vector<std::string> RosIntrospection::Parser::_formatted_string
private

Definition at line 223 of file ros_introspection.hpp.

std::ostream* RosIntrospection::Parser::_global_warnings
private

Definition at line 220 of file ros_introspection.hpp.

std::unordered_map<std::string, ROSMessageInfo> RosIntrospection::Parser::_registered_messages
private

Definition at line 210 of file ros_introspection.hpp.

std::unordered_map<ROSType, std::unordered_set<SubstitutionRule> > RosIntrospection::Parser::_registered_rules
private

Definition at line 211 of file ros_introspection.hpp.

bool RosIntrospection::Parser::_rule_cache_dirty
private

Definition at line 216 of file ros_introspection.hpp.

std::unordered_map<std::string, std::vector<RulesCache> > RosIntrospection::Parser::_rule_caches
private

Definition at line 212 of file ros_introspection.hpp.

std::vector<int8_t> RosIntrospection::Parser::_substituted
private

Definition at line 224 of file ros_introspection.hpp.


The documentation for this class was generated from the following files:


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Thu May 16 2019 02:39:10