jhelovuo / RustDDS

Rust implementation of Data Distribution Service
Apache License 2.0
331 stars 67 forks source link

DDS Generator #322

Open jalexcole opened 9 months ago

jalexcole commented 9 months ago

Is there going to be a DDSGen for this library that can read a idl, xml and produce a rust crate from it? If this would be included it looks like dust-dds has there own and that code might be able to be lifted in order to facilitate this. Workspaces should also likely be used.

https://github.com/s2e-systems/dust-dds

jhelovuo commented 9 months ago

Such a code generator is not on the roadmap, as you seem to be the first one to ask for it. So far most of our use cases have used fairly few and simple message types, so coding by hand has been easy enough.

However, the idea is good, and a generator should be fairly straightforward to implement. If you decide to do it, please submit a PR.

There is already a similar generator in ros2-client, but it uses ROS2 .msg definitions as source.

jalexcole commented 9 months ago

I can work on it. How does RustDDS handle sequences. For example http://community.rti.com/rti-doc/500/ndds/doc/html/api_cpp/group__DDSBuiltinSequenceModule.html

jhelovuo commented 9 months ago

CDR Sequence type maps to Vec in Rust. CDR Array maps to a fixed-length array in Rust. CDR String maps to Rust String, although this is slightly wrong. Rust Strings must be valid UTF-8, whereas CDR Strings may not be. This could be circumvented by mapping to e.g. Vec<u8> instead.

RustDDS does this via Serde , so the actual mapping is there. Please see the serialization module for details.

jalexcole commented 9 months ago

For sequences I am thinking of something like type BoundedSequence<T, const N: usize> = Vec<T>; This would allow for a Sequence<T> trait to be built and a BoundedSequence<T, N> struct made so that the std version can have a internal Vec, and the no:std version can have an internal array.

Regarding strings there is a FixedStr library that can be used, however something belonging to RustDDS may be preferred that can handle the u8's internally. https://docs.rs/fixedstr/0.5.5/fixedstr/index.html

The hard part in code generation would be handling Value type inheritance. This will likely have to be done with a proc macro.

This may be an ongoing discussion of how to implement idl features.