Skip to content

Commit e0bb963

Browse files
committed
fix(ci): fix compile errors after ZSerdes refactor
- protobuf_demo: ProtobufSerdes is now a unit struct, remove type param - rmw-zenoh-rs/msg.rs: disambiguate Self::serialize with fully-qualified syntax - service.rs: make rmw_send_request generic over S: ZSerdes, add rmw_send_response for RMW path that bypasses serde bounds
1 parent 2bd99dd commit e0bb963

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

crates/rmw-zenoh-rs/src/msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl ZSerdes<RosMessage> for RosSerdes {
9595
}
9696

9797
fn serialize_with_hint(msg: &RosMessage, _capacity_hint: usize) -> zenoh_buffers::ZBuf {
98-
Self::serialize(msg)
98+
<RosSerdes as ZSerdes<RosMessage>>::serialize(msg)
9999
}
100100

101101
fn serialize_to_vec(msg: &RosMessage) -> Vec<u8> {

crates/rmw-zenoh-rs/src/service.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ impl ClientImpl {
6363
};
6464

6565
// Send the request with notification callback
66-
let _ = self.inner.rmw_send_request(&req, notify_callback)?;
66+
let _ = self
67+
.inner
68+
.rmw_send_request::<crate::msg::RosSerdes, _>(&req, notify_callback)?;
6769

6870
// Return the sequence number we tracked
6971
unsafe {
@@ -317,7 +319,10 @@ impl ServiceImpl {
317319
let resp = crate::msg::RosMessage::new(response, self.response_ts.response);
318320

319321
// Send response
320-
match self.inner.send_response(&resp, &key) {
322+
match self
323+
.inner
324+
.rmw_send_response::<crate::msg::RosSerdes>(&resp, &key)
325+
{
321326
Ok(_) => {
322327
tracing::debug!("[ServiceImpl::send_response] Response sent successfully");
323328
Ok(())

crates/ros-z/examples/protobuf_demo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn run_pubsub_demo(ctx: ZContext, max_count: Option<usize>) -> Result<()> {
3434
println!("--- Part 1: ROS geometry_msgs/Vector3 with Protobuf ---");
3535
let ros_pub = node
3636
.create_pub::<Vector3Proto>("/vector_proto")
37-
.with_serdes::<ProtobufSerdes<Vector3Proto>>()
37+
.with_serdes::<ProtobufSerdes>()
3838
.build()?;
3939

4040
println!("Publishing ROS Vector3 messages...\n");
@@ -55,7 +55,7 @@ pub fn run_pubsub_demo(ctx: ZContext, max_count: Option<usize>) -> Result<()> {
5555
println!("\n--- Part 2: Custom SensorData message (pure protobuf) ---");
5656
let custom_pub = node
5757
.create_pub::<SensorData>("/sensor_data")
58-
.with_serdes::<ProtobufSerdes<SensorData>>()
58+
.with_serdes::<ProtobufSerdes>()
5959
.build()?;
6060

6161
println!("Publishing custom SensorData messages...\n");
@@ -82,7 +82,7 @@ pub fn run_pubsub_demo(ctx: ZContext, max_count: Option<usize>) -> Result<()> {
8282
println!("\nKey points:");
8383
println!("1. ROS messages (Vector3Proto): Auto-generated from ros-z-msgs with MessageTypeInfo");
8484
println!("2. Custom messages (SensorData): Generated from your own .proto files");
85-
println!("3. Both use .with_serdes::<ProtobufSerdes<T>>() for protobuf serialization");
85+
println!("3. Both use .with_serdes::<ProtobufSerdes>() for protobuf serialization");
8686
println!("4. ros-z is transport-agnostic - works with ANY protobuf message!");
8787

8888
Ok(())

crates/ros-z/examples/protobuf_demo/src/types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/// Shared protobuf type definitions and trait implementations
2-
use ros_z::{
3-
MessageTypeInfo, ServiceTypeInfo, WithTypeInfo,
4-
entity::TypeHash,
5-
msg::{ProtobufSerdes, ZService},
6-
};
2+
use ros_z::{MessageTypeInfo, ServiceTypeInfo, WithTypeInfo, entity::TypeHash, msg::ZService};
73

84
// Include protobuf messages generated from sensor_data.proto
95
pub mod generated {

crates/ros-z/src/service.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,17 @@ where
274274
}
275275

276276
#[cfg(feature = "rmw")]
277-
pub fn rmw_send_request<F>(&self, msg: &T::Request, notify: F) -> Result<i64>
277+
pub fn rmw_send_request<S, F>(&self, msg: &T::Request, notify: F) -> Result<i64>
278278
where
279+
S: ZSerdes<T::Request>,
279280
F: Fn() + Send + Sync + 'static,
280-
T::Request: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static,
281281
{
282282
let tx = self.tx.clone();
283283
let attachment = self.new_attachment();
284284
let sn = attachment.sequence_number;
285285
self.inner
286286
.get()
287-
.payload(<CdrCompatSerdes as ZSerdes<T::Request>>::serialize(msg))
287+
.payload(<S as ZSerdes<T::Request>>::serialize(msg))
288288
.attachment(attachment)
289289
.callback(move |reply| {
290290
match reply.into_result() {
@@ -612,6 +612,32 @@ where
612612
}
613613
}
614614

615+
/// RMW-specific: send response using an explicit serializer type parameter.
616+
///
617+
/// Use this instead of [`send_response`](Self::send_response) when the response type does not
618+
/// implement `serde::Serialize` (e.g., `RosMessage` in the RMW crate, which is serialized via
619+
/// a C FFI path through `RosSerdes`).
620+
#[cfg(feature = "rmw")]
621+
pub fn rmw_send_response<S>(&mut self, msg: &T::Response, key: &QueryKey) -> Result<()>
622+
where
623+
S: ZSerdes<T::Response>,
624+
{
625+
match self.map.remove(key) {
626+
Some(query) => {
627+
let payload = <S as ZSerdes<T::Response>>::serialize(msg);
628+
let attachment = Attachment::new(key.sn, key.gid);
629+
query
630+
.reply(&self.key_expr, payload)
631+
.attachment(attachment)
632+
.wait()
633+
}
634+
None => {
635+
error!("[SRV] No query found for sn={}", key.sn);
636+
Err("Query map doesn't contain key".into())
637+
}
638+
}
639+
}
640+
615641
/// Awaits sending the response to a service request.
616642
///
617643
/// - `msg` is the response message to send.

0 commit comments

Comments
 (0)