mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
Upgrade Rust Flatbuffers
This commit is contained in:
parent
168d92f5d2
commit
d770cc18f8
5 changed files with 22 additions and 36 deletions
|
@ -59,12 +59,15 @@ source_set("compiler_files") {
|
|||
"$fb_src/src/code_generators.cpp",
|
||||
"$fb_src/src/flatc.cpp",
|
||||
"$fb_src/src/idl_gen_cpp.cpp",
|
||||
"$fb_src/src/idl_gen_dart.cpp",
|
||||
"$fb_src/src/idl_gen_fbs.cpp",
|
||||
"$fb_src/src/idl_gen_general.cpp",
|
||||
"$fb_src/src/idl_gen_go.cpp",
|
||||
"$fb_src/src/idl_gen_grpc.cpp",
|
||||
"$fb_src/src/idl_gen_js.cpp",
|
||||
"$fb_src/src/idl_gen_json_schema.cpp",
|
||||
"$fb_src/src/idl_gen_lobster.cpp",
|
||||
"$fb_src/src/idl_gen_lua.cpp",
|
||||
"$fb_src/src/idl_gen_php.cpp",
|
||||
"$fb_src/src/idl_gen_python.cpp",
|
||||
"$fb_src/src/idl_gen_rust.cpp",
|
||||
|
|
|
@ -34,10 +34,11 @@ solutions = [{
|
|||
'name':
|
||||
'cpplint'
|
||||
}, {
|
||||
# Tracking a bleeding-edge branch that is nearing rust support.
|
||||
# Tracking a bleeding-edge branch. Upgrade frequently.
|
||||
# https://github.com/google/flatbuffers/pull/3894
|
||||
# https://github.com/rw/flatbuffers/tree/2018-08-12--all-tests-passing
|
||||
'url':
|
||||
'https://github.com/rw/flatbuffers.git@2018-02--rust',
|
||||
'https://github.com/rw/flatbuffers.git@05e594342043179178da5331407eb1cd43d1cf02',
|
||||
'name':
|
||||
'flatbuffers'
|
||||
}]
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
use binding;
|
||||
use binding::{deno_buf, deno_set_response, DenoC};
|
||||
use flatbuffers;
|
||||
use flatbuffers::ByteStringOffset;
|
||||
use flatbuffers::LabeledUOffsetT;
|
||||
use from_c;
|
||||
use fs;
|
||||
use futures;
|
||||
use futures::sync::oneshot;
|
||||
use libc::c_char;
|
||||
use mem;
|
||||
use msg_generated::deno as msg;
|
||||
use std::ffi::CStr;
|
||||
use std::path::Path;
|
||||
|
@ -38,7 +35,7 @@ fn reply_error(d: *const DenoC, cmd_id: u32, msg: &String) {
|
|||
// println!("reply_error{}", msg);
|
||||
let args = msg::BaseArgs {
|
||||
cmdId: cmd_id,
|
||||
error: builder.create_string(msg),
|
||||
error: Some(builder.create_string(msg)),
|
||||
..Default::default()
|
||||
};
|
||||
set_response_base(d, &mut builder, &args)
|
||||
|
@ -49,7 +46,7 @@ fn create_msg(
|
|||
args: &msg::BaseArgs,
|
||||
) -> deno_buf {
|
||||
let base = msg::CreateBase(builder, &args);
|
||||
builder.finish(base);
|
||||
msg::FinishBaseBuffer(builder, base);
|
||||
let data = builder.get_active_buf_slice();
|
||||
deno_buf {
|
||||
// TODO(ry)
|
||||
|
@ -112,22 +109,21 @@ pub extern "C" fn handle_code_fetch(
|
|||
// reply_code_fetch
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::new();
|
||||
let mut msg_args = msg::CodeFetchResArgs {
|
||||
module_name: builder.create_string(&out.module_name),
|
||||
filename: builder.create_string(&out.filename),
|
||||
source_code: builder.create_string(&out.source_code),
|
||||
module_name: Some(builder.create_string(&out.module_name)),
|
||||
filename: Some(builder.create_string(&out.filename)),
|
||||
source_code: Some(builder.create_string(&out.source_code)),
|
||||
..Default::default()
|
||||
};
|
||||
match out.maybe_output_code {
|
||||
Some(ref output_code) => {
|
||||
msg_args.output_code = builder.create_string(output_code);
|
||||
msg_args.output_code = Some(builder.create_string(output_code));
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
let msg = msg::CreateCodeFetchRes(&mut builder, &msg_args);
|
||||
builder.finish(msg);
|
||||
let args = msg::BaseArgs {
|
||||
cmdId: cmd_id,
|
||||
msg: Some(msg.union()),
|
||||
msg: Some(flatbuffers::Offset::new(msg.value())),
|
||||
msg_type: msg::Any::CodeFetchRes,
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -219,12 +215,11 @@ fn send_timer_ready(d: *const DenoC, timer_id: u32, done: bool) {
|
|||
..Default::default()
|
||||
},
|
||||
);
|
||||
builder.finish(msg);
|
||||
send_base(
|
||||
d,
|
||||
&mut builder,
|
||||
&msg::BaseArgs {
|
||||
msg: Some(msg.union()),
|
||||
msg: Some(flatbuffers::Offset::new(msg.value())),
|
||||
msg_type: msg::Any::TimerReady,
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -250,35 +245,22 @@ pub extern "C" fn handle_read_file_sync(
|
|||
}
|
||||
|
||||
// Build the response message. memcpy data into msg.
|
||||
// TODO(ry) zero-copy.
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::new();
|
||||
|
||||
let vec = result.unwrap();
|
||||
//let data =
|
||||
// flatbuffers::LabeledUOffsetT::new(builder.push_bytes(vec.as_slice()));
|
||||
|
||||
let data_ = builder.create_byte_vector(vec.as_slice());
|
||||
|
||||
// TODO(ry) This is a hack that can be removed once builder.create_byte_vector
|
||||
// works properly.
|
||||
let data = unsafe {
|
||||
mem::transmute::<LabeledUOffsetT<ByteStringOffset>, LabeledUOffsetT<&[i8]>>(
|
||||
data_,
|
||||
)
|
||||
};
|
||||
|
||||
let data_off = builder.create_byte_vector(vec.as_slice());
|
||||
let msg = msg::CreateReadFileSyncRes(
|
||||
&mut builder,
|
||||
&msg::ReadFileSyncResArgs {
|
||||
data,
|
||||
data: Some(data_off),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
builder.finish(msg);
|
||||
set_response_base(
|
||||
d,
|
||||
&mut builder,
|
||||
&msg::BaseArgs {
|
||||
msg: Some(msg.union()),
|
||||
msg: Some(flatbuffers::Offset::new(msg.value())),
|
||||
msg_type: msg::Any::ReadFileSyncRes,
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -83,7 +83,7 @@ table FetchRes {
|
|||
id: uint;
|
||||
status: int;
|
||||
header_line: [string];
|
||||
body: [byte];
|
||||
body: [ubyte];
|
||||
}
|
||||
|
||||
table ReadFileSync {
|
||||
|
@ -91,12 +91,12 @@ table ReadFileSync {
|
|||
}
|
||||
|
||||
table ReadFileSyncRes {
|
||||
data: [byte];
|
||||
data: [ubyte];
|
||||
}
|
||||
|
||||
table WriteFileSync {
|
||||
filename: string;
|
||||
data: [byte];
|
||||
data: [ubyte];
|
||||
perm: uint;
|
||||
// perm specified by https://godoc.org/os#FileMode
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 221e8d5662be4d7524e31bb7b647623f46ad53ce
|
||||
Subproject commit cd5323373992f724b5afd2ab5fa074a7357d996a
|
Loading…
Reference in a new issue