Deliver events from LTS
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::frame::{make_frame, make_frame_2};
|
||||
use crate::minmaxavgbins::MinMaxAvgBins;
|
||||
use crate::numops::NumOps;
|
||||
use crate::streams::{Collectable, Collector};
|
||||
@@ -5,6 +6,7 @@ use crate::{
|
||||
ts_offs_from_abs, Appendable, FilterFittingInside, Fits, FitsInside, PushableIndex, RangeOverlapInfo, ReadPbv,
|
||||
ReadableFromFile, SitemtyFrameType, TimeBinnableType, TimeBinnableTypeAggregator, WithLen, WithTimestamps,
|
||||
};
|
||||
use bytes::BytesMut;
|
||||
use err::Error;
|
||||
use netpod::NanoRange;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -40,6 +40,36 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// TODO decide for either make_frame or make_frame_2
|
||||
pub fn make_frame_2<FT>(item: &FT, fty: u32) -> Result<BytesMut, Error>
|
||||
where
|
||||
FT: Serialize,
|
||||
{
|
||||
match bincode::serialize(item) {
|
||||
Ok(enc) => {
|
||||
if enc.len() > u32::MAX as usize {
|
||||
return Err(Error::with_msg(format!("too long payload {}", enc.len())));
|
||||
}
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&enc);
|
||||
let payload_crc = h.finalize();
|
||||
let mut buf = BytesMut::with_capacity(enc.len() + INMEM_FRAME_HEAD);
|
||||
buf.put_u32_le(INMEM_FRAME_MAGIC);
|
||||
buf.put_u32_le(INMEM_FRAME_ENCID);
|
||||
buf.put_u32_le(fty);
|
||||
buf.put_u32_le(enc.len() as u32);
|
||||
buf.put_u32_le(payload_crc);
|
||||
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_term_frame() -> BytesMut {
|
||||
let mut h = crc32fast::Hasher::new();
|
||||
h.update(&[]);
|
||||
|
||||
123
items/src/lib.rs
123
items/src/lib.rs
@@ -1,4 +1,5 @@
|
||||
use crate::eventvalues::EventValues;
|
||||
use crate::frame::make_frame_2;
|
||||
use crate::numops::BoolNum;
|
||||
use bytes::BytesMut;
|
||||
use chrono::{TimeZone, Utc};
|
||||
@@ -212,134 +213,20 @@ pub trait Framable: Send {
|
||||
fn make_frame(&self) -> Result<BytesMut, Error>;
|
||||
}
|
||||
|
||||
// TODO need als Framable for those types defined in other crates.
|
||||
// TODO need also Framable for those types defined in other crates.
|
||||
impl<T> Framable for Sitemty<T>
|
||||
where
|
||||
T: SitemtyFrameType + Send,
|
||||
T: SitemtyFrameType + Serialize + Send,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
todo!()
|
||||
T::FRAME_TYPE_ID
|
||||
}
|
||||
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
todo!()
|
||||
make_frame_2(self, T::FRAME_TYPE_ID)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
impl Framable for Sitemty<serde_json::Value> {
|
||||
fn typeid(&self) -> u32 {
|
||||
EventQueryJsonStringFrame::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Framable for Result<StreamItem<RangeCompletableItem<MinMaxAvgScalarBinBatch>>, Error> {
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Framable for Result<StreamItem<RangeCompletableItem<MinMaxAvgScalarEventBatch>>, Error> {
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Result<StreamItem<RangeCompletableItem<EventValues<NTY>>>, err::Error>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Result<StreamItem<RangeCompletableItem<XBinnedScalarEvents<NTY>>>, err::Error>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Sitemty<MinMaxAvgBins<NTY>>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Sitemty<WaveEvents<NTY>>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Sitemty<XBinnedWaveEvents<NTY>>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Sitemty<MinMaxAvgWaveBins<NTY>>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY> Framable for Sitemty<MinMaxAvgDim1Bins<NTY>>
|
||||
where
|
||||
NTY: NumOps + Serialize,
|
||||
{
|
||||
fn typeid(&self) -> u32 {
|
||||
Self::FRAME_TYPE_ID
|
||||
}
|
||||
fn make_frame(&self) -> Result<BytesMut, Error> {
|
||||
make_frame(self)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub trait EventsNodeProcessor: Send + Unpin {
|
||||
type Input;
|
||||
type Output: Send + Unpin + DeserializeOwned + WithTimestamps + TimeBinnableType;
|
||||
|
||||
Reference in New Issue
Block a user