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

MsgPack Support #28

Open
dOrgJelli opened this issue Feb 4, 2022 · 3 comments
Open

MsgPack Support #28

dOrgJelli opened this issue Feb 4, 2022 · 3 comments

Comments

@dOrgJelli
Copy link

dOrgJelli commented Feb 4, 2022

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.

Reference MsgPack Implementation

https://github.com/polywrap/monorepo/tree/prealpha/packages/wasm/as/assembly/msgpack

@dOrgJelli
Copy link
Author

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

@gagdiez
Copy link
Owner

gagdiez commented Feb 4, 2022

Started a new branch: https://github.com/gagdiez/serial-as/tree/feat-msgpack

I am sure that with your help we will be able to tackle this promptly.

@JairusSW
Copy link

JairusSW commented Feb 3, 2023

@gagdiez, MessagePack is already implemented 😄
https://github.com/wapc/as-msgpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants