Skip to main content

DataNormalizer

Trait DataNormalizer 

Source
pub trait DataNormalizer {
    type Frame: Debug + Clone + PartialEq;

    // Required method
    fn normalize(&self, frame: &Self::Frame) -> Result<DataPoint, Error>;

    // Provided methods
    fn normalize_all(
        &self,
        frame: &Self::Frame,
    ) -> Result<Vec<DataPoint>, Error> { ... }
    fn normalize_batch(
        &self,
        frames: &[Self::Frame],
    ) -> Result<Vec<DataPoint>, Error> { ... }
}
Expand description

Normalizes a parsed protocol frame into a TUP DataPoint.

§Examples

use tpt_protocol_core::{DataNormalizer, Error};
use tpt_protocol_tup::{DataPoint, Quality, SourceProtocol, TupValue};

struct MyNormalizer;

impl DataNormalizer for MyNormalizer {
    type Frame = f64;

    fn normalize(&self, frame: &Self::Frame) -> Result<DataPoint, Error> {
        Ok(DataPoint::new(
            SourceProtocol::Modbus, "dev", "point",
            1000, TupValue::Float(*frame), Quality::Good,
        ))
    }
}

let n = MyNormalizer;
let dp = n.normalize(&42.5).unwrap();
assert_eq!(dp.device_id, "dev");

Normalizers have no clock, so they leave timestamp at 0 when the source carries no time. The ingesting caller stamps it. The daemon’s replay path does this with the current time.

Required Associated Types§

Required Methods§

Source

fn normalize(&self, frame: &Self::Frame) -> Result<DataPoint, Error>

Provided Methods§

Source

fn normalize_all(&self, frame: &Self::Frame) -> Result<Vec<DataPoint>, Error>

Every data point one frame carries. A frame can hold several values (for example, a Sparkplug payload with many metrics).

The default is the single point from normalize. Override it when a frame fans out.

Source

fn normalize_batch( &self, frames: &[Self::Frame], ) -> Result<Vec<DataPoint>, Error>

Normalizes a batch of frames into one vector of DataPoints. Each frame contributes all of its points, from normalize_all.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§