Skip to content
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 into arbitrary Serializers #194

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

max-heller
Copy link
Contributor

Implements a postcard-dyn "reserializer" that deserializes postcard-serialized data and feeds it into an arbitrary Serializer in a streaming fashion (without needing to construct an intermediate representation in memory). I think this is (or could be) fully lossless. This means postcard -> serde_json::Value (or whatever generic representation postcard-dyn ends up providing), postcard -> json, and arbitrary other postcard -> X transformations can be performed by the same generic implementation.

A few implementation limitations:

  • Serialize methods require &'static strs for structs/variants/field names. To provide these, the current 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 a Serializeable postcard_dyn::Value.
  • This is implemented as a Serializeable struct that does the deserializing, which is the most straightforward way I found to implement the transformation. However, this means methods only receive &self, which necessitates use of RefCell for getting exclusive access to the Flavor.

@jamesmunns wanted to get your thoughts before I put more work into it. I think it's promising, but the first limitation is... rather limiting.

Copy link

netlify bot commented Dec 1, 2024

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
🔨 Latest commit 1fca580
🔍 Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/674bbd7594f8460008350465

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