Since there is a rust library for serializing both Bincode and JSON, WASM can help. To get started we need to create a new library.

Generate a new library project

$ cargo new --lib bincode_parser
$ cd bincode_parser
Now that we have our project, we need to add some dependencies. Update the [dependencies] section of your Cargo.toml file to include these items. While we are at it lets make sure that the [lib] section has crate-type = ["cdylib"] listed in it. It also might be a good idea to set lto = true in the [profile.release] and [profile.dev] sections, this will help to reduce our final .wasm file size by removing any unused glue code automatically.

Cargo.toml

[package]
name = "bincode_parser"
version = "0.1.0"
authors = ["you"]

[lib]
crate-type = ["cdylib"]

[dependencies]
serde = "*"
serde_derive = "*"
serde_json = "*"
bincode = "1.0.0"
wasm-bindgen = "0.2"
wasm_tutorial_shared = { path = "../shared" }

[profile.release]
lto = true
[profile.dev]
lto = true

The main serialization library used in rust is called serde, short for serialize/deserialize. We also want to grab a special macro tied to that library called serde_derive. Serde doesn't implement any actual serialization or deserialization but creates a baseline for developers to create implementations, serde_json and bincode do just that. We don't want to forget wasm-bindgen and obviously the models that our server developer shared with us.

Let's see what these models look like.