anvilistas / anvil-labs

MIT License
9 stars 3 forks source link

serialize mechanism #60

Closed s-cork closed 2 years ago

s-cork commented 2 years ago

Somewhat brain dump for later

inspired by this post: https://anvil.works/forum/t/make-portable-objects-saveable/12348

Anvil has the architecture but it's not exposed We could hook into portable classes to take advantage of the mechanism and do our own version While we're here we could also add support for serialization of builtins

Builtins We might need to override the anvil.server.call() function so that args and kw builtins get converted before being sent over RPC We might also need to do something with the anvil.server.callable to make sure the return value also converts the builtins correctly This might be outside the scope of this PR But it would be nice to fix the problem of:

We might want to add a config option here And we would definitely want to avoid doing this type of overriding with anvil.private function names

serialization Essentially arbitrary portable classes could be serialized to and from JSON We would need portable classes to be registered with the module with a decorator Or we could do another override of the builtin portable_class decorator to register the portable class with us before passing it back to anvil.server.portable_class

We might need to wrap the __serialize__ and __derserialize__/__new_deserialized__ to do a pre-serialization/pre-deserialization. We probably wouldn't be able to handle media objects or Table Rows. We could also just add a functions that you could call inside your __serialize__, __deserialize__.

We could also create a from_json and to_json method.