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
First off, I really love this implementation, and how it leverages templates to automate code generation ❤️
For the Polywrap project (site, repo), we use MsgPack for encoding/decoding the data we send in & out of WebAssembly. MsgPack is most suitable to our use-case because of the following characteristics:
Efficient & compact
Built-in schema (similar to JSON), allowing us to generically read/write objects without assuming property ordering.
Currently we manually generate the (de)serialization logic for wasm module types in AssemblyScript (example type + (de)serialization logic).
If this library were to add support for generic MsgPack serialization, we could replace our manual code-gen with this compiler-driven meta-programming based approach.
Implementation Thoughts
After looking at both the JSON & Borsh implementations in this repo, I think MsgPack would look like a hybrid of both approaches.
Deserialization
Since we can't assume member order (like we can with Borsh), we must perform a middle-step (like in JSON) where we first parse the ArrayBuffer being provided. I'm not too sure what metadata this middle-step would store to aid in the final deserialization. Potentially it could store "buffer slice metadata" enabling the easy lookup of types + properties within the blob.
Serialization
This should be very straight forward, and not much different from Borsh's implementation if I'm not mistaken.
Additional difference I found in implementations: we made use of a Nullable<T> class to allow us to do things like value: Nullable<bool> since AssemblyScript does not support value: bool | null.
I opened up another issue here to add support for "nullable" scalar types: #29
First off, I really love this implementation, and how it leverages templates to automate code generation ❤️
For the Polywrap project (site, repo), we use MsgPack for encoding/decoding the data we send in & out of WebAssembly. MsgPack is most suitable to our use-case because of the following characteristics:
Currently we manually generate the (de)serialization logic for wasm module types in AssemblyScript (example type + (de)serialization logic).
If this library were to add support for generic MsgPack serialization, we could replace our manual code-gen with this compiler-driven meta-programming based approach.
Implementation Thoughts
After looking at both the JSON & Borsh implementations in this repo, I think MsgPack would look like a hybrid of both approaches.
Deserialization
Since we can't assume member order (like we can with Borsh), we must perform a middle-step (like in JSON) where we first parse the ArrayBuffer being provided. I'm not too sure what metadata this middle-step would store to aid in the final deserialization. Potentially it could store "buffer slice metadata" enabling the easy lookup of types + properties within the blob.
Serialization
This should be very straight forward, and not much different from Borsh's implementation if I'm not mistaken.
Reference MsgPack Implementation
https://github.com/polywrap/monorepo/tree/prealpha/packages/wasm/as/assembly/msgpack
The text was updated successfully, but these errors were encountered: