Files
wazero/internal/testing/binaryencoding/function.go
Edoardo Vacchi 117474c477 refactor binary encoding to its own package (#1187)
move binary encoder to its own package

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-03 07:21:22 +08:00

16 lines
670 B
Go

package binaryencoding
import (
"github.com/tetratelabs/wazero/internal/wasm"
)
// EncodeFunctionType returns the wasm.FunctionType encoded in WebAssembly 1.0 (20191205) Binary Format.
//
// Note: Function types are encoded by the byte 0x60 followed by the respective vectors of parameter and result types.
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#function-types%E2%91%A4
func EncodeFunctionType(t *wasm.FunctionType) []byte {
// Only reached when "multi-value" is enabled because WebAssembly 1.0 (20191205) supports at most 1 result.
data := append([]byte{0x60}, EncodeValTypes(t.Params)...)
return append(data, EncodeValTypes(t.Results)...)
}