Skip to content

Add dynamic message functionality #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Add dynamic message functionality #262

wants to merge 1 commit into from

Conversation

nnmm
Copy link
Contributor

@nnmm nnmm commented Sep 18, 2022

This is an overview PR to see the changes at a high level. I recommend you check out this branch and run cargo doc to see what the API looks like. For the review, it will be split into smaller parts.

What are dynamic messages?

Dynamic messages are messages whose type is only known at runtime. You create dynamic messages by specifying the type as a string, e.g. "geometry_msgs/msg/Twist". The dynamic message module then looks for a shared introspection type support library, loads it, and parses the structure of the C message struct from it. That structure contains information about what fields the message contains and what their types are, e.g. field 'angular' of type 'Vector3' at offset 24. Using the structure, the dynamic message module can then read out the value of each field, and even modify it. Basically, it allows accessing the fields of the message as a HashMap from string to a value like this:

enum Value<'msg> {
  Float(&'msg f32),
  Double(&'msg f64),
  ...
  FloatArray(&'msg [f32]),
  ...
  FloatSequence(&'msg Sequence<f32>),
  ...
  FloatBoundedSequence(DynamicBoundedSequence<'msg, f32>)
  ..
}

This is useful for writing generic tools such as introspection tools, bridges to other communication systems, or nodes that manipulate messages à la topic_tools.

In C++, a similar thing exists in https://github.com/osrf/dynamic_message_introspection and https://github.com/facontidavide/ros2_introspection.

Features:

  • Subscription and publisher for dynamic messages
  • Conversion between statically typed and dynamically typed messages
  • Safe access of fields – no unsafe required in user code

Non-features:

  • Dynamic services and clients
  • Serde impls for the dynamic type (requires compiling the Rust message package into a dynamic library)

Notes

  • The entire dynamic_message module is behind a feature flag that will be disabled by default. Thus, there is no impact on compile times for the majority of users who do not need this.
  • I still need to finish writing some more tests

Future work:

  • Factor out the common parts of Subscription and DynamicSubscription (and the same for publishers) – this can also help compilation times by monomorphizing Subscription.

@nnmm nnmm marked this pull request as draft September 18, 2022 13:26
@nnmm nnmm force-pushed the dynamic_messages branch 8 times, most recently from 977259a to 3758627 Compare September 21, 2022 13:29
@nnmm
Copy link
Contributor Author

nnmm commented Sep 21, 2022

@eduidl, you might be interested in this, since I know you wrote a client library for Rust as well as a command-line tool that uses message introspection :)

@nnmm nnmm force-pushed the dynamic_messages branch 7 times, most recently from f3817fe to 6b3e10f Compare October 11, 2022 11:59
@nnmm nnmm force-pushed the dynamic_messages branch 2 times, most recently from b5a8f6d to 1ab566e Compare October 28, 2022 16:22
@nnmm nnmm force-pushed the dynamic_messages branch from 1ab566e to 2936a40 Compare November 3, 2022 13:35
@esteve
Copy link
Collaborator

esteve commented Jan 9, 2024

@nnmm thanks for all the work, it's unfortunate we couldn't merge all the related PRs earlier, but if you ever come back to ros2-rust, we'd happy to review any future work. I'm closing this PR, but feel free to reopen it 🙂

@esteve esteve closed this Jan 9, 2024
@esteve esteve deleted the dynamic_messages branch August 29, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants