summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-14 00:31:48 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-14 00:31:48 -0400
commit1ad8a2e0881751e7ca642a6dde503dd7b7c3604f (patch)
tree110143a4f35556dcdf3befa8c648b79ea8c826de
parent4db5a80ba314e584adafd0b0ea1db05d70200f6a (diff)
Send protobuf
-rw-r--r--.gitignore1
-rw-r--r--main.go30
-rw-r--r--main.ts5
-rw-r--r--msg.proto13
4 files changed, 40 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index e626c7486..165a7f9ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ node_modules/
dist/
deno
assets.go
+msg.pb.go
diff --git a/main.go b/main.go
index 23db83f9a..fc69fee59 100644
--- a/main.go
+++ b/main.go
@@ -1,11 +1,13 @@
-// To test: make && ./out/render test_input.js
package main
+//go:generate protoc --go_out=. msg.proto
//go:generate ./node_modules/.bin/parcel build --out-dir=dist/ --no-minify main.ts
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go dist/
import (
+ "github.com/golang/protobuf/proto"
"github.com/ry/v8worker2"
+ "os"
)
func recv(msg []byte) []byte {
@@ -13,20 +15,32 @@ func recv(msg []byte) []byte {
return nil
}
-func main() {
- indexFn := "dist/main.js"
- data, err := Asset(indexFn)
+func loadAsset(w *v8worker2.Worker, path string) {
+ data, err := Asset(path)
if err != nil {
panic("asset not found")
}
- code := string(data)
+ err = w.Load(path, string(data))
+ if err != nil {
+ panic(err)
+ }
+}
+func main() {
worker := v8worker2.New(recv)
+ loadAsset(worker, "dist/main.js")
- // Load up index.js code.
- err = worker.Load(indexFn, code)
+ loadMsg := &Msg{
+ Kind: Msg_LOAD,
+ Argv: os.Args,
+ }
+ out, err := proto.Marshal(loadMsg)
if err != nil {
- println("Problem executing Javascript.")
panic(err)
}
+ err = worker.SendBytes(out)
+ if err != nil {
+ panic(err)
+ }
+
}
diff --git a/main.ts b/main.ts
index 3c107eca0..38044b3d8 100644
--- a/main.ts
+++ b/main.ts
@@ -1,4 +1,7 @@
import * as ts from "typescript";
+V8Worker2.recv((ab: ArrayBuffer) {
+ V8Worker2.print("Got array buffer", ab.byteLength);
+});
-V8Worker2.print("Hello World");
+V8Worker2.print("Hello");
diff --git a/msg.proto b/msg.proto
new file mode 100644
index 000000000..d76875e13
--- /dev/null
+++ b/msg.proto
@@ -0,0 +1,13 @@
+syntax = "proto3";
+package main;
+
+
+message Msg {
+ enum MsgKind {
+ LOAD = 0;
+ }
+ MsgKind kind = 10;
+
+ // LOAD
+ repeated string argv = 11;
+}