-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port cli/ops/resources.rs to json ops
- Loading branch information
1 parent
8577cd8
commit b2ce5c4
Showing
6 changed files
with
19 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,14 @@ | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
use super::dispatch_flatbuffers::serialize_response; | ||
use super::utils::ok_buf; | ||
use super::utils::CliOpResult; | ||
use crate::msg; | ||
use super::dispatch_json::{JsonOp, Value}; | ||
use crate::resources::table_entries; | ||
use crate::state::ThreadSafeState; | ||
use deno::*; | ||
use flatbuffers::FlatBufferBuilder; | ||
|
||
pub fn op_resources( | ||
_state: &ThreadSafeState, | ||
base: &msg::Base<'_>, | ||
data: Option<PinnedBuf>, | ||
) -> CliOpResult { | ||
assert!(data.is_none()); | ||
let cmd_id = base.cmd_id(); | ||
|
||
let builder = &mut FlatBufferBuilder::new(); | ||
_args: Value, | ||
_zero_copy: Option<PinnedBuf>, | ||
) -> Result<JsonOp, ErrBox> { | ||
let serialized_resources = table_entries(); | ||
|
||
let res: Vec<_> = serialized_resources | ||
.iter() | ||
.map(|(key, value)| { | ||
let repr = builder.create_string(value); | ||
|
||
msg::Resource::create( | ||
builder, | ||
&msg::ResourceArgs { | ||
rid: *key, | ||
repr: Some(repr), | ||
}, | ||
) | ||
}) | ||
.collect(); | ||
|
||
let resources = builder.create_vector(&res); | ||
let inner = msg::ResourcesRes::create( | ||
builder, | ||
&msg::ResourcesResArgs { | ||
resources: Some(resources), | ||
}, | ||
); | ||
|
||
ok_buf(serialize_response( | ||
cmd_id, | ||
builder, | ||
msg::BaseArgs { | ||
inner: Some(inner.as_union_value()), | ||
inner_type: msg::Any::ResourcesRes, | ||
..Default::default() | ||
}, | ||
)) | ||
Ok(JsonOp::Sync(json!(serialized_resources))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters