35 #ifndef ROS_INTROSPECTION_HPP 36 #define ROS_INTROSPECTION_HPP 38 #include <unordered_set> 53 std::vector< std::pair<StringTreeLeaf, Variant> >
value;
57 std::vector< std::pair<StringTreeLeaf, std::string> >
name;
62 std::vector< std::pair<StringTreeLeaf, std::vector<uint8_t>>>
blob;
70 Parser(): _rule_cache_dirty(true), _global_warnings(&
std::cerr), _discard_large_array(true) {}
74 _discard_large_array = discard_entire_array;
90 void registerMessageDefinition(
const std::string& message_identifier,
100 void registerRenamingRules(
const ROSType& type,
101 const std::vector<SubstitutionRule> &rules );
109 const ROSMessageInfo* getMessageInfo(
const std::string& msg_identifier)
const;
143 bool deserializeIntoFlatContainer(
const std::string& msg_identifier,
146 const uint32_t max_array_size )
const;
168 void applyNameTransform(
const std::string& msg_identifier,
170 RenamedValues* renamed_value );
186 void applyVisitorToBuffer(
const std::string& msg_identifier,
const ROSType &monitored_type,
190 template <
typename T>
202 rule( &r ), pattern_head(nullptr), alias_head(nullptr)
214 void updateRuleCache();
218 void createTrees(
ROSMessageInfo &info,
const std::string &type_name)
const;
230 template<
typename T>
inline 238 if( msg_info ==
nullptr)
240 throw std::runtime_error(
"extractField: msg_identifier not registered. Use registerMessageDefinition" );
245 if( getMessageByType( monitored_type, *msg_info) ==
nullptr)
247 throw std::runtime_error(
"extractField: message type doesn't contain this field type" );
250 std::function<void(const MessageTreeNode*)> recursiveImpl;
251 size_t buffer_offset = 0;
257 const ROSMessage* msg_definition = msg_node->value();
262 if( msg_type == monitored_type )
265 buffer.
size() - buffer_offset );
273 if(field.isConstant() )
continue;
277 int32_t array_size = field.arraySize();
278 if( array_size == -1)
283 if( field_type.
isBuiltin() && field_type != monitored_type )
288 buffer_offset += field_type.
typeSize() * array_size;
296 for (
int i=0;
i<array_size;
i++ )
298 recursiveImpl( msg_node->child(index_m) );
317 #endif // ROS_INTROSPECTION_HPP std::function< void(const ROSType &, absl::Span< uint8_t > &)> VisitingCallback
std::ostream * _global_warnings
std::vector< std::string > _formatted_string
std::vector< std::pair< StringTreeLeaf, std::string > > name
bool _discard_large_array
Variant ReadFromBufferToVariant(const absl::Span< uint8_t > &buffer, size_t &offset)
const std::vector< ROSField > & fields() const
Vector of fields.
const StringTree * tree
Tree that the StringTreeLeaf(s) refer to.
std::vector< int > _alias_array_pos
Element of the tree. it has a single parent and N >= 0 children.
int typeSize() const
If builtin, size of builtin, -1 means variable or undefined.
constexpr pointer data() const noexcept
std::unordered_map< std::string, std::vector< RulesCache > > _rule_caches
const TreeNode< T > * croot() const
Constant pointer to the root of the tree.
void setMaxArrayPolicy(bool discard_entire_array)
constexpr size_type size() const noexcept
std::unordered_map< ROSType, std::unordered_set< SubstitutionRule > > _registered_rules
std::unordered_map< std::string, ROSMessageInfo > _registered_messages
const SubstitutionRule * rule
std::vector< std::pair< StringTreeLeaf, Variant > > value
T extractField(const std::string &msg_identifier, const absl::Span< uint8_t > &buffer)
std::vector< int8_t > _substituted
void ReadFromBuffer(const absl::Span< uint8_t > &buffer, size_t &offset, T &destination)
const StringTreeNode * pattern_head
const ROSType & type() const
const StringTreeNode * alias_head
std::vector< std::pair< StringTreeLeaf, std::vector< uint8_t > > > blob
std::vector< std::pair< std::string, Variant > > RenamedValues
bool operator==(const RulesCache &other)
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
void setWarningsStream(std::ostream *output)
Change where the warning messages are displayed.
const char * definition()
void deserialize(Stream &stream, T &t)
BuiltinType typeID() const
If type is builtin, returns the id. BuiltinType::OTHER otherwise.
bool isBuiltin() const
True if the type is ROS builtin.
RulesCache(const SubstitutionRule &r)