Repository navigation
Object serialization API — what other msgpack libraries provide and what it could look like in Pony #59
SeanTAllen
started this conversation in
Research
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Current state
The library currently provides two levels of API:
uint_8,uint_32,fixstr,str_8,fixarray,array_16, etc. The caller chooses the exact wire format.uint,int,str,array,map,ext,timestamp. These auto-select the smallest wire format within a format family, but the caller still thinks in terms of msgpack types.Most other msgpack libraries provide a third level that we don't have yet.
What "high-level API" means in other libraries
The common pattern across languages: one call to serialize a native object into bytes, one call to deserialize bytes back. The user never thinks about msgpack format codes, array headers, or string length prefixes. The library maps language-native types to msgpack format families automatically.
Python (msgpack-python)
Python's dynamic typing makes this straightforward: dicts become maps, lists become arrays, strings/ints/floats/bools/None map directly.
Go (vmihailenco/msgpack)
Go uses runtime reflection plus struct tags to map struct fields to map keys. The
Marshal/Unmarshalinterface mirrorsencoding/json.Rust (rmp-serde)
Rust uses serde's derive macros to generate serialization code at compile time — no runtime reflection needed. Any type that implements
Serialize/Deserializeworks automatically.What this would look like in Pony
Pony has no runtime reflection. The two viable approaches are:
Approach 1: Trait-based
Define a trait that types implement to describe their serialization:
Usage would look something like:
This is verbose. Each type manually implements its serialization. It's roughly equivalent to manually implementing
serde::Serializein Rust without the derive macro — nobody does that by choice.Approach 2: Dynamic value type
Instead of serializing user types directly, provide a recursive value type that mirrors the msgpack data model:
With pack/unpack functions:
Users would build and destructure
MsgPackValuetrees. Simpler to implement than trait-based serialization, but the user has to convert between their types andMsgPackValuemanually.Discussion points
Is there demand? The compact methods cover the "don't make me think about format sizes" use case. Is "don't make me think about msgpack types at all" a real need for Pony users, or is the current level of abstraction sufficient?
Trait-based vs. value type? The trait approach is more type-safe but very verbose without macros. The value type approach is simpler to implement and use, but loses static typing.
Reference capabilities complicate deserialization. Constructing complex Pony objects from a byte stream requires careful capability management (
iso,val,ref). Serialization is easier (everything is readable). This asymmetry makes a general-purpose deserialization API harder to design in Pony than in most languages.Scope. A full object serialization layer is a significant undertaking. It could be a separate package that depends on this one, rather than being built into the core library.
All reactions