Skip to content

Zero copy byte deserialization#6

Open
iblnkn wants to merge 2 commits intoAtostek:masterfrom
iblnkn:zero-copy-byte-deserialization
Open

Zero copy byte deserialization#6
iblnkn wants to merge 2 commits intoAtostek:masterfrom
iblnkn:zero-copy-byte-deserialization

Conversation

@iblnkn
Copy link
Copy Markdown

@iblnkn iblnkn commented Mar 25, 2026

We're using this crate to deserialize ROS2 sensor messages (images, point clouds) and needed efficient handling of large byte payloads.

Changes:

  1. Implements the bytes path correctly so byte payloads can be
    serialized and deserialized as contiguous blocks instead of
    one byte at a time through the seq path.

  2. Fixes the deserializer's lifetime constraints so borrowed slices
    can reference the input buffer directly, enabling zero-copy
    deserialization.

Added tests

  • Round-trip tests for owned bytes, empty bytes, borrowed bytes, and
    bytes embedded in a struct
  • Cross-path test: data serialized as Vec<u8> can be deserialized
    through the bytes path
  • Regression test confirming Vec<u8> without serde_bytes still works

@iblnkn
Copy link
Copy Markdown
Author

iblnkn commented Apr 21, 2026

@jhelovuo What do you think of this change?

@jhelovuo
Copy link
Copy Markdown
Member

This looks brilliant! Something I have been thinking in the past, but never got around to implement.

There is a problem that this is not a drop-in replacement suitable for RustDDS, because of different lifetime signatures. RustDDS is our motivation to have this package at all.

Do you have ideas how to make these compatible?

@jhelovuo jhelovuo self-assigned this Apr 27, 2026
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.

2 participants