mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
Use proto2 instead of proto3
Travis doesn't support proto3.
This commit is contained in:
parent
9ea397861f
commit
d0a8bacab6
@ -23,9 +23,9 @@ func recv(buf []byte) (response []byte) {
|
|||||||
msg := &BaseMsg{}
|
msg := &BaseMsg{}
|
||||||
check(proto.Unmarshal(buf, msg))
|
check(proto.Unmarshal(buf, msg))
|
||||||
assert(len(msg.Payload) > 0, "BaseMsg has empty payload.")
|
assert(len(msg.Payload) > 0, "BaseMsg has empty payload.")
|
||||||
subscribers, ok := channels[msg.Channel]
|
subscribers, ok := channels[*msg.Channel]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("No subscribers for channel " + msg.Channel)
|
panic("No subscribers for channel " + *msg.Channel)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(subscribers); i++ {
|
for i := 0; i < len(subscribers); i++ {
|
||||||
s := subscribers[i]
|
s := subscribers[i]
|
||||||
@ -48,7 +48,7 @@ func Sub(channel string, cb Subscriber) {
|
|||||||
|
|
||||||
func Pub(channel string, payload []byte) {
|
func Pub(channel string, payload []byte) {
|
||||||
resChan <- &BaseMsg{
|
resChan <- &BaseMsg{
|
||||||
Channel: channel,
|
Channel: &channel,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
main.go
8
main.go
@ -83,11 +83,11 @@ func main() {
|
|||||||
out, err := proto.Marshal(&Msg{
|
out, err := proto.Marshal(&Msg{
|
||||||
Payload: &Msg_Start{
|
Payload: &Msg_Start{
|
||||||
Start: &StartMsg{
|
Start: &StartMsg{
|
||||||
Cwd: cwd,
|
Cwd: &cwd,
|
||||||
Argv: args,
|
Argv: args,
|
||||||
DebugFlag: *flagDebug,
|
DebugFlag: flagDebug,
|
||||||
MainJs: main_js,
|
MainJs: &main_js,
|
||||||
MainMap: main_map,
|
MainMap: &main_map,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
46
msg.proto
46
msg.proto
@ -1,13 +1,13 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto2";
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
message BaseMsg {
|
message BaseMsg {
|
||||||
string channel = 1;
|
optional string channel = 1;
|
||||||
bytes payload = 2;
|
optional bytes payload = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Msg {
|
message Msg {
|
||||||
string error = 1;
|
optional string error = 1;
|
||||||
oneof payload {
|
oneof payload {
|
||||||
StartMsg start = 10;
|
StartMsg start = 10;
|
||||||
SourceCodeFetchMsg source_code_fetch = 11;
|
SourceCodeFetchMsg source_code_fetch = 11;
|
||||||
@ -20,43 +20,43 @@ message Msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message StartMsg {
|
message StartMsg {
|
||||||
string cwd = 1;
|
optional string cwd = 1;
|
||||||
repeated string argv = 2;
|
repeated string argv = 2;
|
||||||
bool debug_flag = 3;
|
optional bool debug_flag = 3;
|
||||||
string main_js = 4; // The contents of dist/main.js
|
optional string main_js = 4; // The contents of dist/main.js
|
||||||
string main_map = 5; // The contents of dist/main.map
|
optional string main_map = 5; // The contents of dist/main.map
|
||||||
}
|
}
|
||||||
|
|
||||||
message SourceCodeFetchMsg {
|
message SourceCodeFetchMsg {
|
||||||
string module_specifier = 1;
|
optional string module_specifier = 1;
|
||||||
string containing_file = 2;
|
optional string containing_file = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SourceCodeFetchResMsg {
|
message SourceCodeFetchResMsg {
|
||||||
// If it's a non-http module, moduleName and filename will be the same.
|
// 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
|
// For http modules, moduleName is its resolved http URL, and filename
|
||||||
// is the location of the locally downloaded source code.
|
// is the location of the locally downloaded source code.
|
||||||
string moduleName = 1;
|
optional string moduleName = 1;
|
||||||
string filename = 2;
|
optional string filename = 2;
|
||||||
string source_code = 3;
|
optional string source_code = 3;
|
||||||
string output_code = 4; // Non-empty only if cached.
|
optional string output_code = 4; // Non-empty only if cached.
|
||||||
}
|
}
|
||||||
|
|
||||||
message SourceCodeCacheMsg {
|
message SourceCodeCacheMsg {
|
||||||
string filename = 1;
|
optional string filename = 1;
|
||||||
string source_code = 2;
|
optional string source_code = 2;
|
||||||
string output_code = 3;
|
optional string output_code = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ExitMsg { int32 code = 1; }
|
message ExitMsg { optional int32 code = 1; }
|
||||||
|
|
||||||
message TimerStartMsg {
|
message TimerStartMsg {
|
||||||
int32 id = 1;
|
optional int32 id = 1;
|
||||||
bool interval = 2;
|
optional bool interval = 2;
|
||||||
int32 duration = 3; // In milliseconds.
|
optional int32 duration = 3; // In milliseconds.
|
||||||
}
|
}
|
||||||
|
|
||||||
message TimerReadyMsg {
|
message TimerReadyMsg {
|
||||||
int32 id = 1;
|
optional int32 id = 1;
|
||||||
bool done = 2;
|
optional bool done = 2;
|
||||||
}
|
}
|
||||||
|
23
os.go
23
os.go
@ -16,14 +16,14 @@ func InitOS() {
|
|||||||
switch msg.Payload.(type) {
|
switch msg.Payload.(type) {
|
||||||
case *Msg_Exit:
|
case *Msg_Exit:
|
||||||
payload := msg.GetExit()
|
payload := msg.GetExit()
|
||||||
os.Exit(int(payload.Code))
|
os.Exit(int(*payload.Code))
|
||||||
case *Msg_SourceCodeFetch:
|
case *Msg_SourceCodeFetch:
|
||||||
payload := msg.GetSourceCodeFetch()
|
payload := msg.GetSourceCodeFetch()
|
||||||
return HandleSourceCodeFetch(payload.ModuleSpecifier, payload.ContainingFile)
|
return HandleSourceCodeFetch(*payload.ModuleSpecifier, *payload.ContainingFile)
|
||||||
case *Msg_SourceCodeCache:
|
case *Msg_SourceCodeCache:
|
||||||
payload := msg.GetSourceCodeCache()
|
payload := msg.GetSourceCodeCache()
|
||||||
return HandleSourceCodeCache(payload.Filename, payload.SourceCode,
|
return HandleSourceCodeCache(*payload.Filename, *payload.SourceCode,
|
||||||
payload.OutputCode)
|
*payload.OutputCode)
|
||||||
default:
|
default:
|
||||||
panic("[os] Unexpected message " + string(buf))
|
panic("[os] Unexpected message " + string(buf))
|
||||||
}
|
}
|
||||||
@ -39,7 +39,8 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = err.Error()
|
var errStr = err.Error()
|
||||||
|
res.Error = &errStr
|
||||||
}
|
}
|
||||||
out, err = proto.Marshal(res)
|
out, err = proto.Marshal(res)
|
||||||
check(err)
|
check(err)
|
||||||
@ -72,12 +73,13 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sourceCode = string(sourceCodeBuf)
|
||||||
res.Payload = &Msg_SourceCodeFetchRes{
|
res.Payload = &Msg_SourceCodeFetchRes{
|
||||||
SourceCodeFetchRes: &SourceCodeFetchResMsg{
|
SourceCodeFetchRes: &SourceCodeFetchResMsg{
|
||||||
ModuleName: moduleName,
|
ModuleName: &moduleName,
|
||||||
Filename: filename,
|
Filename: &filename,
|
||||||
SourceCode: string(sourceCodeBuf),
|
SourceCode: &sourceCode,
|
||||||
OutputCode: outputCode,
|
OutputCode: &outputCode,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -91,7 +93,8 @@ func HandleSourceCodeCache(filename string, sourceCode string,
|
|||||||
err := ioutil.WriteFile(fn, outputCodeBuf, 0600)
|
err := ioutil.WriteFile(fn, outputCodeBuf, 0600)
|
||||||
res := &Msg{}
|
res := &Msg{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = err.Error()
|
var errStr = err.Error()
|
||||||
|
res.Error = &errStr
|
||||||
}
|
}
|
||||||
out, err := proto.Marshal(res)
|
out, err := proto.Marshal(res)
|
||||||
check(err)
|
check(err)
|
||||||
|
@ -12,7 +12,8 @@ func InitTimers() {
|
|||||||
switch msg.Payload.(type) {
|
switch msg.Payload.(type) {
|
||||||
case *Msg_TimerStart:
|
case *Msg_TimerStart:
|
||||||
payload := msg.GetTimerStart()
|
payload := msg.GetTimerStart()
|
||||||
return HandleTimerStart(payload.Id, payload.Interval, payload.Duration)
|
return HandleTimerStart(*payload.Id, *payload.Interval,
|
||||||
|
*payload.Duration)
|
||||||
default:
|
default:
|
||||||
panic("[timers] Unexpected message " + string(buf))
|
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, err := proto.Marshal(&Msg{
|
||||||
Payload: &Msg_TimerReady{
|
Payload: &Msg_TimerReady{
|
||||||
TimerReady: &TimerReadyMsg{
|
TimerReady: &TimerReadyMsg{
|
||||||
Id: id,
|
Id: &id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user