rust-aec
Pure Rust decoder for CCSDS 121.0-B-3 Adaptive Entropy Coding (AEC), with an initial focus on GRIB2 Data Representation Template 5.0 = 42 (CCSDS/AEC).
This crate was created to avoid native libaec build friction (C/CMake/bindgen) on Windows while keeping byte-for-byte compatibility.
Repository: https://github.com/hkwk/rust-aec
Visual comparison
| rust-aec | libaec |
|---|---|
![]() |
![]() |
Status
- Decoder implemented for the subset needed by GRIB2 template 5.0=42.
- Validated against
libaecusing an “oracle” byte-for-byte comparison on real GRIB2 data (in the upstream workspace that hosts this crate).
What this crate provides
decode(input, params, output_samples) -> Result<Vec<u8>, AecError>: decode an AEC bitstream into packed sample bytes.AecParams/AecFlags: minimal parameter set aligned withlibaec’saec_stream.flags_from_grib2_ccsds_flags(ccsds_flags: u8): helper for GRIB2 template 5.42.
Non-goals (for now)
- Full coverage of every possible
libaecflag combination. - Streaming / incremental decode API.
- Complete GRIB2 decoding pipeline (bitmap/reduced grids etc.). This crate only decodes the AEC payload.
Usage
Decode a GRIB2 template 42 payload
You need:
payload: the GRIB2 Section 7 payload (the CCSDS/AEC bitstream)num_points: number of decoded samples (GRIB2:section5.num_encoded_points)bits_per_sample,block_size,rsi,ccsds_flags: from GRIB2 template 5.42
use ;
let params = new;
let decoded: = decode?;
decoded is a byte vector of length num_points * bytes_per_sample, where bytes_per_sample = ceil(bits_per_sample/8).
Byte order is controlled by the MSB flag.
Example program
This crate ships a small example binary:
cargo run -p rust-aec --example decode_aec_payload -- --payload aec_payload.bin --samples 1038240
API notes
- When
AecFlags::DATA_PREPROCESSis set, the output bytes are the reconstructed sample values (inverse preprocessing applied). - When preprocessing is not set, the output bytes represent the raw coded values.
License
MIT. See LICENSE.
Related
- The host workspace includes a GRIB2 preview integration that can fall back to
rust-aecfor template 42.

