Back to Docs
⚙️

API Reference

Quick reference for ALEC's main types and methods. For complete documentation with examples, see docs.rs/alec.

alec::Encoder

Full docs

Compresses sensor values using delta encoding and learned patterns.

Method Returns Description
new(ctx) Encoder Create encoder with shared context
with_config(ctx, config) Encoder Create encoder with custom configuration
encode(value, priority) EncodedMessage Encode single value
encode_batch(values, priority) EncodedMessage Encode multiple values

alec::Decoder

Full docs

Decompresses ALEC messages back to original values.

Method Returns Description
new(ctx) Decoder Create decoder with shared context
decode(bytes) Result<f64> Decode single message
decode_batch(bytes) Result<Vec<f64>> Decode batch message

alec::Context

Full docs

Shared state between encoder and decoder. Must be synchronized.

Method Returns Description
new() Context Create empty context
from_bytes(bytes) Result<Context> Deserialize context
to_bytes() Vec<u8> Serialize context for sync
reset() () Clear context state

alec::Priority

Full docs

Message priority levels for classification and routing.

Method Returns Description
P1 Critical - safety threshold breach
P2 Anomaly - unexpected deviation
P3 Important - significant change
P4 Normal - new baseline
P5 Routine - predictable/repeated
Auto Automatic classification

alec::Config

Full docs

Configuration builder for encoder behavior.

Method Returns Description
builder() ConfigBuilder Start building config
critical_threshold(f64) ConfigBuilder Set P1 threshold
anomaly_sigma(f64) ConfigBuilder Set P2 std deviation threshold
max_message_size(usize) ConfigBuilder Limit output size
build() Config Finalize configuration

Error Handling

Error Cause Recovery
DecodeError::InvalidHeader Corrupted or truncated message Request retransmission
DecodeError::ContextMismatch Encoder/decoder out of sync Resync context or reset
EncodeError::ValueOutOfRange Value exceeds representable range Use raw encoding mode
EncodeError::MessageTooLarge Output exceeds max_message_size Split into smaller batches

Complete Documentation

For full API documentation with examples, type signatures, and implementation details:

View on docs.rs