47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
|
|
//go:build wasip1
|
||
|
|
|
||
|
|
package rudder
|
||
|
|
|
||
|
|
import "unsafe"
|
||
|
|
|
||
|
|
//go:wasmimport rudder_v1 input_len
|
||
|
|
func importInputLength() uint32
|
||
|
|
|
||
|
|
//go:wasmimport rudder_v1 input
|
||
|
|
func importInput(pointer unsafe.Pointer)
|
||
|
|
|
||
|
|
//go:wasmimport rudder_v1 call
|
||
|
|
func importCall(pointer unsafe.Pointer, length uint32) uint32
|
||
|
|
|
||
|
|
//go:wasmimport rudder_v1 result
|
||
|
|
func importResult(pointer unsafe.Pointer)
|
||
|
|
|
||
|
|
//go:wasmimport rudder_v1 output
|
||
|
|
func importOutput(pointer unsafe.Pointer, length uint32)
|
||
|
|
|
||
|
|
//go:wasmexport handle
|
||
|
|
func handle() {
|
||
|
|
runHandle()
|
||
|
|
}
|
||
|
|
|
||
|
|
//go:wasmexport describe
|
||
|
|
func describe() {
|
||
|
|
runDescribe()
|
||
|
|
}
|
||
|
|
|
||
|
|
func readInput() []byte {
|
||
|
|
input := make([]byte, importInputLength())
|
||
|
|
importInput(unsafe.Pointer(unsafe.SliceData(input)))
|
||
|
|
return input
|
||
|
|
}
|
||
|
|
|
||
|
|
func hostCall(request []byte) []byte {
|
||
|
|
response := make([]byte, importCall(unsafe.Pointer(unsafe.SliceData(request)), uint32(len(request))))
|
||
|
|
importResult(unsafe.Pointer(unsafe.SliceData(response)))
|
||
|
|
return response
|
||
|
|
}
|
||
|
|
|
||
|
|
func writeOutput(body []byte) {
|
||
|
|
importOutput(unsafe.Pointer(unsafe.SliceData(body)), uint32(len(body)))
|
||
|
|
}
|