summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-22 14:10:13 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-22 14:10:15 -0400
commitd0a8bacab612ae2ecae3525fb7548f1c5e6ed35d (patch)
treef12982ff0bad14b32f12da0b1417a4111d2676ed
parent9ea397861feeefcce9f18947e10aa6cc155ec459 (diff)
Use proto2 instead of proto3
Travis doesn't support proto3.
-rw-r--r--dispatch.go6
-rw-r--r--main.go8
-rw-r--r--msg.proto46
-rw-r--r--os.go23
-rw-r--r--timers.go5
5 files changed, 46 insertions, 42 deletions
diff --git a/dispatch.go b/dispatch.go
index 9ac12d25c..09e5bad9f 100644
--- a/dispatch.go
+++ b/dispatch.go
@@ -23,9 +23,9 @@ func recv(buf []byte) (response []byte) {
msg := &BaseMsg{}
check(proto.Unmarshal(buf, msg))
assert(len(msg.Payload) > 0, "BaseMsg has empty payload.")
- subscribers, ok := channels[msg.Channel]
+ subscribers, ok := channels[*msg.Channel]
if !ok {
- panic("No subscribers for channel " + msg.Channel)
+ panic("No subscribers for channel " + *msg.Channel)
}
for i := 0; i < len(subscribers); i++ {
s := subscribers[i]
@@ -48,7 +48,7 @@ func Sub(channel string, cb Subscriber) {
func Pub(channel string, payload []byte) {
resChan <- &BaseMsg{
- Channel: channel,
+ Channel: &channel,
Payload: payload,
}
}
diff --git a/main.go b/main.go
index 8e01567cc..2c669e322 100644
--- a/main.go
+++ b/main.go
@@ -83,11 +83,11 @@ func main() {
out, err := proto.Marshal(&Msg{
Payload: &Msg_Start{
Start: &StartMsg{
- Cwd: cwd,
+ Cwd: &cwd,
Argv: args,
- DebugFlag: *flagDebug,
- MainJs: main_js,
- MainMap: main_map,
+ DebugFlag: flagDebug,
+ MainJs: &main_js,
+ MainMap: &main_map,
},
},
})
diff --git a/msg.proto b/msg.proto
index 3d90dc380..081b2df8c 100644
--- a/msg.proto
+++ b/msg.proto
@@ -1,13 +1,13 @@
-syntax = "proto3";
+syntax = "proto2";
package main;
message BaseMsg {
- string channel = 1;
- bytes payload = 2;
+ optional string channel = 1;
+ optional bytes payload = 2;
}
message Msg {
- string error = 1;
+ optional string error = 1;
oneof payload {
StartMsg start = 10;
SourceCodeFetchMsg source_code_fetch = 11;
@@ -20,43 +20,43 @@ message Msg {
}
message StartMsg {
- string cwd = 1;
+ optional string cwd = 1;
repeated string argv = 2;
- bool debug_flag = 3;
- string main_js = 4; // The contents of dist/main.js
- string main_map = 5; // The contents of dist/main.map
+ optional bool debug_flag = 3;
+ optional string main_js = 4; // The contents of dist/main.js
+ optional string main_map = 5; // The contents of dist/main.map
}
message SourceCodeFetchMsg {
- string module_specifier = 1;
- string containing_file = 2;
+ optional string module_specifier = 1;
+ optional string containing_file = 2;
}
message SourceCodeFetchResMsg {
// If it's a non-http module, moduleName and filename will be the same.
// For http modules, moduleName is its resolved http URL, and filename
// is the location of the locally downloaded source code.
- string moduleName = 1;
- string filename = 2;
- string source_code = 3;
- string output_code = 4; // Non-empty only if cached.
+ optional string moduleName = 1;
+ optional string filename = 2;
+ optional string source_code = 3;
+ optional string output_code = 4; // Non-empty only if cached.
}
message SourceCodeCacheMsg {
- string filename = 1;
- string source_code = 2;
- string output_code = 3;
+ optional string filename = 1;
+ optional string source_code = 2;
+ optional string output_code = 3;
}
-message ExitMsg { int32 code = 1; }
+message ExitMsg { optional int32 code = 1; }
message TimerStartMsg {
- int32 id = 1;
- bool interval = 2;
- int32 duration = 3; // In milliseconds.
+ optional int32 id = 1;
+ optional bool interval = 2;
+ optional int32 duration = 3; // In milliseconds.
}
message TimerReadyMsg {
- int32 id = 1;
- bool done = 2;
+ optional int32 id = 1;
+ optional bool done = 2;
}
diff --git a/os.go b/os.go
index 214492eea..59c24ccdf 100644
--- a/os.go
+++ b/os.go
@@ -16,14 +16,14 @@ func InitOS() {
switch msg.Payload.(type) {
case *Msg_Exit:
payload := msg.GetExit()
- os.Exit(int(payload.Code))
+ os.Exit(int(*payload.Code))
case *Msg_SourceCodeFetch:
payload := msg.GetSourceCodeFetch()
- return HandleSourceCodeFetch(payload.ModuleSpecifier, payload.ContainingFile)
+ return HandleSourceCodeFetch(*payload.ModuleSpecifier, *payload.ContainingFile)
case *Msg_SourceCodeCache:
payload := msg.GetSourceCodeCache()
- return HandleSourceCodeCache(payload.Filename, payload.SourceCode,
- payload.OutputCode)
+ return HandleSourceCodeCache(*payload.Filename, *payload.SourceCode,
+ *payload.OutputCode)
default:
panic("[os] Unexpected message " + string(buf))
}
@@ -39,7 +39,8 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
defer func() {
if err != nil {
- res.Error = err.Error()
+ var errStr = err.Error()
+ res.Error = &errStr
}
out, err = proto.Marshal(res)
check(err)
@@ -72,12 +73,13 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
return
}
+ var sourceCode = string(sourceCodeBuf)
res.Payload = &Msg_SourceCodeFetchRes{
SourceCodeFetchRes: &SourceCodeFetchResMsg{
- ModuleName: moduleName,
- Filename: filename,
- SourceCode: string(sourceCodeBuf),
- OutputCode: outputCode,
+ ModuleName: &moduleName,
+ Filename: &filename,
+ SourceCode: &sourceCode,
+ OutputCode: &outputCode,
},
}
return
@@ -91,7 +93,8 @@ func HandleSourceCodeCache(filename string, sourceCode string,
err := ioutil.WriteFile(fn, outputCodeBuf, 0600)
res := &Msg{}
if err != nil {
- res.Error = err.Error()
+ var errStr = err.Error()
+ res.Error = &errStr
}
out, err := proto.Marshal(res)
check(err)
diff --git a/timers.go b/timers.go
index 3a1efa103..f9fe28608 100644
--- a/timers.go
+++ b/timers.go
@@ -12,7 +12,8 @@ func InitTimers() {
switch msg.Payload.(type) {
case *Msg_TimerStart:
payload := msg.GetTimerStart()
- return HandleTimerStart(payload.Id, payload.Interval, payload.Duration)
+ return HandleTimerStart(*payload.Id, *payload.Interval,
+ *payload.Duration)
default:
panic("[timers] Unexpected message " + string(buf))
}
@@ -27,7 +28,7 @@ func HandleTimerStart(id int32, interval bool, duration int32) []byte {
payload, err := proto.Marshal(&Msg{
Payload: &Msg_TimerReady{
TimerReady: &TimerReadyMsg{
- Id: id,
+ Id: &id,
},
},
})