Skip to content

Write and read msgpack in Rust - #25

Merged
nickyoung-github merged 2 commits into
masterfrom
feature/rust-msgpack
Nov 29, 2026
Merged

nickyoung-github merged 2 commits into
masterfrom
feature/rust-msgpack

Conversation

@nickyoung-github

Copy link
Copy Markdown
Owner

Stacked on #24 (the descriptors): until that is merged, this shows its commit too.

The generated structs are written as msgpack, and read from it, by Rust itself: as WIRE_FORMAT.md has it, which Python and C++ write and read.

  • dataclass_native::msgpack::{to_msgpack, from_msgpack}, in the crate, which still depends on nothing: so by Rust alone, with no Python.
  • dataclass-native generate rust implements its Wire for each struct, enum and union, and says of each whether it is written as a bundle, which the schema tells.
  • The classes of an extension have __msgpack__ and __from_msgpack__, as those of C++ have, so to_msgpack and from_msgpack of what is bound to Rust no longer go by way of Python.
  • Decimal::parse, as C++ has.

On an Apple M1, of extensions built for release, in microseconds for each Order of the README's Performance section:

pure C++ Rust, before Rust, now
Write msgpack 8.8 2.0 15.0 1.8
Read msgpack 24.2 2.6 31.1 2.7

Tested by the tests of msgpack which are for every mode, run with the extension, including those of data which is rejected; and by a program of Rust alone, which cargo runs. Also checked, though not kept as a test: of 22 objects of most kinds of field, Rust writes the bytes which the Python reference does; and of some 8,800 corruptions of them, Rust and C++ each took or rejected the same, and wrote the same of what they took.

JSON and Arrow are still done by Python for what Rust holds, and are to follow.

@nickyoung-github
nickyoung-github merged commit 1cb29c1 into master Nov 29, 2026
6 checks passed
@nickyoung-github
nickyoung-github deleted the feature/rust-msgpack branch November 29, 2026 21:05
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