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

feat(module) Support module serialization and deserialization #34

Merged
merged 5 commits into from
Jun 5, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Jun 5, 2019

Sequel of #27 and #33.
Ping #23.

Example:

	// Compiles the bytes into a WebAssembly module.
	module1, _ := wasm.Compile(GetBytes())
	defer module1.Close()

	// Serializes the module into a sequence of bytes.
	serialization, _ := module1.Serialize()

	// Do something with `serialization`.
	// Then later…

	// Deserializes the module.
	module2, _ := wasm.DeserializeModule(serialization)
	defer module2.Close()
	// And enjoy!

	// Instantiates the WebAssembly module.
	instance, _ := module2.Instantiate()
	defer instance.Close()

	// Gets an exported function.
	sum, functionExists := instance.Exports["sum"]

	fmt.Println(functionExists)

	// Calls the `sum` exported function with Go values.
	result, _ := sum(1, 2)

	fmt.Println(result)

	// Output:
	// true
	// 3

The final API is quite easy to use. I hope []byte is a generic enough type to be accepted by Go caching libraries.

@Hywan Hywan added 🎉 enhancement New feature or request 📦 component-extension About the Go extension 📚 documentation Do you like to read? 🧪 tests I love tests labels Jun 5, 2019
@Hywan Hywan self-assigned this Jun 5, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Jun 5, 2019

bors r+

bors bot added a commit that referenced this pull request Jun 5, 2019
34: feat(module) Support module serialization and deserialization r=Hywan a=Hywan

Sequel of #27 and #33.
Ping #23.

Example:

```go
	// Compiles the bytes into a WebAssembly module.
	module1, _ := wasm.Compile(GetBytes())
	defer module1.Close()

	// Serializes the module into a sequence of bytes.
	serialization, _ := module1.Serialize()

	// Do something with `serialization`.
	// Then later…

	// Deserializes the module.
	module2, _ := wasm.DeserializeModule(serialization)
	defer module2.Close()
	// And enjoy!

	// Instantiates the WebAssembly module.
	instance, _ := module2.Instantiate()
	defer instance.Close()

	// Gets an exported function.
	sum, functionExists := instance.Exports["sum"]

	fmt.Println(functionExists)

	// Calls the `sum` exported function with Go values.
	result, _ := sum(1, 2)

	fmt.Println(result)

	// Output:
	// true
	// 3
```

The final API is quite easy to use. I hope `[]byte` is a generic enough type to be accepted by Go caching libraries.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Jun 5, 2019

@bors bors bot merged commit a67a898 into wasmerio:master Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-extension About the Go extension 📚 documentation Do you like to read? 🎉 enhancement New feature or request 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant