Commit 1a34fc70 by wzc-a

Merge remote-tracking branch 'origin/master'

parents 04ad946d 600bff40
...@@ -12,8 +12,8 @@ byteorder = "1.5" ...@@ -12,8 +12,8 @@ byteorder = "1.5"
csv = "1.3" csv = "1.3"
protobuf = { version = "3.5", features = ["with-bytes"] } protobuf = { version = "3.5", features = ["with-bytes"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11"
serde_json = "1.0" serde_json = "1.0"
ciborium = "0.2"
petgraph = "0.6" petgraph = "0.6"
rayon = "1.10" rayon = "1.10"
num-traits = "0.2" num-traits = "0.2"
......
...@@ -9,7 +9,7 @@ crate-type = ["cdylib"] ...@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
serde_json = "1.0" serde_json = "1.0"
serde_cbor = "0.11" ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] } arrow-schema = { version = "52.1", features = ["serde"] }
csv = "1.3.0" csv = "1.3.0"
num-complex = "0.4" num-complex = "0.4"
...@@ -19,3 +19,4 @@ nalgebra = "0.33" ...@@ -19,3 +19,4 @@ nalgebra = "0.33"
ds-common = { path = "../ds-common" } ds-common = { path = "../ds-common" }
eig-domain = { path = "../../../eig-domain" } eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" } mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
...@@ -3,24 +3,26 @@ ...@@ -3,24 +3,26 @@
use std::collections::HashMap; use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema}; use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ndarray::Array2; use ndarray::Array2;
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use ds_common::{DEV_CONDUCTOR_DF_NAME, DEV_TOPO_DF_NAME, DS_PF_NLP_CONS, DS_PF_NLP_OBJ, DYN_TOPO_DF_NAME, TN_INPUT_DF_NAME}; use ds_common::{DEV_CONDUCTOR_DF_NAME, DEV_TOPO_DF_NAME, DS_PF_NLP_CONS, DS_PF_NLP_OBJ, DYN_TOPO_DF_NAME, TN_INPUT_DF_NAME};
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use ds_common::tn_input::read_tn_input; use ds_common::tn_input::read_tn_input;
use mems::model::{get_wasm_result, PluginInput, PluginOutput}; use mems::model::{PluginInput, PluginOutput};
use crate::read::read_dev_ohm; use crate::read::read_dev_ohm;
mod read; mod read;
mod nlp; mod nlp;
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串 // 从内存中获取字符串
let input = unsafe { let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _); let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap(); let input: PluginInput = ciborium::from_reader(slice).unwrap();
input input
}; };
let from = 0; let from = 0;
...@@ -81,13 +83,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -81,13 +83,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
} }
} }
} }
if error.is_some() { let output = if error.is_some() {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
}; }
get_wasm_result(output)
} else { } else {
let mut obj_csv_str = String::from("cn,tn\n"); let mut obj_csv_str = String::from("cn,tn\n");
// build schema // build schema
...@@ -105,11 +106,17 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -105,11 +106,17 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
(DS_PF_NLP_OBJ.to_string(), obj_csv_str.into_bytes()), (DS_PF_NLP_OBJ.to_string(), obj_csv_str.into_bytes()),
(DS_PF_NLP_CONS.to_string(), cons_csv_str.into_bytes()), (DS_PF_NLP_CONS.to_string(), cons_csv_str.into_bytes()),
]; ];
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(vec![obj_schema, cons_schema]), schema: Some(vec![obj_schema, cons_schema]),
csv_bytes, csv_bytes,
};
get_wasm_result(output)
} }
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
} }
\ No newline at end of file
...@@ -9,10 +9,11 @@ crate-type = ["cdylib"] ...@@ -9,10 +9,11 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
serde_json = "1.0" serde_json = "1.0"
serde_cbor = "0.11" ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] } arrow-schema = { version = "52.1", features = ["serde"] }
petgraph = "0.6" petgraph = "0.6"
eig-domain = { path = "../../../eig-domain" } eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" } mems = { path = "../../../mems" }
csv = "1.3.0" csv = "1.3.0"
ndarray = "0.15" ndarray = "0.15"
bytes = "1.6.1"
use std::collections::HashMap; use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema}; use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use csv::StringRecordsIter; use csv::StringRecordsIter;
use log::{info, warn}; use log::{info, warn};
use ndarray::{Array2, ArrayBase, Ix2, OwnedRepr}; use ndarray::{Array2, ArrayBase, Ix2, OwnedRepr};
use eig_domain::PropValue; use eig_domain::PropValue;
use mems::model::{get_csv_str, get_df_from_in_plugin, get_island_from_plugin_input, get_wasm_result, PluginInput, PluginOutput}; use mems::model::{get_csv_str, get_df_from_in_plugin, get_island_from_plugin_input, PluginInput, PluginOutput};
use mems::model::dev::PsRsrType; use mems::model::dev::PsRsrType;
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
info!("Read plugin input firstly"); info!("Read plugin input firstly");
// 从内存中获取字符串 // 从内存中获取字符串
let input = unsafe { let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _); let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap(); let input: PluginInput = ciborium::from_reader(slice).unwrap();
input input
}; };
let mut error = None; let mut error = None;
...@@ -76,27 +80,32 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -76,27 +80,32 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
} }
} }
} }
if error.is_none() { let output = if error.is_none() {
// build schema // build schema
let schema = Schema::new(vec![ let schema = Schema::new(vec![
Field::new("dev_id", DataType::UInt64, false), Field::new("dev_id", DataType::UInt64, false),
Field::new("ohm", DataType::Utf8, false), Field::new("ohm", DataType::Utf8, false),
]); ]);
let csv_bytes = vec![("".to_string(), csv_str.into_bytes())]; let csv_bytes = vec![("".to_string(), csv_str.into_bytes())];
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(vec![schema]), schema: Some(vec![schema]),
csv_bytes, csv_bytes,
}; }
get_wasm_result(output)
} else { } else {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
};
get_wasm_result(output)
} }
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
} }
fn read_config(records: &mut StringRecordsIter<&[u8]>) fn read_config(records: &mut StringRecordsIter<&[u8]>)
......
...@@ -9,8 +9,9 @@ crate-type = ["cdylib"] ...@@ -9,8 +9,9 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
csv = "1.3.0" csv = "1.3.0"
serde_cbor = "0.11" ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] } arrow-schema = { version = "52.1", features = ["serde"] }
eig-domain = { path = "../../../eig-domain" } eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" } mems = { path = "../../../mems" }
ds-common = { path = "../ds-common" } ds-common = { path = "../ds-common" }
bytes = "1.6.1"
\ No newline at end of file
use std::collections::HashMap; use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema}; use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ds_common::{DEV_TOPO_DF_NAME, DYN_TOPO_DF_NAME, POINT_DF_NAME, STATIC_TOPO_DF_NAME, TERMINAL_DF_NAME}; use ds_common::{DEV_TOPO_DF_NAME, DYN_TOPO_DF_NAME, POINT_DF_NAME, STATIC_TOPO_DF_NAME, TERMINAL_DF_NAME};
use ds_common::static_topo::{read_static_topo, read_point_terminal, read_terminal_cn_dev}; use ds_common::static_topo::{read_point_terminal, read_static_topo, read_terminal_cn_dev};
use eig_domain::DataUnit; use eig_domain::DataUnit;
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, get_wasm_result, ModelType, PluginInput, PluginOutput}; use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, ModelType, PluginInput, PluginOutput};
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串 // 从内存中获取字符串
let input = unsafe { let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _); let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap(); let input: PluginInput = ciborium::from_reader(slice).unwrap();
input input
}; };
let mut error = None; let mut error = None;
...@@ -60,7 +62,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -60,7 +62,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
} }
} }
} }
if error.is_none() { let output = if error.is_none() {
let (meas, units) = r1.unwrap(); let (meas, units) = r1.unwrap();
let mut point_map: HashMap<u64, u64> = HashMap::with_capacity(points.len()); let mut point_map: HashMap<u64, u64> = HashMap::with_capacity(points.len());
let mut terminal_cn: HashMap<u64, u64> = HashMap::with_capacity(points.len()); let mut terminal_cn: HashMap<u64, u64> = HashMap::with_capacity(points.len());
...@@ -195,18 +197,23 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -195,18 +197,23 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
csv_bytes.push((DEV_TOPO_DF_NAME.to_string(), dev_csv.into_bytes())); csv_bytes.push((DEV_TOPO_DF_NAME.to_string(), dev_csv.into_bytes()));
schema.push(dev_schema); schema.push(dev_schema);
} }
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(schema), schema: Some(schema),
csv_bytes, csv_bytes,
}; }
get_wasm_result(output)
} else { } else {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
};
get_wasm_result(output)
} }
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
} }
\ No newline at end of file
...@@ -9,8 +9,9 @@ crate-type = ["cdylib"] ...@@ -9,8 +9,9 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
csv = "1.3.0" csv = "1.3.0"
serde_cbor = "0.11" ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] } arrow-schema = { version = "52.1", features = ["serde"] }
ds-common = { path = "../ds-common" } ds-common = { path = "../ds-common" }
eig-domain = { path = "../../../eig-domain" } eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" } mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
...@@ -4,21 +4,24 @@ use std::io::Write; ...@@ -4,21 +4,24 @@ use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
use arrow_schema::{DataType, Field, Schema}; use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ds_common::{DEV_TOPO_DF_NAME, POINT_DF_NAME, SHUNT_MEAS_DF_NAME, TERMINAL_DF_NAME, TN_INPUT_DF_NAME}; use ds_common::{DEV_TOPO_DF_NAME, POINT_DF_NAME, SHUNT_MEAS_DF_NAME, TERMINAL_DF_NAME, TN_INPUT_DF_NAME};
use ds_common::dyn_topo::read_dev_topo; use ds_common::dyn_topo::read_dev_topo;
use ds_common::static_topo::{read_point_terminal, read_terminal_cn_dev}; use ds_common::static_topo::{read_point_terminal, read_terminal_cn_dev};
use ds_common::tn_input::read_shunt_measures; use ds_common::tn_input::read_shunt_measures;
use eig_domain::{DataUnit, MeasureValue}; use eig_domain::{DataUnit, MeasureValue};
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, get_wasm_result, PluginInput, PluginOutput}; use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, PluginInput, PluginOutput};
use mems::model::dev::{MeasPhase, PsRsrType}; use mems::model::dev::{MeasPhase, PsRsrType};
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串 // 从内存中获取字符串
let input = unsafe { let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _); let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap(); let input: PluginInput = ciborium::from_reader(slice).unwrap();
input input
}; };
let r2 = get_df_from_in_plugin(&input); let r2 = get_df_from_in_plugin(&input);
...@@ -82,13 +85,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -82,13 +85,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
from += size; from += size;
} }
} }
if error.is_some() { let output = if error.is_some() {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
}; }
get_wasm_result(output)
} else { } else {
if with_static { if with_static {
let mut csv_str = String::from("point,terminal,phase\n"); let mut csv_str = String::from("point,terminal,phase\n");
...@@ -138,24 +140,22 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -138,24 +140,22 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
} }
// write graph // write graph
let csv_bytes = vec![(SHUNT_MEAS_DF_NAME.to_string(), csv_str.into_bytes())]; let csv_bytes = vec![(SHUNT_MEAS_DF_NAME.to_string(), csv_str.into_bytes())];
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(vec![schema]), schema: Some(vec![schema]),
csv_bytes, csv_bytes,
}; }
get_wasm_result(output)
} else { } else {
let r1 = get_meas_from_plugin_input(&input); let r1 = get_meas_from_plugin_input(&input);
if let Err(s) = &r1 { if let Err(s) = &r1 {
error = Some(s.clone()); error = Some(s.clone());
} }
if error.is_some() { if error.is_some() {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
}; }
get_wasm_result(output)
} else { } else {
let (meas, units) = r1.unwrap(); let (meas, units) = r1.unwrap();
let len = terminal_of_shunt_dev.len(); let len = terminal_of_shunt_dev.len();
...@@ -253,15 +253,21 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -253,15 +253,21 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
let _ = file.sync_all(); let _ = file.sync_all();
} }
let csv_bytes = vec![(TN_INPUT_DF_NAME.to_string(), csv_str.into_bytes())]; let csv_bytes = vec![(TN_INPUT_DF_NAME.to_string(), csv_str.into_bytes())];
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(vec![schema]), schema: Some(vec![schema]),
csv_bytes, csv_bytes,
};
get_wasm_result(output)
} }
} }
} }
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
} }
unsafe fn create_measure(m: &MeasureValue, phase: &MeasPhase, ratio: f64, unsafe fn create_measure(m: &MeasureValue, phase: &MeasPhase, ratio: f64,
......
...@@ -8,7 +8,8 @@ crate-type = ["cdylib"] ...@@ -8,7 +8,8 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
serde_cbor = "0.11" ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] } arrow-schema = { version = "52.1", features = ["serde"] }
petgraph = "0.6" petgraph = "0.6"
mems = { path = "../../../mems" } mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
use std::collections::HashMap; use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema}; use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use petgraph::graph::UnGraph; use petgraph::graph::UnGraph;
use mems::model::{get_csv_str, get_island_from_plugin_input, get_wasm_result, ModelType, PluginInput, PluginOutput}; use mems::model::{get_csv_str, get_island_from_plugin_input, ModelType, PluginInput, PluginOutput};
use mems::model::dev::{CN, Island, PropDefine, PsRsrType, RsrDefine}; use mems::model::dev::{CN, Island, PropDefine, PsRsrType, RsrDefine};
// use std::fs; // use std::fs;
...@@ -14,13 +15,14 @@ const NORMAL_OPEN: &str = "normalOpen"; ...@@ -14,13 +15,14 @@ const NORMAL_OPEN: &str = "normalOpen";
const STATIC_TOPO_DF_NAME: &str = "static_topo"; const STATIC_TOPO_DF_NAME: &str = "static_topo";
const TERMINAL_DF_NAME: &str = "terminal_cn_dev"; const TERMINAL_DF_NAME: &str = "terminal_cn_dev";
const POINT_DF_NAME: &str = "point_terminal_phase"; const POINT_DF_NAME: &str = "point_terminal_phase";
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串 // 从内存中获取字符串
let input = unsafe { let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _); let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap(); let input: PluginInput =ciborium::from_reader(slice).unwrap();
input input
}; };
let mut error = None; let mut error = None;
...@@ -28,7 +30,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -28,7 +30,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
if let Err(s) = &r { if let Err(s) = &r {
error = Some(s.clone()); error = Some(s.clone());
} }
if error.is_none() { let output = if error.is_none() {
let (island, prop_defs, defines) = r.unwrap(); let (island, prop_defs, defines) = r.unwrap();
let mut outgoing = vec![]; let mut outgoing = vec![];
for model_input in &input.model { for model_input in &input.model {
...@@ -114,20 +116,25 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -114,20 +116,25 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
if !is_matched { if !is_matched {
create_static_topo(&island, &prop_defs, &defines, &mut csv_bytes, &mut schema); create_static_topo(&island, &prop_defs, &defines, &mut csv_bytes, &mut schema);
} }
let output = PluginOutput { PluginOutput {
error_msg: None, error_msg: None,
schema: Some(schema), schema: Some(schema),
csv_bytes, csv_bytes,
}; }
get_wasm_result(output)
} else { } else {
let output = PluginOutput { PluginOutput {
error_msg: error, error_msg: error,
schema: None, schema: None,
csv_bytes: vec![], csv_bytes: vec![],
};
get_wasm_result(output)
} }
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
} }
fn create_static_topo(island: &Island, prop_defs: &[PropDefine], defines: &HashMap<u64, RsrDefine>, csv_bytes: &mut Vec<(String, Vec<u8>)>, schema: &mut Vec<Schema>) { fn create_static_topo(island: &Island, prop_defs: &[PropDefine], defines: &HashMap<u64, RsrDefine>, csv_bytes: &mut Vec<(String, Vec<u8>)>, schema: &mut Vec<Schema>) {
......
use std::collections::HashMap; use std::collections::HashMap;
use bytes::{Buf, BufMut, BytesMut};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use eig_aoe::aoe::AoeModel; use eig_aoe::aoe::AoeModel;
...@@ -301,7 +301,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec< ...@@ -301,7 +301,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
} }
let size = input.model_len[index] as usize; let size = input.model_len[index] as usize;
let end = from + size; let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]); let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() { if r.is_err() {
return Err(format!("{:?}", r)); return Err(format!("{:?}", r));
} }
...@@ -313,7 +313,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec< ...@@ -313,7 +313,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
} }
let size = input.model_len[index] as usize; let size = input.model_len[index] as usize;
let end = from + size; let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]); let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() { if r.is_err() {
return Err(format!("{:?}", r)); return Err(format!("{:?}", r));
} }
...@@ -325,7 +325,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec< ...@@ -325,7 +325,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
} }
let size = input.model_len[index] as usize; let size = input.model_len[index] as usize;
let end = from + size; let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]); let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() { if r.is_err() {
return Err(format!("{:?}", r)); return Err(format!("{:?}", r));
} }
...@@ -359,7 +359,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal ...@@ -359,7 +359,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal
} }
let size = input.model_len[index] as usize; let size = input.model_len[index] as usize;
let end = from + size; let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]); let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() { if r.is_err() {
return Err(format!("{:?}", r)); return Err(format!("{:?}", r));
} }
...@@ -371,7 +371,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal ...@@ -371,7 +371,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal
} }
let size = input.model_len[index] as usize; let size = input.model_len[index] as usize;
let end = from + size; let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]); let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() { if r.is_err() {
return Err(format!("{:?}", r)); return Err(format!("{:?}", r));
} }
...@@ -431,17 +431,19 @@ pub fn get_df_from_in_plugin(input: &PluginInput) -> Result<usize, String> { ...@@ -431,17 +431,19 @@ pub fn get_df_from_in_plugin(input: &PluginInput) -> Result<usize, String> {
Ok(from) Ok(from)
} }
#[inline] // #[inline]
pub fn get_wasm_result(output: PluginOutput) -> u64 { // pub fn get_wasm_result(output: PluginOutput) -> u64 {
// 下面的unwrap是必要的,否则输出的字节无法解析 // // 下面的unwrap是必要的,否则输出的字节无法解析
let v = serde_cbor::to_vec(&output).unwrap(); // let mut v = Vec::new();
let offset = v.as_ptr() as i32; // ciborium::into_writer(&output, &mut v).unwrap();
let len = v.len() as u32; // v.shrink_to_fit();
let mut bytes = BytesMut::with_capacity(8); // let offset = v.as_ptr() as i32;
bytes.put_i32(offset); // let len = v.len() as u32;
bytes.put_u32(len); // let mut bytes = BytesMut::with_capacity(8);
return bytes.get_u64(); // bytes.put_i32(offset);
} // bytes.put_u32(len);
// return bytes.get_u64();
// }
#[inline] #[inline]
pub fn get_csv_str(s: &str) -> String { pub fn get_csv_str(s: &str) -> String {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论