pamoja-codec
Serialization and framing for pamoja: pluggable wire formats behind a common Codec trait.
Pluggable serialization for pamoja payloads.
Concrete wire formats - CBOR for constrained devices, Protocol Buffers, JSON,
or raw framing - implement the [Codec] trait. This crate defines the trait
and provides serde-based implementations behind feature flags:
- [
CborCodec] (featurecbor, on by default) - compact binary framing for constrained devices and metered links. - [
JsonCodec] (featurejson, on by default) - human-readable framing for interop and debugging. - [
BytesCodec] (always available) - a no-op codec that carries raw bytes.
For metered links it also packs batches of samples into far fewer bytes:
[encode_deltas] delta-encodes a series of integers, and [Quantizer] rounds
f32 readings to a fixed precision and delta-encodes them.
Examples
A little-endian codec for u32 values:
use Codec;
use ;
;
let codec = LeU32;
let encoded = codec.encode.unwrap;
assert_eq!;
trait Codec
Encodes and decodes values of type T to and from byte buffers.
A codec is the bridge between in-memory values and the bytes carried by a
Transport or persisted by a
Store.
fn encode(&self, value: &T) -> Result <Vec <u8>>
Encodes a value into a byte buffer.
Arguments
value- the value to serialize.
Returns
A byte buffer containing the encoded representation of value.
Errors
Returns Error::Codec if the value cannot
be encoded.
fn decode(&self, bytes: &[u8]) -> Result <T>
Decodes a value from a byte buffer.
Arguments
bytes- the encoded representation to deserialize.
Returns
The value decoded from bytes.
Errors
Returns Error::Codec if bytes is not a
valid encoding of T.
License
MIT - part of the pamoja workspace: one memory-safe Rust core with bindings for every language.