Skip to content

Commit

Permalink
Send protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed May 14, 2018
1 parent 4db5a80 commit 1ad8a2e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
dist/
deno
assets.go
msg.pb.go
30 changes: 22 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
// 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 {
println("recv cb", string(msg))
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)
}

}
5 changes: 4 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -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");
13 changes: 13 additions & 0 deletions msg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package main;


message Msg {
enum MsgKind {
LOAD = 0;
}
MsgKind kind = 10;

// LOAD
repeated string argv = 11;
}

0 comments on commit 1ad8a2e

Please sign in to comment.