summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-04 14:50:28 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-04 16:43:08 -0400
commit06a28998ea3fd38a2173d71eeb3fae5fb5559b2e (patch)
tree79307e9e8c745ec56bc8c18570faccb498219c1a /src
parent72cd03a1c53633a216f5e284bd1820ea52bf795c (diff)
Replace protobufs with flatbuffers
Diffstat (limited to 'src')
-rw-r--r--src/main.rs1
-rw-r--r--src/mock_main.cc28
-rw-r--r--src/msg.fbs12
-rw-r--r--src/msg.proto96
-rw-r--r--src/snapshot_creator.cc2
5 files changed, 31 insertions, 108 deletions
diff --git a/src/main.rs b/src/main.rs
index 31a225d20..4441b4005 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
extern crate libc;
+
use libc::c_char;
use libc::c_int;
use libc::c_void;
diff --git a/src/mock_main.cc b/src/mock_main.cc
index 1341e6397..40d3d89d2 100644
--- a/src/mock_main.cc
+++ b/src/mock_main.cc
@@ -10,8 +10,9 @@
#include <unistd.h>
#endif
+#include "flatbuffers/flatbuffers.h"
#include "include/deno.h"
-#include "src/msg.pb.h"
+#include "src/msg_generated.h"
#include "third_party/v8/src/base/logging.h"
static char** global_argv;
@@ -20,24 +21,29 @@ static int global_argc;
void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
printf("MessagesFromJS %s\n", channel);
- deno::Msg response;
- response.set_command(deno::Msg_Command_START);
+ flatbuffers::FlatBufferBuilder builder;
char cwdbuf[1024];
// TODO(piscisaureus): support unicode on windows.
- std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf)));
- response.set_start_cwd(cwd);
+ getcwd(cwdbuf, sizeof(cwdbuf));
+ auto start_cwd = builder.CreateString(cwdbuf);
+ std::vector<flatbuffers::Offset<flatbuffers::String>> args;
for (int i = 0; i < global_argc; ++i) {
- printf("arg %d %s\n", i, global_argv[i]);
- response.add_start_argv(global_argv[i]);
+ args.push_back(builder.CreateString(global_argv[i]));
}
- printf("response.start_argv_size %d \n", response.start_argv_size());
+ auto start_argv = builder.CreateVector(args);
- std::string output;
- CHECK(response.SerializeToString(&output));
+ deno::MsgBuilder msg_builder(builder);
+ msg_builder.add_command(deno::Command_START);
+ msg_builder.add_start_cwd(start_cwd);
+ msg_builder.add_start_argv(start_argv);
- deno_buf bufout{output.c_str(), output.length()};
+ auto response = msg_builder.Finish();
+ builder.Finish(response);
+
+ deno_buf bufout{reinterpret_cast<const char*>(builder.GetBufferPointer()),
+ builder.GetSize()};
deno_set_response(d, bufout);
}
diff --git a/src/msg.fbs b/src/msg.fbs
new file mode 100644
index 000000000..3dbb8e420
--- /dev/null
+++ b/src/msg.fbs
@@ -0,0 +1,12 @@
+namespace deno;
+
+enum Command: byte {
+ START = 0,
+}
+
+table Msg {
+ command: Command;
+ start_cwd: string;
+ start_argv: [string];
+}
+
diff --git a/src/msg.proto b/src/msg.proto
deleted file mode 100644
index 1b093050d..000000000
--- a/src/msg.proto
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
-// All rights reserved. MIT License.
-syntax = "proto3";
-package deno;
-
-message Msg {
- enum Command {
- ERROR = 0;
- START = 1;
- CODE_FETCH = 2;
- CODE_FETCH_RES = 3;
- CODE_CACHE = 4;
- EXIT = 5;
- TIMER_START = 6;
- TIMER_READY = 7;
- TIMER_CLEAR = 8;
- FETCH_REQ = 9;
- FETCH_RES = 10;
- READ_FILE_SYNC = 11;
- READ_FILE_SYNC_RES = 12;
- WRITE_FILE_SYNC = 13;
- }
- Command command = 1;
-
- // 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.
-
- // ERROR
- string error = 2;
-
- // START
- string start_cwd = 10;
- repeated string start_argv = 11;
- bool start_debug_flag = 12;
- string start_main_js = 13; // The contents of dist/main.js
- string start_main_map = 14; // The contents of dist/main.map
-
- // CODE_FETCH
- string code_fetch_module_specifier = 20;
- string code_fetch_containing_file = 21;
-
- // 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.
- string code_fetch_res_module_name = 30;
- string code_fetch_res_filename = 31;
- string code_fetch_res_source_code = 32;
- string code_fetch_res_output_code = 33; // Non-empty only if cached.
-
- // CODE_CACHE
- string code_cache_filename = 41;
- string code_cache_source_code = 42;
- string code_cache_output_code = 43;
-
- // EXIT
- int32 exit_code = 50;
-
- // TIMER_START
- int32 timer_start_id = 60;
- bool timer_start_interval = 61;
- int32 timer_start_delay = 62; // In milliseconds.
-
- // TIMER_READY
- int32 timer_ready_id = 70;
- bool timer_ready_done = 71;
-
- // TIMER_CLEAR
- int32 timer_clear_id = 80;
-
- // FETCH_REQ
- int32 fetch_req_id = 90;
- string fetch_req_url = 91;
- // repeated string fetch_req_header_line = 91
-
- // FETCH_RES
- int32 fetch_res_id = 100;
- int32 fetch_res_status = 101;
- repeated string fetch_res_header_line = 102;
- bytes fetch_res_body = 103;
-
- // READ_FILE_SYNC
- string read_file_sync_filename = 110;
-
- // READ_FILE_SYNC_RES
- bytes read_file_sync_data = 120;
-
- // WRITE_FILE_SYNC
- string write_file_sync_filename = 130;
- bytes write_file_sync_data = 131;
- uint32 write_file_sync_perm = 132;
- // write_file_sync_perm specified by https://godoc.org/os#FileMode
-}
diff --git a/src/snapshot_creator.cc b/src/snapshot_creator.cc
index 30134b3ab..a49f656aa 100644
--- a/src/snapshot_creator.cc
+++ b/src/snapshot_creator.cc
@@ -35,7 +35,7 @@ v8::StartupData MakeSnapshot(const char* js_filename, const char* js_source) {
}
auto snapshot_blob =
- creator->CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep);
+ creator->CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
return snapshot_blob;
}