jhelovuo / ros2-client

ROS2 client library based on RustDDS
66 stars 14 forks source link

Stateful deserialization of Service::Response #29

Open rlidwka opened 2 months ago

rlidwka commented 2 months ago

This PR added stateful deserialization for subscriptions: https://github.com/jhelovuo/ros2-client/pull/20

I'm doing services and actions with dynamic data, such that exact type is not yet known at compile time (it's user-defined in configuration).

Would be very nice to have the same thing for services and actions. I'd like to have Service::async_receive_response_seed function at least to go along with Service::async_receive_response.

Any pointers? If I were to implement it, where should I start?

jhelovuo commented 3 weeks ago

This advice is a bit delayed, but here goes.

I'll discuss just Client below. Server is quite accurately a mirror image of Client, so required work is very similar.

A Service Client contains the field response_receiver, which should be modified to allow for seedful deserialization.

The outermost DataWriterR already supports this, but ResponseWrapper does not. It uses deserialize_from_cdr_with_rep_id, which needs to be replaced with the seedful version deserialize_from_cdr_with_decoder_and_rep_id, and the required decoder parameter passed down the stack from the new Service::async_receive_response_seed function.

Implementing this does require studying and understanding the wrappers used to implement various ServiceMappings, which is non-trivial. Otherwise, this basic idea of this generalization should be quite straightforward.