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

Serialize arrays and pointers #4824

Closed
wants to merge 2 commits into from

Conversation

marijnfs
Copy link
Contributor

I needed to serializer structs with arrays like:

struct Message {
username: u8[:0],
message: u8[],
};

The current serializer doesn't allow for such 'pointer' types, probably since you would need an allocator during deserialization.

I added a serialization_allocate that implements the serialization in a way that allows for this.
The deserializer takes an allocator and allocates memory as needed.

Marijn Stollenga added 2 commits March 26, 2020 23:16
…eserialization of structs with array types and pointers

Put logic in beginning of functions, not in struct unpacking
Fix test
@shawnl
Copy link
Contributor

shawnl commented Mar 27, 2020

Following pointers is not serialization. Look how cap'n'crunch (which uses structures with embedded relative pointers) does it.

@marijnfs
Copy link
Contributor Author

Following pointers is not serialization. Look how cap'n'crunch (which uses structures with embedded relative pointers) does it.

Yes following pointers can be dangerous so that could be an optional behaviour. The main goal though was the serialization of variable array types, which is the more common usage. They don't have the 'following pointer' issues.

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Mar 30, 2020
@andrewrk
Copy link
Member

Hi @marijnfs, thanks for the pull request, and apologies for taking so long to get to the review.

I think, in this case, I'm going to ask you to maintain this in your own project or in a separate repository based on the fact that it is mostly copy-pasted code with some modifications. I don't think that the std lib at version 1.0 will have a serialization/deserialization API. We have a lot of extra APIs in the std lib right now that will likely be extracted into separately maintained packages, but they remain in std for now because they provide extra test coverage as the language evolves. But since this is mostly copy-pasted code with some modifications, it introduces a lot of maintenance cost, with little code coverage benefits.

@andrewrk andrewrk closed this May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants