You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have ability to serialize and deserialize storages and pointers with serde. It can be useful in game when you want to save current CGS state. However, it's not easy as I thought before.
Basically, serde isn't a big problem, this test works well after a few lines added:
It's definitely safe to deserialize Storage and pointers. But there is one condition - you must not have any Storage in memory before deserializing.
Each Storage has unique identifier, that is used by pointers to link with specific storage. Identifier is controlled by static AtomicUsize. So, deserialized Storage uses "old" identifier, that isn't valid in the new program state. Pointers to deserialised Storage will be able to retrieve data from user's Storage and vise versa.
How to solve this challenge?
My idea is to provide procedural macro for user-defined structs.
Rough code:
#[derive(FroggySerialize)]structMyWorld{storage1:Storage<MyType>,storage2:Storage<MyAnotherType>,pointers:Vec<Pointer>,#[serde(skip)]// ability to use serde's attributesunnecessary_data:i32,necessary_user_data:MyAwesomeType,}
This macro will provide custom serde::Serialize and serde::Deserialize traits implementation.
Serializing
sync pending
serialize data (we don't even need meta, for example)
Deserializing
deserialize data
update all unique ids both in Storage and Pointer according to current program state
deserialize pointers and sync pending
The text was updated successfully, but these errors were encountered:
It would be nice to have ability to serialize and deserialize storages and pointers with
serde
. It can be useful in game when you want to save current CGS state. However, it's not easy as I thought before.Basically,
serde
isn't a big problem, this test works well after a few lines added:It's definitely safe to deserialize
Storage
and pointers. But there is one condition - you must not have anyStorage
in memory before deserializing.Each
Storage
has unique identifier, that is used by pointers to link with specific storage. Identifier is controlled by staticAtomicUsize
. So, deserializedStorage
uses "old" identifier, that isn't valid in the new program state. Pointers to deserialisedStorage
will be able to retrieve data from user'sStorage
and vise versa.How to solve this challenge?
My idea is to provide procedural macro for user-defined structs.
Rough code:
This macro will provide custom
serde::Serialize
andserde::Deserialize
traits implementation.meta
, for example)Storage
andPointer
according to current program stateThe text was updated successfully, but these errors were encountered: