refactor!: Optimize serialization and make it compatible with more data formats #437
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My previous use of serde wasn't compatible with many data formats other than JSON, particularly those that serialize enum discriminants as integers rather than strings, and those that require the size of a map to be specified at the start of serialization.
To solve this, I've refactored the node structs internally. The dynamic properties are now stored in their own struct, and only that struct needs custom implementations of
Serialize
andDeserialize
.I also made serialization and deserialization more efficient by serializing the bitmasks for the actions and flags directly, rather than serializing the actions as a sequence and the flags as key/value pairs in the outer map.
The serialization to JSON, and similar formats, is now less human-friendly than it was. The dynamic properties are now stored in a sub-object inside the node object, and the actions and flags are now serialized as integers rather than something self-describing. But, in the real-world uses of serialization that are now important to us, like Newton, efficiency is more important than human readability. Newton will almost certainly switch from JSON to a binary format, like postcard or GVariant.