Skip to content

Commit 65cfaea

Browse files
committed
[serde_multipart] new crate: multipart codec for serde
Serde codec for multipart messages. //! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted //! from the main payload and appended to a list of `parts`. Each part is backed by //! [`bytes::Bytes`] for cheap, zero-copy sharing. //! //! On decode, the body and its parts are reassembled into the original value //! without copying. //! //! The on-the-wire form is a [`Message`] (body + parts). Your transport sends //! and receives [`Message`]s; the codec reconstructs the value, enabling //! efficient network I/O without compacting data into a single buffer. //! //! Implementation note: this crate uses Rust's min_specialization feature to enable //! the use of [`Part`]s with any Serde serializer or deserializer. This feature //! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`] //! is not customizable. If customization is needed, you need to add specialization //! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`] //! for details. This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer. The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type). The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed. Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/) ghstack-source-id: 302490371 Pull Request resolved: #831
1 parent 83b35d8 commit 65cfaea

File tree

7 files changed

+1170
-0
lines changed

7 files changed

+1170
-0
lines changed

serde_multipart/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# @generated by autocargo from //monarch/serde_multipart:serde_multipart
2+
3+
[package]
4+
name = "serde_multipart"
5+
version = "0.0.0"
6+
authors = ["Facebook <[email protected]>"]
7+
edition = "2021"
8+
description = "multipart encoding for serde"
9+
repository = "https://github.com/pytorch-labs/monarch/"
10+
license = "BSD-3-Clause"
11+
12+
[dependencies]
13+
bincode = "1.3.3"
14+
bytes = { version = "1.10", features = ["serde"] }
15+
serde = { version = "1.0.219", features = ["derive", "rc"] }

serde_multipart/src/de.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod bincode;

0 commit comments

Comments
 (0)