-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postcard-dyn: reserialize from arbitrary Deserializer into arbitrary Serializer #194
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for cute-starship-2d9c9b canceled.
|
8d762a5
to
1fca580
Compare
Ouch, yeah, that first limitiation. I don't really love that in the "always" case, do you think this would make sense as an alternate interface in this crate instead of replacing the existing machinery? |
Yes, probably, and it should be doable to provide both interfaces backed by a single implementation with a parameter selecting either "lossy, non-leaky transformation" or "lossless, leaky" transformation. However, what do we expect users to do with a |
One other option: we could expose an |
16455e4
to
e1400ba
Compare
Pushed an update that avoids leaking for the |
Some more context on the |
374cc4f
to
dd37309
Compare
dd37309
to
2f9fc3f
Compare
Implements a
postcard-dyn
"reserializer" that deserializes data from an arbitraryDeserializer
and feeds it into an arbitrarySerializer
in a streaming fashion (without needing to construct an intermediate representation in memory) based on a postcard schema. This meanspostcard -> serde_json::Value
(or whatever generic representationpostcard-dyn
ends up providing),postcard <-> json
, and arbitrary otherpostcard <-> X
transformations can be performed by the same generic implementation.Unfortunately,
Deserializer
andSerializer
methods require&'static str
s for structs/variants/field names. To provide these, the lossless implementation allocates and leaks one copy of each unique string that must be used as&'static
. I can't find a way around this that isn't lossy and this seems inevitable in order to provide aSerialize
ablepostcard_dyn::Value
. A separate, lossy transformation is also provided that does not leak memory but only supports json-like representations of structs/enums as maps.