1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Send protobuf

This commit is contained in:
Ryan Dahl 2018-05-14 00:31:48 -04:00
parent 4db5a80ba3
commit 1ad8a2e088
4 changed files with 43 additions and 12 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ node_modules/
dist/
deno
assets.go
msg.pb.go

36
main.go
View file

@ -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)
}
}

View file

@ -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
msg.proto Normal file
View file

@ -0,0 +1,13 @@
syntax = "proto3";
package main;
message Msg {
enum MsgKind {
LOAD = 0;
}
MsgKind kind = 10;
// LOAD
repeated string argv = 11;
}