Skip to content

refactor(msg): decouple serialization from ZMessage via ZSerdes<T> trait#131

Open
YuanYuYuan wants to merge 14 commits into
mainfrom
dev/serdes-param
Open

refactor(msg): decouple serialization from ZMessage via ZSerdes<T> trait#131
YuanYuYuan wants to merge 14 commits into
mainfrom
dev/serdes-param

Conversation

@YuanYuYuan
Copy link
Copy Markdown
Collaborator

Summary

Decouples serialization format from message type by replacing ZMessage::Serdes (an associated type) with a ZSerdes<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

  • ZMessage is now a plain marker trait with a blanket impl covering all Send + Sync + 'static types; no manual impl ZMessage needed
  • ZSerdes<T> trait replaces the old associated type — unit structs NativeCdrSerdes and SerdeCdrSerdes implement it for their respective bounds
  • ZPub<T, S = NativeCdrSerdes> / ZSub<T, Q, S = NativeCdrSerdes> — new S type 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 site
  • ZNode::create_pub_impl / create_sub_impl#[doc(hidden)] methods accepting explicit Option<TypeInfo> enable external ecosystems to bypass the WithTypeInfo requirement
  • roslibrust_ros2 integration simplifiedRosMessageWrapper and WrapperSerdes dropped; T: RosMessageType is now used directly with SerdeCdrSerdes via .with_serdes()
  • All internal call sites (action, dynamic, service, codegen, Python bindings, RMW) updated to fully-qualified ZSerdes syntax

Breaking Changes

Types that previously called impl ZMessage for MyType { type Serdes = ...; } must be updated:

  • Remove the impl ZMessage block entirely — it is now a blanket impl
  • Replace any .publish() / .recv() callers that relied on type Serdes with an explicit .with_serdes::<S>() on the builder if the type is not CdrSerialize + CdrDeserialize + CdrSerializedSize (i.e., serde-only types need .with_serdes::<SerdeCdrSerdes>())

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.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 9, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://ZettaScaleLabs.github.io/ros-z/pr-preview/pr-131/

Built to branch gh-pages at 2026-03-11 17:41 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

- 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
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant