mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
Move away from oneof in msg.proto
This is due to the size added to msg.pb.js for every new message. See comment in msg.proto.
This commit is contained in:
parent
8eeededd90
commit
d765300de5
5 changed files with 67 additions and 45 deletions
16
main.go
16
main.go
|
@ -58,16 +58,14 @@ func main() {
|
|||
cwd, err := os.Getwd()
|
||||
check(err)
|
||||
|
||||
var command = Msg_START // TODO use proto3
|
||||
PubMsg("start", &Msg{
|
||||
Payload: &Msg_Start{
|
||||
Start: &StartMsg{
|
||||
Cwd: &cwd,
|
||||
Argv: args,
|
||||
DebugFlag: flagDebug,
|
||||
MainJs: &main_js,
|
||||
MainMap: &main_map,
|
||||
},
|
||||
},
|
||||
Command: &command,
|
||||
StartCwd: &cwd,
|
||||
StartArgv: args,
|
||||
StartDebugFlag: flagDebug,
|
||||
StartMainJs: &main_js,
|
||||
StartMainMap: &main_map,
|
||||
})
|
||||
|
||||
DispatchLoop()
|
||||
|
|
6
main.ts
6
main.ts
|
@ -19,7 +19,11 @@ dispatch.sub("start", (payload: Uint8Array) => {
|
|||
startCalled = true;
|
||||
|
||||
const msg = pb.Msg.decode(payload);
|
||||
const { cwd, argv, debugFlag, mainJs, mainMap } = msg.start;
|
||||
const cwd = msg.startCwd;
|
||||
const argv = msg.startArgv;
|
||||
const debugFlag = msg.startDebugFlag;
|
||||
const mainJs = msg.startMainJs;
|
||||
const mainMap = msg.startMainMap;
|
||||
|
||||
debug = debugFlag;
|
||||
util.log("start", { cwd, argv, debugFlag });
|
||||
|
|
66
msg.proto
66
msg.proto
|
@ -8,24 +8,46 @@ message BaseMsg {
|
|||
|
||||
message Msg {
|
||||
optional string error = 1;
|
||||
oneof payload {
|
||||
StartMsg start = 10;
|
||||
SourceCodeFetchMsg source_code_fetch = 11;
|
||||
SourceCodeFetchResMsg source_code_fetch_res = 12;
|
||||
SourceCodeCacheMsg source_code_cache = 13;
|
||||
ExitMsg exit = 14;
|
||||
TimerStartMsg timer_start = 15;
|
||||
TimerReadyMsg timer_ready = 16;
|
||||
TimerClearMsg timer_clear = 17;
|
||||
}
|
||||
}
|
||||
|
||||
message StartMsg {
|
||||
optional string cwd = 1;
|
||||
repeated string argv = 2;
|
||||
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
|
||||
enum Command {
|
||||
ERROR = 1;
|
||||
START = 2;
|
||||
SOURCE_CODE_FETCH_RES = 3;
|
||||
ONEOF = 100;
|
||||
}
|
||||
optional Command command = 2 [ default = ONEOF ];
|
||||
|
||||
// We avoid creating a message for each command (and use oneof or any types)
|
||||
// In order to reduce code in the size of the generated javascript
|
||||
// "msg.pb.js". It seems that each new message adds 20k and we want to
|
||||
// potentially add many hundreds of commands. Therefore we just prefix command
|
||||
// arguments by their name.
|
||||
|
||||
// Start
|
||||
optional string start_cwd = 10;
|
||||
repeated string start_argv = 11;
|
||||
optional bool start_debug_flag = 12;
|
||||
optional string start_main_js = 13; // The contents of dist/main.js
|
||||
optional string start_main_map = 14; // The contents of dist/main.map
|
||||
|
||||
// SOURCE_CODE_FETCH_RES
|
||||
// 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.
|
||||
optional string source_code_fetch_res_module_name = 30;
|
||||
optional string source_code_fetch_res_filename = 31;
|
||||
optional string source_code_fetch_res_source_code = 32;
|
||||
optional string source_code_fetch_res_output_code =
|
||||
33; // Non-empty only if cached.
|
||||
|
||||
oneof payload {
|
||||
SourceCodeFetchMsg source_code_fetch = 100;
|
||||
SourceCodeCacheMsg source_code_cache = 102;
|
||||
ExitMsg exit = 103;
|
||||
TimerStartMsg timer_start = 104;
|
||||
TimerReadyMsg timer_ready = 105;
|
||||
TimerClearMsg timer_clear = 106;
|
||||
}
|
||||
}
|
||||
|
||||
message SourceCodeFetchMsg {
|
||||
|
@ -33,16 +55,6 @@ message SourceCodeFetchMsg {
|
|||
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.
|
||||
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 {
|
||||
optional string filename = 1;
|
||||
optional string source_code = 2;
|
||||
|
|
14
os.go
14
os.go
|
@ -99,13 +99,13 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
|
|||
}
|
||||
|
||||
var sourceCode = string(sourceCodeBuf)
|
||||
res.Payload = &Msg_SourceCodeFetchRes{
|
||||
SourceCodeFetchRes: &SourceCodeFetchResMsg{
|
||||
ModuleName: &moduleName,
|
||||
Filename: &filename,
|
||||
SourceCode: &sourceCode,
|
||||
OutputCode: &outputCode,
|
||||
},
|
||||
var command = Msg_SOURCE_CODE_FETCH_RES
|
||||
res = &Msg{
|
||||
Command: &command,
|
||||
SourceCodeFetchResModuleName: &moduleName,
|
||||
SourceCodeFetchResFilename: &filename,
|
||||
SourceCodeFetchResSourceCode: &sourceCode,
|
||||
SourceCodeFetchResOutputCode: &outputCode,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
10
os.ts
10
os.ts
|
@ -1,5 +1,7 @@
|
|||
import { ModuleInfo } from "./types";
|
||||
import { sendMsg } from "./dispatch";
|
||||
import { main as pb } from "./msg.pb";
|
||||
import { assert } from "./util";
|
||||
|
||||
export function exit(code = 0): void {
|
||||
sendMsg("os", { exit: { code } });
|
||||
|
@ -12,7 +14,13 @@ export function sourceCodeFetch(
|
|||
const res = sendMsg("os", {
|
||||
sourceCodeFetch: { moduleSpecifier, containingFile }
|
||||
});
|
||||
return res.sourceCodeFetchRes;
|
||||
assert(res.command === pb.Msg.Command.SOURCE_CODE_FETCH_RES);
|
||||
return {
|
||||
moduleName: res.sourceCodeFetchResModuleName,
|
||||
filename: res.sourceCodeFetchResFilename,
|
||||
sourceCode: res.sourceCodeFetchResSourceCode,
|
||||
outputCode: res.sourceCodeFetchResOutputCode
|
||||
};
|
||||
}
|
||||
|
||||
export function sourceCodeCache(
|
||||
|
|
Loading…
Reference in a new issue