feat(cdr): direct CDR serialization with bulk-copy path for plain sequences - #125
Merged
Conversation
…ith bytemuck bulk-copy path Adds direct CDR serialization traits to ros-z-cdr, bypassing serde reflection: - CdrSerialize / CdrDeserialize / CdrSerializedSize traits in traits.rs - Bulk-copy path for bytemuck::Pod types (Vec<f32>, Vec<Pose>, etc.) - Codegen emits bytemuck Pod/Zeroable derives on plain structs and CDR trait impls for all generated message types - CdrSerializedSize enables pre-allocation without serializing
…internal types - Add NativeCdrSerdes<T> as default ZMessage::Serdes for CDR-capable types via blanket impl - Implement CdrSerialize/CdrDeserialize/CdrSerializedSize for all concrete action message types and type-description wire types (ZBuf, GoalId, GoalStatus, GoalInfo, Time, and 11 framework message structs) - Update Publisher/Subscriber builders to use T::Serdes instead of hardcoded SerdeCdrSerdes, preserving serde path for serde-only types - Fix ZBuf::cdr_serialize double-length-prefix bug - Rename FastCdrSerdes->NativeCdrSerdes and CdrSerdes->SerdeCdrSerdes to clarify which path goes through serde reflection vs direct trait dispatch
…of in generated code
…nd_return in generated code
…ead_pod_slice cast_slice requires the input slice to be memory-aligned to align_of::<T>(). Network buffers arriving from ROS2 are not guaranteed to be 8-byte aligned, causing bytemuck to panic when deserializing f64 arrays (e.g. Imu/Odometry covariance arrays). Switch to pod_collect_to_vec which handles misalignment by copying into a fresh aligned allocation. Also restore the SplitBuffer import in mod tests which was mistakenly removed (contiguous() is a method on the SplitBuffer trait, used in that module).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the serde-based CDR serialization path with direct trait dispatch for generated message types, eliminating serde reflection overhead. Plain struct sequences (e.g.
Vec<Pose>,Vec<f32>) now use bulkmemcpyinstead of element-by-element serialization. This PR is inspired by ros2/rosidl_typesupport_fastrtps#142.Key Changes
CdrSerialize,CdrDeserialize,CdrSerializedSize) inros-z-cdrfor direct CDR serialization without serdebytemuck::Podsequences —Vec<f32>,Vec<Pose>, etc. serialize/deserialize as a singlememcpybytemuck::Pod/Zeroablederives on plain structs and CDR trait impls for all generated message typesNativeCdrSerdes<T>blanket wires generated types to the fast path automatically; serde-only types fall back toSerdeCdrSerdes<T>ZBuf::cdr_serializebug fix — was writing the sequence length prefix twiceFastCdrSerdes→NativeCdrSerdesandCdrSerdes→SerdeCdrSerdesto clarify the two pathsBenchmark results (release build, x86_64)
Wire format is byte-identical between the two paths (verified by test).
Breaking Changes
CdrSerdesandFastCdrSerdesare renamed toSerdeCdrSerdesandNativeCdrSerdes. Any code referencing these types by name will need updating.