pub struct Quantizer { /* private fields */ }Expand description
Packs a batch of f32 readings into a compact byte form for a metered link.
A quantizer rounds each reading to a fixed precision - set by the scale, where
100.0 keeps two decimal places - turns it into an integer, and delta-encodes the
batch with encode_deltas. This is lossy by exactly the rounding step, which is
the right trade for a cheap sensor on an expensive link: a fridge temperature to
the nearest hundredth of a degree costs a byte or two per sample instead of four.
The same scale must be used to encode and decode.
§Examples
use pamoja_codec::Quantizer;
// Quantize to 0.1 precision and pack a slowly-rising series.
let quantizer = Quantizer::new(10.0);
let readings = [20.0, 20.1, 20.2, 20.3];
let packed = quantizer.encode(&readings);
assert!(packed.len() < readings.len() * 4); // smaller than four bytes per reading
let restored = quantizer.decode(&packed).unwrap();
assert!((restored[2] - 20.2).abs() < 0.05);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Quantizer
impl RefUnwindSafe for Quantizer
impl Send for Quantizer
impl Sync for Quantizer
impl Unpin for Quantizer
impl UnsafeUnpin for Quantizer
impl UnwindSafe for Quantizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more