35 #ifndef ROS_INTROSPECTION_HPP 36 #define ROS_INTROSPECTION_HPP 38 #include <unordered_set> 52 std::vector< std::pair<StringTreeLeaf, Variant> >
value;
56 std::vector< std::pair<StringTreeLeaf, std::string> >
name;
61 std::vector< std::pair<StringTreeLeaf, Span<uint8_t>>>
blob;
72 _global_warnings(&
std::cerr),
73 _discard_large_array(DISCARD_LARGE_ARRAYS),
74 _blob_policy(STORE_BLOB_AS_COPY)
78 DISCARD_LARGE_ARRAYS =
true,
79 KEEP_LARGE_ARRAYS =
false 84 _discard_large_array = discard_entire_array;
89 _discard_large_array =
static_cast<MaxArrayPolicy>(discard_entire_array);
94 return _discard_large_array;
99 STORE_BLOB_AS_REFERENCE};
107 _blob_policy = policy;
128 void registerMessageDefinition(
const std::string& message_identifier,
138 void registerRenamingRules(
const ROSType& type,
139 const std::vector<SubstitutionRule> &rules );
147 const ROSMessageInfo* getMessageInfo(
const std::string& msg_identifier)
const;
181 bool deserializeIntoFlatContainer(
const std::string& msg_identifier,
184 const uint32_t max_array_size )
const;
206 void applyNameTransform(
const std::string& msg_identifier,
208 RenamedValues* renamed_value ,
bool dont_add_topicname =
false);
224 void applyVisitorToBuffer(
const std::string& msg_identifier,
const ROSType &monitored_type,
228 template <
typename T>
229 T extractField(
const std::string& msg_identifier,
const Span<uint8_t> &buffer);
240 rule( &r ), pattern_head(nullptr), alias_head(nullptr)
252 void updateRuleCache();
256 void createTrees(
ROSMessageInfo &info,
const std::string &type_name)
const;
269 template<
typename T>
inline 277 if( msg_info ==
nullptr)
279 throw std::runtime_error(
"extractField: msg_identifier not registered. Use registerMessageDefinition" );
284 if( getMessageByType( monitored_type, *msg_info) ==
nullptr)
286 throw std::runtime_error(
"extractField: message type doesn't contain this field type" );
289 std::function<void(const MessageTreeNode*)> recursiveImpl;
290 size_t buffer_offset = 0;
296 const ROSMessage* msg_definition = msg_node->value();
301 if( msg_type == monitored_type )
304 buffer.size() - buffer_offset );
312 if(field.isConstant() )
continue;
316 int32_t array_size = field.arraySize();
317 if( array_size == -1)
322 if( field_type.
isBuiltin() && field_type != monitored_type )
327 buffer_offset += field_type.
typeSize() * array_size;
335 for (
int i=0; i<array_size; i++ )
337 recursiveImpl( msg_node->child(index_m) );
356 #endif // ROS_INTROSPECTION_HPP std::ostream * _global_warnings
std::vector< std::string > _formatted_string
std::vector< std::pair< StringTreeLeaf, std::string > > name
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
Variant ReadFromBufferToVariant(const Span< uint8_t > &buffer, size_t &offset)
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.
std::unordered_map< std::string, std::vector< RulesCache > > _rule_caches
const TreeNode< T > * croot() const
Constant pointer to the root of the tree.
void setBlobPolicy(BlobPolicy policy)
std::vector< std::vector< uint8_t > > blob_storage
void setMaxArrayPolicy(bool discard_entire_array)
T extractField(const std::string &msg_identifier, const Span< uint8_t > &buffer)
std::unordered_map< ROSType, std::unordered_set< SubstitutionRule > > _registered_rules
std::unordered_map< std::string, ROSMessageInfo > _registered_messages
const SubstitutionRule * rule
MaxArrayPolicy _discard_large_array
std::vector< std::pair< StringTreeLeaf, Variant > > value
std::vector< int8_t > _substituted
const StringTreeNode * pattern_head
const ROSType & type() const
MaxArrayPolicy maxArrayPolicy() const
const StringTreeNode * alias_head
std::vector< std::pair< std::string, Variant > > RenamedValues
std::vector< std::pair< StringTreeLeaf, Span< uint8_t > > > blob
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.
std::function< void(const ROSType &, Span< uint8_t > &)> VisitingCallback
BlobPolicy blobPolicy() const
void setMaxArrayPolicy(MaxArrayPolicy discard_entire_array)
RulesCache(const SubstitutionRule &r)
void ReadFromBuffer(const Span< uint8_t > &buffer, size_t &offset, T &destination)