mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
introduce JSON serialization for ops (#2799)
Converts env(), exit(), execPath(), utime() and utimeSync() to use JSON instead of flatbuffers.
This commit is contained in:
parent
47c216317f
commit
bc467b265f
16 changed files with 355 additions and 241 deletions
|
@ -4,6 +4,7 @@ use deno::*;
|
|||
|
||||
mod compiler;
|
||||
mod dispatch_flatbuffers;
|
||||
mod dispatch_json;
|
||||
mod dispatch_minimal;
|
||||
mod errors;
|
||||
mod fetch;
|
||||
|
@ -23,9 +24,16 @@ mod timers;
|
|||
mod utils;
|
||||
mod workers;
|
||||
|
||||
// Warning! These values are duplicated in the TypeScript code (js/dispatch.ts),
|
||||
// update with care.
|
||||
pub const OP_FLATBUFFER: OpId = 44;
|
||||
pub const OP_READ: OpId = 1;
|
||||
pub const OP_WRITE: OpId = 2;
|
||||
pub const OP_EXIT: OpId = 3;
|
||||
pub const OP_IS_TTY: OpId = 4;
|
||||
pub const OP_ENV: OpId = 5;
|
||||
pub const OP_EXEC_PATH: OpId = 6;
|
||||
pub const OP_UTIME: OpId = 7;
|
||||
|
||||
pub fn dispatch(
|
||||
state: &ThreadSafeState,
|
||||
|
@ -43,10 +51,36 @@ pub fn dispatch(
|
|||
OP_WRITE => {
|
||||
dispatch_minimal::dispatch(io::op_write, state, control, zero_copy)
|
||||
}
|
||||
OP_EXIT => dispatch_json::dispatch(os::op_exit, state, control, zero_copy),
|
||||
OP_IS_TTY => {
|
||||
dispatch_json::dispatch(os::op_is_tty, state, control, zero_copy)
|
||||
}
|
||||
OP_ENV => dispatch_json::dispatch(os::op_env, state, control, zero_copy),
|
||||
OP_EXEC_PATH => {
|
||||
dispatch_json::dispatch(os::op_exec_path, state, control, zero_copy)
|
||||
}
|
||||
OP_UTIME => {
|
||||
dispatch_json::dispatch(fs::op_utime, state, control, zero_copy)
|
||||
}
|
||||
OP_FLATBUFFER => dispatch_flatbuffers::dispatch(state, control, zero_copy),
|
||||
_ => panic!("bad op_id"),
|
||||
};
|
||||
|
||||
state.metrics_op_dispatched(bytes_sent_control, bytes_sent_zero_copy);
|
||||
op
|
||||
|
||||
match op {
|
||||
Op::Sync(buf) => {
|
||||
state.metrics_op_completed(buf.len());
|
||||
Op::Sync(buf)
|
||||
}
|
||||
Op::Async(fut) => {
|
||||
use crate::futures::Future;
|
||||
let state = state.clone();
|
||||
let result_fut = Box::new(fut.map(move |buf: Buf| {
|
||||
state.clone().metrics_op_completed(buf.len());
|
||||
buf
|
||||
}));
|
||||
Op::Async(result_fut)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue