Skip to content

Commit 5cc8772

Browse files
Switch to using SafeArray
1 parent 097f6c4 commit 5cc8772

File tree

12 files changed

+460
-598
lines changed

12 files changed

+460
-598
lines changed

application/apps/rustcore/rs-bindings/Cargo.lock

+428-556
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/apps/rustcore/rs-bindings/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111

1212
[build-dependencies]
1313
# Added "default-features = false" becuase: https://github.com/rust-lang/rust/issues/98903
14-
node-bindgen = { version="6.0", default-features = false, features = ["build"] }
14+
node-bindgen = { version="6.1", default-features = false, features = ["build"] }
1515
[dependencies]
1616
anyhow = "1.0"
1717
crossbeam-channel = "0.5"
@@ -20,7 +20,7 @@ indexer_base = { path = "../../indexer/indexer_base" }
2020
log = "0.4"
2121
log4rs = "1.2"
2222
merging = { path = "../../indexer/merging" }
23-
node-bindgen = { version="6.0", features = ["serde-json"] }
23+
node-bindgen = { version="6.1", features = ["serde-json"] }
2424
processor = { path = "../../indexer/processor" }
2525
serde = { version = "1.0", features = ["derive"] }
2626
serde_json = "1.0"

application/apps/rustcore/rs-bindings/src/js/converting/attachment.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use node_bindgen::{
2-
core::{val::JsEnv, NjError, TryIntoJs},
2+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
33
sys::napi_value,
44
};
55
use proto::*;
@@ -37,7 +37,6 @@ impl From<AttachmentInfoList> for Vec<u8> {
3737

3838
impl TryIntoJs for AttachmentInfoList {
3939
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
40-
let bytes: Vec<u8> = self.into();
41-
bytes.try_to_js(js_env)
40+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
4241
}
4342
}

application/apps/rustcore/rs-bindings/src/js/converting/errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use error::{
44
grab_error, search_error,
55
};
66
use node_bindgen::{
7-
core::{val::JsEnv, NjError, TryIntoJs},
7+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
88
sys::napi_value,
99
};
1010
use processor::{grabber::GrabError, search::error::SearchError};
@@ -29,8 +29,7 @@ impl From<E> for ComputationErrorWrapper {
2929

3030
impl TryIntoJs for ComputationErrorWrapper {
3131
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
32-
let bytes: Vec<u8> = self.into();
33-
bytes.try_to_js(js_env)
32+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
3433
}
3534
}
3635

application/apps/rustcore/rs-bindings/src/js/converting/event.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::errors::get_native_err;
22
use event::callback_event::search_values_updated;
33
use event::callback_event::{self, Event};
44
use node_bindgen::{
5-
core::{val::JsEnv, NjError, TryIntoJs},
5+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
66
sys::napi_value,
77
};
88
use proto::*;
@@ -21,8 +21,7 @@ impl CallbackEventWrapped {
2121

2222
impl TryIntoJs for CallbackEventWrapped {
2323
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
24-
let bytes: Vec<u8> = self.into();
25-
bytes.try_to_js(js_env)
24+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
2625
}
2726
}
2827

application/apps/rustcore/rs-bindings/src/js/converting/grabbing.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use node_bindgen::{
2-
core::{val::JsEnv, NjError, TryIntoJs},
2+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
33
sys::napi_value,
44
};
55
use proto::*;
@@ -34,7 +34,6 @@ impl From<GrabbedElements> for Vec<u8> {
3434

3535
impl TryIntoJs for GrabbedElements {
3636
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
37-
let bytes: Vec<u8> = self.into();
38-
bytes.try_to_js(js_env)
37+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
3938
}
4039
}

application/apps/rustcore/rs-bindings/src/js/converting/progress.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use node_bindgen::{
2-
core::{val::JsEnv, NjError, TryIntoJs},
2+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
33
sys::napi_value,
44
};
55
use progress::{self, lifecycle_transition};
@@ -52,7 +52,6 @@ impl From<LifecycleTransitionWrapper> for Vec<u8> {
5252

5353
impl TryIntoJs for LifecycleTransitionWrapper {
5454
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
55-
let bytes: Vec<u8> = self.into();
56-
bytes.try_to_js(js_env)
55+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
5756
}
5857
}

application/apps/rustcore/rs-bindings/src/js/converting/ranges.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use node_bindgen::{
2-
core::{val::JsEnv, NjError, TryIntoJs},
2+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
33
sys::napi_value,
44
};
55
use proto::*;
@@ -33,7 +33,6 @@ impl From<RangeInclusiveList> for Vec<u8> {
3333

3434
impl TryIntoJs for RangeInclusiveList {
3535
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
36-
let bytes: Vec<u8> = self.into();
37-
bytes.try_to_js(js_env)
36+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
3837
}
3938
}

application/apps/rustcore/rs-bindings/src/js/converting/sde.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use sources::sde::{SdeRequest, SdeResponse};
55
use std::{convert::TryInto, ops::Deref};
66
pub struct SdeResponseWrapped(pub SdeResponse);
77
use node_bindgen::{
8-
core::{val::JsEnv, NjError, TryIntoJs},
8+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
99
sys::napi_value,
1010
};
1111

@@ -40,7 +40,6 @@ impl TryInto<SdeRequest> for JsIncomeBuffer {
4040

4141
impl TryIntoJs for SdeResponseWrapped {
4242
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
43-
let bytes: Vec<u8> = self.into();
44-
bytes.try_to_js(js_env)
43+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
4544
}
4645
}

application/apps/rustcore/rs-bindings/src/js/jobs/converting.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use command_outcome::Cancelled;
22
use node_bindgen::{
3-
core::{val::JsEnv, NjError, TryIntoJs},
3+
core::{safebuffer::SafeArrayBuffer, val::JsEnv, NjError, TryIntoJs},
44
sys::napi_value,
55
};
66
use output::{Empty, StringVec};
@@ -138,42 +138,36 @@ impl From<CommandOutcomeWrapper<i64>> for Vec<u8> {
138138

139139
impl TryIntoJs for CommandOutcomeWrapper<String> {
140140
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
141-
let bytes: Vec<u8> = self.into();
142-
bytes.try_to_js(js_env)
141+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
143142
}
144143
}
145144

146145
impl TryIntoJs for CommandOutcomeWrapper<i64> {
147146
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
148-
let bytes: Vec<u8> = self.into();
149-
bytes.try_to_js(js_env)
147+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
150148
}
151149
}
152150

153151
impl TryIntoJs for CommandOutcomeWrapper<()> {
154152
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
155-
let bytes: Vec<u8> = self.into();
156-
bytes.try_to_js(js_env)
153+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
157154
}
158155
}
159156

160157
impl TryIntoJs for CommandOutcomeWrapper<bool> {
161158
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
162-
let bytes: Vec<u8> = self.into();
163-
bytes.try_to_js(js_env)
159+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
164160
}
165161
}
166162

167163
impl TryIntoJs for CommandOutcomeWrapper<Vec<String>> {
168164
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
169-
let bytes: Vec<u8> = self.into();
170-
bytes.try_to_js(js_env)
165+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
171166
}
172167
}
173168

174169
impl TryIntoJs for CommandOutcomeWrapper<Option<String>> {
175170
fn try_to_js(self, js_env: &JsEnv) -> Result<napi_value, NjError> {
176-
let bytes: Vec<u8> = self.into();
177-
bytes.try_to_js(js_env)
171+
SafeArrayBuffer::new(self.into()).try_to_js(js_env)
178172
}
179173
}

application/apps/rustcore/rs-bindings/src/js/session/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use crate::{
1010
logging::targets,
1111
};
1212
use log::{debug, error, info, warn};
13-
use node_bindgen::{core::buffer::JSArrayBuffer, derive::node_bindgen};
13+
use node_bindgen::{
14+
core::{buffer::JSArrayBuffer, safebuffer::SafeArrayBuffer},
15+
derive::node_bindgen,
16+
};
1417
use processor::grabber::LineRange;
1518
use session::{
1619
events::{CallbackEvent, ComputationError, NativeError},
@@ -660,7 +663,7 @@ impl RustSession {
660663
}
661664

662665
#[node_bindgen]
663-
fn test_grab_els_as_proto(&self) -> Result<Vec<u8>, ComputationErrorWrapper> {
666+
fn test_grab_els_as_proto(&self) -> Result<SafeArrayBuffer, ComputationErrorWrapper> {
664667
let var_name = Vec::new();
665668
let mut elements = var_name;
666669
for i in 0..50 {
@@ -674,6 +677,6 @@ impl RustSession {
674677
})
675678
}
676679
let msg = proto::GrabbedElementList { elements };
677-
Ok(prost::Message::encode_to_vec(&msg))
680+
Ok(SafeArrayBuffer::new(prost::Message::encode_to_vec(&msg)))
678681
}
679682
}

application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Protocol', function () {
5959
.then((session: Session) => {
6060
// Set provider into debug mode
6161
session.debug(true);
62-
const MESSAGES_COUNT = 100;
62+
const MESSAGES_COUNT = 1000;
6363
{
6464
const meausere: { json: number; proto: number } = { json: 0, proto: 0 };
6565
meausere.json = Date.now();
@@ -75,7 +75,7 @@ describe('Protocol', function () {
7575
}
7676
meausere.proto = Date.now() - meausere.proto;
7777
console.log(
78-
`Receiving messages count: ${MESSAGES_COUNT}\nJSON: ${
78+
`Receiving messages (no decoding) count: ${MESSAGES_COUNT}\nJSON: ${
7979
meausere.json
8080
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
8181
meausere.proto
@@ -97,7 +97,7 @@ describe('Protocol', function () {
9797
}
9898
meausere.proto = Date.now() - meausere.proto;
9999
console.log(
100-
`Grabbing messages count: ${MESSAGES_COUNT}\nJSON: ${
100+
`Grabbing messages (with decoding) count: ${MESSAGES_COUNT}\nJSON: ${
101101
meausere.json
102102
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
103103
meausere.proto

0 commit comments

Comments
 (0)