Skip to content

refactor(tlv): decode and encode piece wire layouts with zerocopy structs - #119

Merged
gaius-qi merged 3 commits into
mainfrom
feature/zerocopy
Oct 15, 2026
Merged

gaius-qi merged 3 commits into
mainfrom
feature/zerocopy

Conversation

@gaius-qi

@gaius-qi gaius-qi commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Description

This pull request introduces significant updates to the Vortex protocol crate, focusing on clarifying and documenting the wire format, simplifying error handling, modernizing and expanding benchmarks, and making several project metadata improvements. The changes enhance the developer experience, ensure protocol interoperability, and streamline the codebase by removing unnecessary components.

Documentation and Protocol Clarification:

  • Expanded protocol documentation in docs/README.md to specify the exact wire format for all message types, including detailed tables for each packet value, field sizes, and semantics. Clarified that the wire format is stable and interoperable across releases, and updated behavioral descriptions for each tag.
  • Added a "Usage" section and a code example to README.md showing how to encode and decode messages using the crate, and clarified benchmarking instructions to match the new benchmark structure.

Benchmarking Overhaul:

  • Completely reworked benches/vortex.rs to benchmark encoding and decoding (including full packets) for all message types using a generic helper, replacing the previous approach that benchmarked only construction, serialization, and deserialization for a limited set of types.

Error Handling Simplification:

  • Simplified the Error type in src/error/mod.rs by removing unused variants and conversion errors, focusing on protocol-level errors only. Updated documentation for clarity.

Project Metadata Updates:

  • Updated Cargo.toml to bump the version to 0.2.0, set the minimum Rust version, update the repository URL, and add the zerocopy dependency for future extensibility.

Codebase Cleanup:

  • Removed the unused and redundant src/tlv/close.rs file, as the protocol now treats Close as an empty value with no special struct or logic required.

Performance

image image

Related Issue

Motivation and Context

Screenshots (if appropriate)

…ucts

Replace manual byte-slice parsing and assembly across the piece and
download request/response TLV types with fixed-layout zerocopy structs.
Fixed-size header fields are now read and written through typed wire
layouts, and decoding tolerates trailing bytes beyond the known layout
instead of rejecting the message. Adds the zerocopy dependency.

Signed-off-by: Gaius <gaius.qi@gmail.com>
… API

Introduce a `Message` trait with `encode`/`decode` and implement it for all
TLV packet types, replacing the ad-hoc `From<Bytes>`/`Into<Bytes>`
conversions. Piece metadata parsing is consolidated into a shared
`PieceMetadata` codec with strict length-prefixed decoding, and the
`Close` packet type is removed along with its module.

Also update tests, benches, and docs: drop the old proptest suite in favor
of wire-format and packet-stream integration tests, add proptest roundtrips
for encode/decode, add truncation checks for piece content decoding, and
document the wire format in the README.

Signed-off-by: Gaius <gaius.qi@gmail.com>
@gaius-qi gaius-qi self-assigned this Oct 15, 2026
@gaius-qi
gaius-qi requested review from a team as code owners October 15, 2026 03:30
@gaius-qi gaius-qi added the enhancement New feature or request label Oct 15, 2026
…eature/zerocopy

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@gaius-qi
gaius-qi enabled auto-merge (squash) October 15, 2026 03:48
@gaius-qi
gaius-qi merged commit 6dd0549 into main Oct 15, 2026
5 checks passed
@gaius-qi
gaius-qi deleted the feature/zerocopy branch October 15, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants