add plugins
All checks were successful
Build Multi-Platform Binaries / build (push) Successful in 11m9s
All checks were successful
Build Multi-Platform Binaries / build (push) Successful in 11m9s
This commit is contained in:
29
pkg/plugin/wasm/memory.go
Normal file
29
pkg/plugin/wasm/memory.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package wasm
|
||||
|
||||
import (
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
)
|
||||
|
||||
// ReadString 从 WASM 内存读取字符串
|
||||
func ReadString(mem api.Memory, ptr, len uint32) (string, bool) {
|
||||
data, ok := mem.Read(ptr, len)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return string(data), true
|
||||
}
|
||||
|
||||
// WriteString 向 WASM 内存写入字符串
|
||||
func WriteString(mem api.Memory, ptr uint32, s string) bool {
|
||||
return mem.Write(ptr, []byte(s))
|
||||
}
|
||||
|
||||
// ReadBytes 从 WASM 内存读取字节
|
||||
func ReadBytes(mem api.Memory, ptr, len uint32) ([]byte, bool) {
|
||||
return mem.Read(ptr, len)
|
||||
}
|
||||
|
||||
// WriteBytes 向 WASM 内存写入字节
|
||||
func WriteBytes(mem api.Memory, ptr uint32, data []byte) bool {
|
||||
return mem.Write(ptr, data)
|
||||
}
|
||||
Reference in New Issue
Block a user