Reference self Node by host and optionally port, get rid of DType
This commit is contained in:
@@ -421,7 +421,6 @@ where
|
||||
|
||||
pub fn make_test_node(id: u32) -> Node {
|
||||
Node {
|
||||
id: format!("{:02}", id),
|
||||
host: "localhost".into(),
|
||||
listen: "0.0.0.0".into(),
|
||||
port: 8800 + id as u16,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use err::Error;
|
||||
use netpod::timeunits::MS;
|
||||
use netpod::{Channel, NanoRange, Nanos, Node};
|
||||
use netpod::{Channel, NanoRange, Nanos, Node, ScalarType};
|
||||
use nom::number::complete::{be_i16, be_i32, be_i64, be_i8, be_u8};
|
||||
use nom::Needed;
|
||||
#[allow(unused_imports)]
|
||||
@@ -25,30 +25,6 @@ where
|
||||
Err(nom::Err::Error(e))
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive, Serialize, Deserialize)]
|
||||
pub enum DType {
|
||||
Bool = 0,
|
||||
Bool8 = 1,
|
||||
Int8 = 2,
|
||||
Uint8 = 3,
|
||||
Int16 = 4,
|
||||
Uint16 = 5,
|
||||
Character = 6,
|
||||
Int32 = 7,
|
||||
Uint32 = 8,
|
||||
Int64 = 9,
|
||||
Uint64 = 10,
|
||||
Float32 = 11,
|
||||
Float64 = 12,
|
||||
String = 13,
|
||||
}
|
||||
|
||||
impl DType {
|
||||
pub fn to_i16(&self) -> i16 {
|
||||
ToPrimitive::to_i16(self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPrimitive, ToPrimitive, Serialize, Deserialize)]
|
||||
pub enum CompressionMethod {
|
||||
BitshuffleLZ4 = 0,
|
||||
@@ -78,7 +54,7 @@ pub struct ConfigEntry {
|
||||
-16 f64
|
||||
*/
|
||||
pub precision: i16,
|
||||
pub dtype: DType,
|
||||
pub scalar_type: ScalarType,
|
||||
pub is_compressed: bool,
|
||||
pub is_shaped: bool,
|
||||
pub is_array: bool,
|
||||
@@ -117,7 +93,6 @@ fn parse_short_string(inp: &[u8]) -> NRes<Option<String>> {
|
||||
}
|
||||
}
|
||||
|
||||
//pub fn parse_entry(inp: &[u8]) -> IResult<&[u8], Option<ConfigEntry>> {
|
||||
pub fn parse_entry(inp: &[u8]) -> NRes<Option<ConfigEntry>> {
|
||||
let (inp, len1) = be_i32(inp)?;
|
||||
if len1 < 0 || len1 > 4000 {
|
||||
@@ -150,14 +125,14 @@ pub fn parse_entry(inp: &[u8]) -> NRes<Option<ConfigEntry>> {
|
||||
let is_array = dtmask & 0x40 != 0;
|
||||
let is_big_endian = dtmask & 0x20 != 0;
|
||||
let is_shaped = dtmask & 0x10 != 0;
|
||||
let (inp, dtype) = be_i8(inp)?;
|
||||
let (inp, dtype) = be_u8(inp)?;
|
||||
if dtype > 13 {
|
||||
return mkerr(format!("unexpected data type {}", dtype));
|
||||
}
|
||||
let dtype = match num_traits::FromPrimitive::from_i8(dtype) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
return mkerr(format!("Can not convert {} to DType", dtype));
|
||||
let scalar_type = match ScalarType::from_dtype_index(dtype) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return mkerr(format!("Can not convert {} to DType {:?}", dtype, e));
|
||||
}
|
||||
};
|
||||
let (inp, compression_method) = match is_compressed {
|
||||
@@ -211,7 +186,7 @@ pub fn parse_entry(inp: &[u8]) -> NRes<Option<ConfigEntry>> {
|
||||
modulo,
|
||||
offset,
|
||||
precision,
|
||||
dtype,
|
||||
scalar_type,
|
||||
is_compressed: is_compressed,
|
||||
is_array: is_array,
|
||||
is_shaped: is_shaped,
|
||||
|
||||
@@ -224,7 +224,7 @@ impl EventChunker {
|
||||
ts,
|
||||
pulse,
|
||||
Some(decomp),
|
||||
ScalarType::from_dtype_index(type_index),
|
||||
ScalarType::from_dtype_index(type_index)?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +103,6 @@ where
|
||||
buf: BytesMut,
|
||||
wp: usize,
|
||||
) -> (Option<Option<Result<InMemoryFrame, Error>>>, BytesMut, usize) {
|
||||
trace!(
|
||||
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tryparse with buf.len() {} wp {}",
|
||||
buf.len(),
|
||||
wp
|
||||
);
|
||||
let mut buf = buf;
|
||||
let nb = wp;
|
||||
if nb >= INMEM_FRAME_HEAD {
|
||||
@@ -126,9 +121,10 @@ where
|
||||
wp,
|
||||
);
|
||||
}
|
||||
trace!("tryparse len {}", len);
|
||||
if len == 0 {
|
||||
info!("stop-frame with nb {}", nb);
|
||||
if nb != INMEM_FRAME_HEAD + INMEM_FRAME_FOOT {
|
||||
warn!("stop-frame with nb {}", nb);
|
||||
}
|
||||
(Some(None), buf, wp)
|
||||
} else {
|
||||
if len > 1024 * 32 {
|
||||
|
||||
@@ -55,7 +55,6 @@ pub async fn gen_test_data() -> Result<(), Error> {
|
||||
}
|
||||
for i1 in 0..3 {
|
||||
let node = Node {
|
||||
id: format!("{:02}", i1),
|
||||
host: "localhost".into(),
|
||||
listen: "0.0.0.0".into(),
|
||||
port: 7780 + i1 as u16,
|
||||
|
||||
@@ -11,7 +11,7 @@ use futures_util::StreamExt;
|
||||
#[allow(unused_imports)]
|
||||
use netpod::log::*;
|
||||
use netpod::timeunits::SEC;
|
||||
use netpod::{Node, NodeConfig, ScalarType, Shape};
|
||||
use netpod::{Node, NodeConfig, Shape};
|
||||
use std::net::SocketAddr;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::tcp::OwnedWriteHalf;
|
||||
@@ -168,7 +168,7 @@ async fn raw_conn_handler_inner_try(
|
||||
keyspace: entry.ks as u8,
|
||||
time_bin_size: entry.bs,
|
||||
shape: shape,
|
||||
scalar_type: ScalarType::from_dtype_index(entry.dtype.to_i16() as u8),
|
||||
scalar_type: entry.scalar_type.clone(),
|
||||
big_endian: entry.is_big_endian,
|
||||
array: entry.is_array,
|
||||
compression: entry.is_compressed,
|
||||
|
||||
Reference in New Issue
Block a user