Begin refactor frame handling, update clap
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector, ToJsonBytes, ToJsonResult};
|
||||
use crate::{
|
||||
ts_offs_from_abs, Appendable, FilterFittingInside, Fits, FitsInside, FrameTypeStatic, IsoDateTime, NewEmpty,
|
||||
ts_offs_from_abs, Appendable, FilterFittingInside, Fits, FitsInside, FrameTypeStaticSYC, IsoDateTime, NewEmpty,
|
||||
RangeOverlapInfo, ReadPbv, ReadableFromFile, Sitemty, SitemtyFrameType, SubFrId, TimeBinnableDyn, TimeBinnableType,
|
||||
TimeBinnableTypeAggregator, TimeBinned, TimeBinnerDyn, TimeBins, WithLen,
|
||||
};
|
||||
@@ -28,16 +28,11 @@ pub struct MinMaxAvgDim0Bins<NTY> {
|
||||
pub avgs: Vec<f32>,
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for MinMaxAvgDim0Bins<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for MinMaxAvgDim0Bins<NTY>
|
||||
where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::MIN_MAX_AVG_DIM_0_BINS_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
// TODO remove usage of this
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> SitemtyFrameType for MinMaxAvgDim0Bins<NTY>
|
||||
@@ -45,7 +40,7 @@ where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector, ToJsonBytes, ToJsonResult};
|
||||
use crate::waveevents::WaveEvents;
|
||||
use crate::{
|
||||
pulse_offs_from_abs, ts_offs_from_abs, Appendable, FilterFittingInside, Fits, FitsInside, FrameTypeStatic,
|
||||
pulse_offs_from_abs, ts_offs_from_abs, Appendable, FilterFittingInside, Fits, FitsInside, FrameTypeStaticSYC,
|
||||
IsoDateTime, NewEmpty, RangeOverlapInfo, ReadPbv, ReadableFromFile, Sitemty, SitemtyFrameType, SubFrId,
|
||||
TimeBinnableDyn, TimeBinnableType, TimeBinnableTypeAggregator, TimeBinned, TimeBins, WithLen,
|
||||
};
|
||||
@@ -27,16 +27,11 @@ pub struct MinMaxAvgDim1Bins<NTY> {
|
||||
pub avgs: Vec<Option<Vec<f32>>>,
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for MinMaxAvgDim1Bins<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for MinMaxAvgDim1Bins<NTY>
|
||||
where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::MIN_MAX_AVG_DIM_1_BINS_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
// TODO remove usage of this
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> SitemtyFrameType for MinMaxAvgDim1Bins<NTY>
|
||||
@@ -44,7 +39,7 @@ where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ pub enum EventsItem {
|
||||
}
|
||||
|
||||
impl SitemtyFrameType for EventsItem {
|
||||
//const FRAME_TYPE_ID: u32 = crate::EVENTS_ITEM_FRAME_TYPE_ID;
|
||||
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
crate::EVENTS_ITEM_FRAME_TYPE_ID
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::inmem::InMemoryFrame;
|
||||
use crate::{FrameDecodable, FrameType, LogItem, StatsItem};
|
||||
use crate::{
|
||||
FrameType, FrameTypeStatic, Sitemty, StreamItem, ERROR_FRAME_TYPE_ID, INMEM_FRAME_ENCID, INMEM_FRAME_HEAD,
|
||||
INMEM_FRAME_MAGIC, NON_DATA_FRAME_TYPE_ID, TERM_FRAME_TYPE_ID,
|
||||
ERROR_FRAME_TYPE_ID, INMEM_FRAME_ENCID, INMEM_FRAME_HEAD, INMEM_FRAME_MAGIC, LOG_FRAME_TYPE_ID,
|
||||
RANGE_COMPLETE_FRAME_TYPE_ID, STATS_FRAME_TYPE_ID, TERM_FRAME_TYPE_ID,
|
||||
};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use err::Error;
|
||||
#[allow(unused)]
|
||||
use netpod::log::*;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
pub fn make_frame<FT>(item: &FT) -> Result<BytesMut, Error>
|
||||
where
|
||||
@@ -65,8 +66,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove duplication for these similar `make_*_frame` functions:
|
||||
|
||||
pub fn make_error_frame(error: &::err::Error) -> Result<BytesMut, Error> {
|
||||
//trace!("make_error_frame");
|
||||
match bincode::serialize(error) {
|
||||
Ok(enc) => {
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
@@ -93,8 +95,75 @@ pub fn make_error_frame(error: &::err::Error) -> Result<BytesMut, Error> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_term_frame() -> BytesMut {
|
||||
//trace!("make_term_frame");
|
||||
pub fn make_log_frame(item: &LogItem) -> Result<BytesMut, Error> {
|
||||
match bincode::serialize(item) {
|
||||
Ok(enc) => {
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&enc);
|
||||
let payload_crc = h.finalize();
|
||||
let mut buf = BytesMut::with_capacity(INMEM_FRAME_HEAD);
|
||||
buf.put_u32_le(INMEM_FRAME_MAGIC);
|
||||
buf.put_u32_le(INMEM_FRAME_ENCID);
|
||||
buf.put_u32_le(LOG_FRAME_TYPE_ID);
|
||||
buf.put_u32_le(enc.len() as u32);
|
||||
buf.put_u32_le(payload_crc);
|
||||
// TODO add padding to align to 8 bytes.
|
||||
buf.put(enc.as_ref());
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&buf);
|
||||
let frame_crc = h.finalize();
|
||||
buf.put_u32_le(frame_crc);
|
||||
Ok(buf)
|
||||
}
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_stats_frame(item: &StatsItem) -> Result<BytesMut, Error> {
|
||||
match bincode::serialize(item) {
|
||||
Ok(enc) => {
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&enc);
|
||||
let payload_crc = h.finalize();
|
||||
let mut buf = BytesMut::with_capacity(INMEM_FRAME_HEAD);
|
||||
buf.put_u32_le(INMEM_FRAME_MAGIC);
|
||||
buf.put_u32_le(INMEM_FRAME_ENCID);
|
||||
buf.put_u32_le(STATS_FRAME_TYPE_ID);
|
||||
buf.put_u32_le(enc.len() as u32);
|
||||
buf.put_u32_le(payload_crc);
|
||||
// TODO add padding to align to 8 bytes.
|
||||
buf.put(enc.as_ref());
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&buf);
|
||||
let frame_crc = h.finalize();
|
||||
buf.put_u32_le(frame_crc);
|
||||
Ok(buf)
|
||||
}
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_range_complete_frame() -> Result<BytesMut, Error> {
|
||||
let enc = [];
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&enc);
|
||||
let payload_crc = h.finalize();
|
||||
let mut buf = BytesMut::with_capacity(INMEM_FRAME_HEAD);
|
||||
buf.put_u32_le(INMEM_FRAME_MAGIC);
|
||||
buf.put_u32_le(INMEM_FRAME_ENCID);
|
||||
buf.put_u32_le(RANGE_COMPLETE_FRAME_TYPE_ID);
|
||||
buf.put_u32_le(enc.len() as u32);
|
||||
buf.put_u32_le(payload_crc);
|
||||
// TODO add padding to align to 8 bytes.
|
||||
buf.put(enc.as_ref());
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&buf);
|
||||
let frame_crc = h.finalize();
|
||||
buf.put_u32_le(frame_crc);
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
pub fn make_term_frame() -> Result<BytesMut, Error> {
|
||||
let enc = [];
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&enc);
|
||||
@@ -111,12 +180,12 @@ pub fn make_term_frame() -> BytesMut {
|
||||
h.update(&buf);
|
||||
let frame_crc = h.finalize();
|
||||
buf.put_u32_le(frame_crc);
|
||||
buf
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
pub fn decode_frame<T>(frame: &InMemoryFrame) -> Result<T, Error>
|
||||
where
|
||||
T: FrameTypeStatic + DeserializeOwned,
|
||||
T: FrameDecodable,
|
||||
{
|
||||
if frame.encid() != INMEM_FRAME_ENCID {
|
||||
return Err(Error::with_msg(format!("unknown encoder id {:?}", frame)));
|
||||
@@ -137,69 +206,69 @@ where
|
||||
"ERROR bincode::deserialize len {} ERROR_FRAME_TYPE_ID",
|
||||
frame.buf().len()
|
||||
);
|
||||
let n = frame.buf().len().min(64);
|
||||
let n = frame.buf().len().min(128);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(e)?
|
||||
}
|
||||
};
|
||||
Ok(T::from_error(k))
|
||||
} else if frame.tyid() == NON_DATA_FRAME_TYPE_ID {
|
||||
error!("TODO NON_DATA_FRAME_TYPE_ID");
|
||||
type TT = Sitemty<crate::scalarevents::ScalarEvents<u32>>;
|
||||
let _k: TT = match bincode::deserialize::<TT>(frame.buf()) {
|
||||
Ok(item) => match item {
|
||||
Ok(StreamItem::DataItem(_)) => {
|
||||
error!(
|
||||
"ERROR bincode::deserialize len {} NON_DATA_FRAME_TYPE_ID but found Ok(StreamItem::DataItem)",
|
||||
frame.buf().len()
|
||||
);
|
||||
let n = frame.buf().len().min(64);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(Error::with_msg_no_trace("NON_DATA_FRAME_TYPE_ID decode error"))?
|
||||
}
|
||||
Ok(StreamItem::Log(k)) => Ok(StreamItem::Log(k)),
|
||||
Ok(StreamItem::Stats(k)) => Ok(StreamItem::Stats(k)),
|
||||
Err(e) => {
|
||||
error!("decode_frame sees error: {e:?}");
|
||||
Err(e)
|
||||
}
|
||||
},
|
||||
} else if frame.tyid() == LOG_FRAME_TYPE_ID {
|
||||
let k: LogItem = match bincode::deserialize(frame.buf()) {
|
||||
Ok(item) => item,
|
||||
Err(e) => {
|
||||
error!(
|
||||
"ERROR bincode::deserialize len {} ERROR_FRAME_TYPE_ID",
|
||||
"ERROR bincode::deserialize len {} LOG_FRAME_TYPE_ID",
|
||||
frame.buf().len()
|
||||
);
|
||||
let n = frame.buf().len().min(64);
|
||||
let n = frame.buf().len().min(128);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(e)?
|
||||
}
|
||||
};
|
||||
Err(Error::with_msg_no_trace("TODO NON_DATA_FRAME_TYPE_ID"))
|
||||
Ok(T::from_log(k))
|
||||
} else if frame.tyid() == STATS_FRAME_TYPE_ID {
|
||||
let k: StatsItem = match bincode::deserialize(frame.buf()) {
|
||||
Ok(item) => item,
|
||||
Err(e) => {
|
||||
error!(
|
||||
"ERROR bincode::deserialize len {} STATS_FRAME_TYPE_ID",
|
||||
frame.buf().len()
|
||||
);
|
||||
let n = frame.buf().len().min(128);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(e)?
|
||||
}
|
||||
};
|
||||
Ok(T::from_stats(k))
|
||||
} else if frame.tyid() == RANGE_COMPLETE_FRAME_TYPE_ID {
|
||||
// There is currently no content in this variant.
|
||||
Ok(T::from_range_complete())
|
||||
} else {
|
||||
let tyid = T::FRAME_TYPE_ID;
|
||||
if frame.tyid() != tyid {
|
||||
return Err(Error::with_msg(format!(
|
||||
Err(Error::with_msg(format!(
|
||||
"type id mismatch expect {:x} found {:x} {:?}",
|
||||
tyid,
|
||||
frame.tyid(),
|
||||
frame
|
||||
)));
|
||||
}
|
||||
match bincode::deserialize(frame.buf()) {
|
||||
Ok(item) => Ok(item),
|
||||
Err(e) => {
|
||||
error!(
|
||||
"ERROR bincode::deserialize len {} tyid {:x}",
|
||||
frame.buf().len(),
|
||||
frame.tyid()
|
||||
);
|
||||
let n = frame.buf().len().min(64);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(e)?
|
||||
)))
|
||||
} else {
|
||||
match bincode::deserialize(frame.buf()) {
|
||||
Ok(item) => Ok(item),
|
||||
Err(e) => {
|
||||
error!(
|
||||
"ERROR bincode::deserialize len {} tyid {:x}",
|
||||
frame.buf().len(),
|
||||
frame.tyid()
|
||||
);
|
||||
let n = frame.buf().len().min(64);
|
||||
let s = String::from_utf8_lossy(&frame.buf()[..n]);
|
||||
error!("frame.buf as string: {:?}", s);
|
||||
Err(e)?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ use crate::numops::BoolNum;
|
||||
use bytes::BytesMut;
|
||||
use chrono::{TimeZone, Utc};
|
||||
use err::Error;
|
||||
use frame::{make_error_frame, make_log_frame, make_range_complete_frame, make_stats_frame};
|
||||
#[allow(unused)]
|
||||
use netpod::log::*;
|
||||
use netpod::timeunits::{MS, SEC};
|
||||
use netpod::{log::Level, AggKind, EventDataReadStats, EventQueryJsonStringFrame, NanoRange, Shape};
|
||||
use netpod::{log::Level, AggKind, EventDataReadStats, NanoRange, Shape};
|
||||
use netpod::{DiskStats, RangeFilterStats, ScalarType};
|
||||
use numops::StringNum;
|
||||
use serde::de::{self, DeserializeOwned, Visitor};
|
||||
@@ -38,12 +39,14 @@ use tokio::io::{AsyncRead, ReadBuf};
|
||||
pub const TERM_FRAME_TYPE_ID: u32 = 0x01;
|
||||
pub const ERROR_FRAME_TYPE_ID: u32 = 0x02;
|
||||
pub const EVENT_QUERY_JSON_STRING_FRAME: u32 = 0x100;
|
||||
pub const EVENT_VALUES_FRAME_TYPE_ID: u32 = 0x500;
|
||||
pub const EVENTS_0D_FRAME_TYPE_ID: u32 = 0x500;
|
||||
pub const MIN_MAX_AVG_DIM_0_BINS_FRAME_TYPE_ID: u32 = 0x700;
|
||||
pub const MIN_MAX_AVG_DIM_1_BINS_FRAME_TYPE_ID: u32 = 0x800;
|
||||
pub const MIN_MAX_AVG_WAVE_BINS: u32 = 0xa00;
|
||||
pub const WAVE_EVENTS_FRAME_TYPE_ID: u32 = 0xb00;
|
||||
pub const NON_DATA_FRAME_TYPE_ID: u32 = 0xc00;
|
||||
pub const LOG_FRAME_TYPE_ID: u32 = 0xc00;
|
||||
pub const STATS_FRAME_TYPE_ID: u32 = 0xd00;
|
||||
pub const RANGE_COMPLETE_FRAME_TYPE_ID: u32 = 0xe00;
|
||||
pub const EVENT_FULL_FRAME_TYPE_ID: u32 = 0x2200;
|
||||
pub const EVENTS_ITEM_FRAME_TYPE_ID: u32 = 0x2300;
|
||||
pub const STATS_EVENTS_FRAME_TYPE_ID: u32 = 0x2400;
|
||||
@@ -166,65 +169,77 @@ pub trait SubFrId {
|
||||
}
|
||||
|
||||
impl SubFrId for u8 {
|
||||
const SUB: u32 = 3;
|
||||
const SUB: u32 = 0x03;
|
||||
}
|
||||
|
||||
impl SubFrId for u16 {
|
||||
const SUB: u32 = 5;
|
||||
const SUB: u32 = 0x05;
|
||||
}
|
||||
|
||||
impl SubFrId for u32 {
|
||||
const SUB: u32 = 8;
|
||||
const SUB: u32 = 0x08;
|
||||
}
|
||||
|
||||
impl SubFrId for u64 {
|
||||
const SUB: u32 = 0xa;
|
||||
const SUB: u32 = 0x0a;
|
||||
}
|
||||
|
||||
impl SubFrId for i8 {
|
||||
const SUB: u32 = 2;
|
||||
const SUB: u32 = 0x02;
|
||||
}
|
||||
|
||||
impl SubFrId for i16 {
|
||||
const SUB: u32 = 4;
|
||||
const SUB: u32 = 0x04;
|
||||
}
|
||||
|
||||
impl SubFrId for i32 {
|
||||
const SUB: u32 = 7;
|
||||
const SUB: u32 = 0x07;
|
||||
}
|
||||
|
||||
impl SubFrId for i64 {
|
||||
const SUB: u32 = 9;
|
||||
const SUB: u32 = 0x09;
|
||||
}
|
||||
|
||||
impl SubFrId for f32 {
|
||||
const SUB: u32 = 0xb;
|
||||
const SUB: u32 = 0x0b;
|
||||
}
|
||||
|
||||
impl SubFrId for f64 {
|
||||
const SUB: u32 = 0xc;
|
||||
const SUB: u32 = 0x0c;
|
||||
}
|
||||
|
||||
impl SubFrId for StringNum {
|
||||
const SUB: u32 = 0xd;
|
||||
const SUB: u32 = 0x0d;
|
||||
}
|
||||
|
||||
impl SubFrId for BoolNum {
|
||||
const SUB: u32 = 0xe;
|
||||
const SUB: u32 = 0x0e;
|
||||
}
|
||||
|
||||
// To be implemented by the data containers, i.e. the T's in Sitemty<T>, e.g. ScalarEvents.
|
||||
// TODO rename this, since it is misleading because it is not meanto to be implemented by Sitemty.
|
||||
pub trait SitemtyFrameType {
|
||||
//const FRAME_TYPE_ID: u32;
|
||||
// TODO check actual usage of this
|
||||
fn frame_type_id(&self) -> u32;
|
||||
}
|
||||
|
||||
pub trait FrameTypeStatic {
|
||||
const FRAME_TYPE_ID: u32;
|
||||
fn from_error(x: ::err::Error) -> Self;
|
||||
}
|
||||
|
||||
// Required for any inner type of Sitemty.
|
||||
pub trait FrameTypeStaticSYC {
|
||||
const FRAME_TYPE_ID: u32;
|
||||
}
|
||||
|
||||
impl<T> FrameTypeStatic for Sitemty<T>
|
||||
where
|
||||
T: FrameTypeStaticSYC,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = <T as FrameTypeStaticSYC>::FRAME_TYPE_ID;
|
||||
}
|
||||
|
||||
// Framable trait objects need some inspection to handle the supposed-to-be common Err ser format:
|
||||
// Meant to be implemented by Sitemty.
|
||||
pub trait FrameType {
|
||||
fn frame_type_id(&self) -> u32;
|
||||
@@ -232,23 +247,6 @@ pub trait FrameType {
|
||||
fn err(&self) -> Option<&::err::Error>;
|
||||
}
|
||||
|
||||
impl FrameTypeStatic for EventQueryJsonStringFrame {
|
||||
const FRAME_TYPE_ID: u32 = EVENT_QUERY_JSON_STRING_FRAME;
|
||||
|
||||
fn from_error(_x: err::Error) -> Self {
|
||||
error!("FrameTypeStatic::from_error todo");
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FrameTypeStatic> FrameTypeStatic for Sitemty<T> {
|
||||
const FRAME_TYPE_ID: u32 = <T as FrameTypeStatic>::FRAME_TYPE_ID;
|
||||
|
||||
fn from_error(e: err::Error) -> Self {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FrameType for Box<T>
|
||||
where
|
||||
T: FrameType,
|
||||
@@ -268,11 +266,10 @@ where
|
||||
|
||||
impl<T> FrameType for Sitemty<T>
|
||||
where
|
||||
// SitemtyFrameType
|
||||
T: FrameTypeStatic,
|
||||
T: FrameTypeStaticSYC,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<T as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<T as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
|
||||
fn is_err(&self) -> bool {
|
||||
@@ -290,20 +287,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl FrameType for EventQueryJsonStringFrame {
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
}
|
||||
|
||||
fn is_err(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn err(&self) -> Option<&::err::Error> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl SitemtyFrameType for Box<dyn TimeBinned> {
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
self.as_time_binnable_dyn().frame_type_id()
|
||||
@@ -316,7 +299,6 @@ impl SitemtyFrameType for Box<dyn EventsDyn> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do we need Send here?
|
||||
pub trait Framable {
|
||||
fn make_frame(&self) -> Result<BytesMut, Error>;
|
||||
}
|
||||
@@ -343,10 +325,10 @@ where
|
||||
let frame_type_id = k.frame_type_id();
|
||||
make_frame_2(self, frame_type_id)
|
||||
}
|
||||
_ => {
|
||||
let frame_type_id = NON_DATA_FRAME_TYPE_ID;
|
||||
make_frame_2(self, frame_type_id)
|
||||
}
|
||||
Ok(StreamItem::DataItem(RangeCompletableItem::RangeComplete)) => make_range_complete_frame(),
|
||||
Ok(StreamItem::Log(item)) => make_log_frame(item),
|
||||
Ok(StreamItem::Stats(item)) => make_stats_frame(item),
|
||||
Err(e) => make_error_frame(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,6 +342,41 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FrameDecodable: FrameTypeStatic + DeserializeOwned {
|
||||
fn from_error(e: ::err::Error) -> Self;
|
||||
fn from_log(item: LogItem) -> Self;
|
||||
fn from_stats(item: StatsItem) -> Self;
|
||||
fn from_range_complete() -> Self;
|
||||
}
|
||||
|
||||
impl<T> FrameDecodable for Sitemty<T>
|
||||
where
|
||||
T: FrameTypeStaticSYC + DeserializeOwned,
|
||||
{
|
||||
fn from_error(e: err::Error) -> Self {
|
||||
Err(e)
|
||||
}
|
||||
|
||||
fn from_log(item: LogItem) -> Self {
|
||||
Ok(StreamItem::Log(item))
|
||||
}
|
||||
|
||||
fn from_stats(item: StatsItem) -> Self {
|
||||
Ok(StreamItem::Stats(item))
|
||||
}
|
||||
|
||||
fn from_range_complete() -> Self {
|
||||
Ok(StreamItem::DataItem(RangeCompletableItem::RangeComplete))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct EventQueryJsonStringFrame(pub String);
|
||||
|
||||
impl FrameTypeStaticSYC for EventQueryJsonStringFrame {
|
||||
const FRAME_TYPE_ID: u32 = EVENT_QUERY_JSON_STRING_FRAME;
|
||||
}
|
||||
|
||||
pub trait EventsNodeProcessor: Send + Unpin {
|
||||
type Input;
|
||||
type Output: Send + Unpin + DeserializeOwned + WithTimestamps + TimeBinnableType + ByteEstimate;
|
||||
@@ -476,8 +493,9 @@ pub trait TimeBinnableType:
|
||||
+ NewEmpty
|
||||
+ Appendable
|
||||
+ Serialize
|
||||
+ DeserializeOwned
|
||||
+ ReadableFromFile
|
||||
+ FrameTypeStatic
|
||||
+ FrameTypeStaticSYC
|
||||
{
|
||||
type Output: TimeBinnableType;
|
||||
type Aggregator: TimeBinnableTypeAggregator<Input = Self, Output = Self::Output> + Send + Unpin;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector};
|
||||
use crate::{
|
||||
pulse_offs_from_abs, ts_offs_from_abs, Appendable, ByteEstimate, Clearable, EventAppendable, EventsDyn,
|
||||
FilterFittingInside, Fits, FitsInside, FrameTypeStatic, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv,
|
||||
FilterFittingInside, Fits, FitsInside, FrameTypeStaticSYC, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv,
|
||||
ReadableFromFile, SitemtyFrameType, TimeBinnableDyn, TimeBinnableType, TimeBinnableTypeAggregator, TimeBinnerDyn,
|
||||
WithLen, WithTimestamps,
|
||||
};
|
||||
@@ -52,17 +52,11 @@ impl<NTY> ScalarEvents<NTY> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for ScalarEvents<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for ScalarEvents<NTY>
|
||||
where
|
||||
NTY: NumOps,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::EVENT_VALUES_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
// TODO this method should not be used, remove.
|
||||
error!("impl<NTY> FrameTypeStatic for ScalarEvents<NTY>");
|
||||
panic!()
|
||||
}
|
||||
const FRAME_TYPE_ID: u32 = crate::EVENTS_0D_FRAME_TYPE_ID + NTY::SUB;
|
||||
}
|
||||
|
||||
impl<NTY> SitemtyFrameType for ScalarEvents<NTY>
|
||||
@@ -70,7 +64,7 @@ where
|
||||
NTY: NumOps,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::streams::{Collectable, Collector};
|
||||
use crate::{
|
||||
ts_offs_from_abs, Appendable, ByteEstimate, Clearable, EventAppendable, FilterFittingInside, Fits, FitsInside,
|
||||
FrameTypeStatic, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile, SitemtyFrameType,
|
||||
FrameTypeStaticSYC, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile, SitemtyFrameType,
|
||||
TimeBinnableType, TimeBinnableTypeAggregator, WithLen, WithTimestamps,
|
||||
};
|
||||
use err::Error;
|
||||
@@ -17,18 +17,13 @@ pub struct StatsEvents {
|
||||
pub pulses: Vec<u64>,
|
||||
}
|
||||
|
||||
impl FrameTypeStatic for StatsEvents {
|
||||
impl FrameTypeStaticSYC for StatsEvents {
|
||||
const FRAME_TYPE_ID: u32 = crate::STATS_EVENTS_FRAME_TYPE_ID;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
// TODO remove usage of this
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl SitemtyFrameType for StatsEvents {
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::xbinnedscalarevents::XBinnedScalarEvents;
|
||||
use crate::xbinnedwaveevents::XBinnedWaveEvents;
|
||||
use crate::{
|
||||
Appendable, ByteEstimate, Clearable, EventAppendable, EventsDyn, EventsNodeProcessor, FilterFittingInside, Fits,
|
||||
FitsInside, FrameTypeStatic, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile,
|
||||
FitsInside, FrameTypeStaticSYC, NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile,
|
||||
SitemtyFrameType, SubFrId, TimeBinnableDyn, TimeBinnableType, TimeBinnableTypeAggregator, WithLen, WithTimestamps,
|
||||
};
|
||||
use err::Error;
|
||||
@@ -40,16 +40,11 @@ impl<NTY> WaveEvents<NTY> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for WaveEvents<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for WaveEvents<NTY>
|
||||
where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::WAVE_EVENTS_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
// TODO remove this method.
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> SitemtyFrameType for WaveEvents<NTY>
|
||||
@@ -57,7 +52,7 @@ where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::binsdim0::MinMaxAvgDim0Bins;
|
||||
use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector};
|
||||
use crate::{
|
||||
ts_offs_from_abs, Appendable, ByteEstimate, Clearable, FilterFittingInside, Fits, FitsInside, FrameTypeStatic,
|
||||
ts_offs_from_abs, Appendable, ByteEstimate, Clearable, FilterFittingInside, Fits, FitsInside, FrameTypeStaticSYC,
|
||||
NewEmpty, PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile, SitemtyFrameType, SubFrId, TimeBinnableType,
|
||||
TimeBinnableTypeAggregator, WithLen, WithTimestamps,
|
||||
};
|
||||
@@ -23,15 +23,11 @@ pub struct XBinnedScalarEvents<NTY> {
|
||||
pub avgs: Vec<f32>,
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for XBinnedScalarEvents<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for XBinnedScalarEvents<NTY>
|
||||
where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::X_BINNED_SCALAR_EVENTS_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> SitemtyFrameType for XBinnedScalarEvents<NTY>
|
||||
@@ -39,7 +35,7 @@ where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::binsdim1::MinMaxAvgDim1Bins;
|
||||
use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector};
|
||||
use crate::{
|
||||
Appendable, ByteEstimate, Clearable, FilterFittingInside, Fits, FitsInside, FrameTypeStatic, NewEmpty,
|
||||
Appendable, ByteEstimate, Clearable, FilterFittingInside, Fits, FitsInside, FrameTypeStaticSYC, NewEmpty,
|
||||
PushableIndex, RangeOverlapInfo, ReadPbv, ReadableFromFile, SitemtyFrameType, SubFrId, TimeBinnableType,
|
||||
TimeBinnableTypeAggregator, WithLen, WithTimestamps,
|
||||
};
|
||||
@@ -23,15 +23,11 @@ pub struct XBinnedWaveEvents<NTY> {
|
||||
pub avgs: Vec<Vec<f32>>,
|
||||
}
|
||||
|
||||
impl<NTY> FrameTypeStatic for XBinnedWaveEvents<NTY>
|
||||
impl<NTY> FrameTypeStaticSYC for XBinnedWaveEvents<NTY>
|
||||
where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
const FRAME_TYPE_ID: u32 = crate::X_BINNED_WAVE_EVENTS_FRAME_TYPE_ID + NTY::SUB;
|
||||
|
||||
fn from_error(_: err::Error) -> Self {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO use a generic impl for this:
|
||||
@@ -40,7 +36,7 @@ where
|
||||
NTY: SubFrId,
|
||||
{
|
||||
fn frame_type_id(&self) -> u32 {
|
||||
<Self as FrameTypeStatic>::FRAME_TYPE_ID
|
||||
<Self as FrameTypeStaticSYC>::FRAME_TYPE_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user