refactor(msg): decouple serialization from ZMessage via ZSerdes<T> trait - #131
refactor(msg): decouple serialization from ZMessage via ZSerdes<T> trait#131YuanYuYuan wants to merge 14 commits into
Conversation
Replace the ZMessage::Serdes associated type with a ZSerdes<T> type parameter on ZPub/ZSub/ZClient/ZServer builders. This allows external message ecosystems (roslibrust) to use ros-z pub/sub directly without wrapper types, and enables future formats (FlatBuffers, Protobuf) at the call site rather than baked into the message type. - ZMessage becomes a plain Send+Sync+'static marker (no associated type) - NativeCdrSerdes/SerdeCdrSerdes become unit structs implementing ZSerdes<T> - ZPub/ZSub default to NativeCdrSerdes; builders expose .with_serdes::<S>() - All action, dynamic, and service call sites updated to explicit ZSerdes API - roslibrust_ros2: drops RosMessageWrapper and WrapperSerdes, uses SerdeCdrSerdes directly via create_pub_impl/create_sub_impl
After introducing the ZMessage blanket impl, all manual
'impl ZMessage for T {}' in examples, tests, and codegen templates
became orphan conflicts. Remove them.
Also add .with_serdes::<SerdeCdrSerdes>() at serde-only pub/sub call
sites (z_custom_message example, pubsub tests) where NativeCdrSerdes
cannot satisfy the ZSerdes<T> bound.
Remove misleading 'implement ZMessage' language from actions.md and protobuf_demo — users no longer write impl ZMessage, it's automatic.
|
- 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
…moving ZSerdes bound overlap
ros-z-py is not in default-members so cargo clippy/build silently skip it. Adding cargo check/clippy -p ros-z-py catches missing deps and type errors locally before they reach CI.
CdrSerdes implements ZSerdes<T> but not ZSerializer/ZDeserializer directly. The publish_serialized and recv_serialized paths don't need those bounds, so drop them from ZPubWrapper and ZSubWrapper struct/impl definitions. Also add explicit type annotation on zenoh::Error to fix E0282.
|
Closing: 83 commits behind The intent is still good and should be re-proposed once the re-entrancy family has landed: replace the Branch |
Summary
Decouples serialization format from message type by replacing
ZMessage::Serdes(an associated type) with aZSerdes<T>trait parameter on publishers, subscribers, and service builders. This enables any message ecosystem — including roslibrust — to plug in a custom wire format without wrapper boilerplate.Key Changes
ZMessageis now a plain marker trait with a blanket impl covering allSend + Sync + 'statictypes; no manualimpl ZMessageneededZSerdes<T>trait replaces the old associated type — unit structsNativeCdrSerdesandSerdeCdrSerdesimplement it for their respective boundsZPub<T, S = NativeCdrSerdes>/ZSub<T, Q, S = NativeCdrSerdes>— newStype parameter with default preserves all existing generated-message callers unchanged.with_serdes::<S>()method on all builders for overriding the wire format at the call siteZNode::create_pub_impl/create_sub_impl—#[doc(hidden)]methods accepting explicitOption<TypeInfo>enable external ecosystems to bypass theWithTypeInforequirementRosMessageWrapperandWrapperSerdesdropped;T: RosMessageTypeis now used directly withSerdeCdrSerdesvia.with_serdes()ZSerdessyntaxBreaking Changes
Types that previously called
impl ZMessage for MyType { type Serdes = ...; }must be updated:impl ZMessageblock entirely — it is now a blanket impl.publish()/.recv()callers that relied ontype Serdeswith an explicit.with_serdes::<S>()on the builder if the type is notCdrSerialize + CdrDeserialize + CdrSerializedSize(i.e., serde-only types need.with_serdes::<SerdeCdrSerdes>())