jhelovuo / RustDDS

Rust implementation of Data Distribution Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access SampleInfo from async reader interface

samcarey opened this issue · comments

Using the async interface, as in the examples:

let mut datareader_stream = reader.async_sample_stream();

This stream produces samples with no metadata (SampleInfo) using the take_bare method internally instead of take.
Is there a way to access the SampleInfo using the async interface, or do I need to resort to synchronously calling take on the reader directly?

Is there a reason that the async interface currently strips the metadata? Performance I'm guessing?
It seems like a more versatile interface would expose the metadata and let the user choose to ignore it.
Or perhaps two interfaces could exist, one that provides metadata and one that doesn't?

This stream produces samples with no metadata (SampleInfo) using the take_bare method internally instead of take.
Is there a way to access the SampleInfo using the async interface, or do I need to resort to synchronously calling take on the reader directly?

No. You need to use the synchronous API.

Is there a reason that the async interface currently strips the metadata? Performance I'm guessing?

Performance and lazy development. You are the first one to come up with a use case of async + metadata.

Our main use case is ROS 2, and that does not use the metadata at all.

Performancewise, a full DataReader (as opposed to SimpleDataReader) needs to maintain a DataSampleCache to generate the various metadata items, and that requires some memory + CPU, even if no-one ever uses the metadata.

It seems like a more versatile interface would expose the metadata and let the user choose to ignore it.
Or perhaps two interfaces could exist, one that provides metadata and one that doesn't?

The correct solution here would be to provide an alternative interface. If you want to try to implement that, then that should be reasonably straightforward. I would start from making a copy of the current async machinery for the DataReader and just replacing its SimpleDataReader with a full version, and using .take() instead of .take_bare() and seeing how far that would get me. Please make a PR if you choose to try.