-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathgreet_plugin.pb.go
More file actions
109 lines (90 loc) · 2.43 KB
/
greet_plugin.pb.go
File metadata and controls
109 lines (90 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//go:build tinygo.wasm
// Code generated by protoc-gen-go-plugin. DO NOT EDIT.
// versions:
// protoc-gen-go-plugin v0.1.0
// protoc v3.21.1
// source: examples/host-functions/greeting/greet.proto
package greeting
import (
context "context"
emptypb "github.com/knqyf263/go-plugin/types/known/emptypb"
wasm "github.com/knqyf263/go-plugin/wasm"
_ "unsafe"
)
const GreeterPluginAPIVersion = 1
//export greeter_api_version
func _greeter_api_version() uint64 {
return GreeterPluginAPIVersion
}
var greeter Greeter
func RegisterGreeter(p Greeter) {
greeter = p
}
//export greeter_greet
func _greeter_greet(ptr, size uint32) uint64 {
b := wasm.PtrToByte(ptr, size)
req := new(GreetRequest)
if err := req.UnmarshalVT(b); err != nil {
return 0
}
response, err := greeter.Greet(context.Background(), req)
if err != nil {
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
return (uint64(ptr) << uint64(32)) | uint64(size) |
// Indicate that this is the error string by setting the 32-th bit, assuming that
// no data exceeds 31-bit size (2 GiB).
(1 << 31)
}
b, err = response.MarshalVT()
if err != nil {
return 0
}
ptr, size = wasm.ByteToPtr(b)
return (uint64(ptr) << uint64(32)) | uint64(size)
}
type hostFunctions struct{}
func NewHostFunctions() HostFunctions {
return hostFunctions{}
}
//go:wasm-module env
//export http_get
//go:linkname _http_get
func _http_get(ptr uint32, size uint32) uint64
func (h hostFunctions) HttpGet(ctx context.Context, request *HttpGetRequest) (*HttpGetResponse, error) {
buf, err := request.MarshalVT()
if err != nil {
return nil, err
}
ptr, size := wasm.ByteToPtr(buf)
ptrSize := _http_get(ptr, size)
wasm.FreePtr(ptr)
ptr = uint32(ptrSize >> 32)
size = uint32(ptrSize)
buf = wasm.PtrToByte(ptr, size)
response := new(HttpGetResponse)
if err = response.UnmarshalVT(buf); err != nil {
return nil, err
}
return response, nil
}
//go:wasm-module env
//export log
//go:linkname _log
func _log(ptr uint32, size uint32) uint64
func (h hostFunctions) Log(ctx context.Context, request *LogRequest) (*emptypb.Empty, error) {
buf, err := request.MarshalVT()
if err != nil {
return nil, err
}
ptr, size := wasm.ByteToPtr(buf)
ptrSize := _log(ptr, size)
wasm.FreePtr(ptr)
ptr = uint32(ptrSize >> 32)
size = uint32(ptrSize)
buf = wasm.PtrToByte(ptr, size)
response := new(emptypb.Empty)
if err = response.UnmarshalVT(buf); err != nil {
return nil, err
}
return response, nil
}