From 1ad8a2e0881751e7ca642a6dde503dd7b7c3604f Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 14 May 2018 00:31:48 -0400 Subject: [PATCH] Send protobuf --- .gitignore | 1 + main.go | 36 +++++++++++++++++++++++++----------- main.ts | 5 ++++- msg.proto | 13 +++++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 msg.proto diff --git a/.gitignore b/.gitignore index e626c7486c..165a7f9ae6 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 23db83f9ab..fc69fee599 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) - - worker := v8worker2.New(recv) - - // Load up index.js code. - err = worker.Load(indexFn, code) + err = w.Load(path, string(data)) if err != nil { - println("Problem executing Javascript.") panic(err) } } + +func main() { + worker := v8worker2.New(recv) + loadAsset(worker, "dist/main.js") + + loadMsg := &Msg{ + Kind: Msg_LOAD, + Argv: os.Args, + } + out, err := proto.Marshal(loadMsg) + if err != nil { + panic(err) + } + err = worker.SendBytes(out) + if err != nil { + panic(err) + } + +} diff --git a/main.ts b/main.ts index 3c107eca07..38044b3d82 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 0000000000..d76875e130 --- /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; +}