feat(wacore-binary): zero-copy Serialize for NodeRef type family - #539
Conversation
…amily Add `serde::Serialize` implementations (behind `#[cfg(feature = "serde")]`) for all borrowed/ref types so that `OwnedNodeRef` can be serialized directly from the yoke buffer without cloning via `to_owned_node()`. Types covered: NodeStr, JidRef, ValueRef, NodeContentRef, NodeRef, OwnedNodeRef. All impls produce byte-identical output to their owned counterparts, verified by parity tests. Zero allocation during serialization.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@claude review |
|
Claude finished @jlucaso1's task in 2m 15s —— View job Code Review: Zero-copy Serialize for NodeRef type family
Overall: Looks good. Clean, well-tested PR. The impls correctly mirror the derive behavior of the owned types, and the test suite verifies JSON parity. A few observations below. CorrectnessThe manual
The zero-copy claim holds: Nit: Impl placement in
|
Benchmark Results59 unchanged benchmark(s)
|
- Wrap AttrsRef in newtype-struct serializer to match Attrs derive output for non-self-describing formats (bincode, postcard, etc.) - Move JidRef Serialize impl after the struct definition
Summary
serde::Serializeimpls (behind#[cfg(feature = "serde")]) for all borrowed/ref types:NodeStr,JidRef,ValueRef,NodeContentRef,NodeRef, andOwnedNodeRefDeref/AsRefto_owned_node()clones when serializingOwnedNodeRefMotivation
OwnedNodeRefexists to avoid cloning decoded nodes, but serialization previously requiredto_owned_node()which defeats the purpose. With these impls, consumers likewhatsapp-rust-bridgecan serialize directly from the yoke buffer:Test plan
cargo clippy --all --tests— cleancargo test -p wacore-binary --features serde -- serde_tests— 5 parity tests passnode_ref_serializes_same_as_node— attrs with String + Jid values, String contentnested_nodes_serialize_same— recursive Nodes contentbytes_content_serializes_same— Bytes contentvalue_ref_matches_node_value— both String and Jid variantsowned_node_ref_serializes_same_as_owned— full round-trip through marshal/unmarshalSummary by CodeRabbit
New Features
Tests