ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm trying to publish in a topic a dictionary with other dictionary inside

As there are no direct dictionaries available in the message format, you have these options:

  • serialize the dictionary (as suggested in the other answer) and write it into a string variable (or uint8[] if it's a binary blob).
  • Flatten the dictionary to non-nested key-value pairs (d["key1"]["key2"]["key3"] turns to "key1.key2.key3"). Then you can use something like diagnostic_msgs/KeyValue[] to hold your data.
  • If you have one level of nesting, you can create a custom KeyDictValue message, in which you store the KeyValue[] "dictionaries" for each "top level" key.

I'm trying to publish in a topic a dictionary with other dictionary inside

As there are no direct dictionaries available in the message format, you have these options:

  • serialize the dictionary (as suggested in the other answer) and write it into a string variable (or uint8[] if it's a binary blob).
  • Flatten the dictionary to non-nested key-value pairs (d["key1"]["key2"]["key3"]{"key1": {"key2": {"key3": "value"}}} turns to "key1.key2.key3"[("key1.key2.key3": "value")]). Then you can use something like diagnostic_msgs/KeyValue[] to hold your data.
  • If you have one level of nesting, you can create a custom KeyDictValue message, in which you store the KeyValue[] "dictionaries" for each "top level" key.