Table of Contents

Class Quantizer

Namespace
Pamoja.Codec
Assembly
Pamoja.Codec.dll

Packs float readings to a fixed precision, for a link charging per byte.

public sealed class Quantizer
Inheritance
Quantizer
Inherited Members

Examples

var quantizer = new Quantizer(100); // keep two decimal places
byte[] packed = quantizer.Encode(new[] { 20.0f, 20.1f, 20.2f });
float[] readings = quantizer.Decode(packed); // to within 0.01

Remarks

Full-precision floats are wasteful when a reading is only meaningful to two decimal places. Rounding to that precision and delta-encoding the batch turns a day of samples into something a metered link can afford.

Constructors

Quantizer(float)

Creates a quantizer at the given precision.

public Quantizer(float scale)

Parameters

scale float

The multiplier applied before rounding; 100 keeps two decimal places. Must be positive and finite.

Exceptions

ArgumentOutOfRangeException

scale is not positive and finite.

Methods

Decode(ReadOnlySpan<byte>)

Unpacks a batch, to within this quantizer's precision.

public float[] Decode(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The encoding produced by Encode(ReadOnlySpan<float>) at the same scale.

Returns

float[]

The readings, in order.

Exceptions

PamojaException

The buffer is malformed.

Encode(ReadOnlySpan<float>)

Quantizes and packs a batch of readings.

public byte[] Encode(ReadOnlySpan<float> readings)

Parameters

readings ReadOnlySpan<float>

The readings, in order.

Returns

byte[]

The packed encoding.

Exceptions

PamojaException

The native call failed.