CCSDS 124.0-B-1 C++ 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
ccsds124 Namespace Reference

Namespaces

namespace  detail
 Pre-computed COUNT encodings for values 1-33.
 

Classes

class  BitBuffer
 Variable-length bit buffer with static allocation. More...
 
class  BitReader
 Sequential bit reader for compressed data. More...
 
class  BitVector
 Fixed-length bit vector with compile-time size. More...
 
class  Ccsds124Exception
 Base exception for CCSDS 124.0-B-1 errors. More...
 
class  Compressor
 CCSDS 124.0-B-1 compressor with static memory allocation. More...
 
struct  CompressParams
 Compression parameters for a single packet. More...
 
class  Decompressor
 CCSDS 124.0-B-1 decompressor with static memory allocation. More...
 
class  InvalidArgumentException
 Exception for invalid arguments. More...
 
class  InvalidDataException
 Exception for invalid/corrupted data. More...
 
class  OverflowException
 Exception for buffer overflow. More...
 
class  UnderflowException
 Exception for buffer underflow. More...
 

Typedefs

using word_t = std::uint32_t
 32-bit word type for bit vector storage (matches C implementation)
 

Enumerations

enum class  Error {
  Ok = 0 , InvalidArg = -1 , Overflow = -2 , Underflow = -3 ,
  InvalidData = -4
}
 Error codes for error-code-based error handling. More...
 

Functions

template<std::size_t N>
Error compress (const std::uint8_t *input_data, std::size_t input_size, std::uint8_t *output_buffer, std::size_t output_buffer_size, std::size_t &output_size, std::uint8_t robustness=0, int pt_limit=0, int ft_limit=0, int rt_limit=0) noexcept
 Compress multi-packet data stream.
 
template<std::size_t N>
Error decompress (const std::uint8_t *input_data, std::size_t input_size, std::uint8_t *output_buffer, std::size_t output_buffer_size, std::size_t &output_size, std::uint8_t robustness=0) noexcept
 Decompress multi-packet data stream.
 
const char * version () noexcept
 Get library version.
 
Error count_decode (BitReader &reader, std::uint32_t &value) noexcept
 Counter decoding (inverse of CCSDS Section 5.2.2, Equation 9).
 
template<std::size_t N>
Error rle_decode (BitReader &reader, BitVector< N > &result) noexcept
 Run-length decoding (inverse of CCSDS Section 5.2.3, Equation 10).
 
template<std::size_t N>
Error bit_insert (BitReader &reader, BitVector< N > &data, const BitVector< N > &mask) noexcept
 Bit insertion (inverse of CCSDS Section 5.2.4, Equation 11).
 
template<std::size_t N>
Error bit_insert_forward (BitReader &reader, BitVector< N > &data, const BitVector< N > &mask) noexcept
 Bit insertion with forward order.
 
template<std::size_t MaxBytes>
Error count_encode (BitBuffer< MaxBytes > &output, std::uint32_t A) noexcept
 Counter encoding (CCSDS Section 5.2.2, Equation 9).
 
template<std::size_t MaxBytes, std::size_t N>
Error rle_encode (BitBuffer< MaxBytes > &output, const BitVector< N > &input) noexcept
 Run-length encoding (CCSDS Section 5.2.3, Equation 10).
 
template<std::size_t MaxBytes, std::size_t N>
Error bit_extract (BitBuffer< MaxBytes > &output, const BitVector< N > &data, const BitVector< N > &mask) noexcept
 Bit extraction in reverse order (CCSDS Section 5.2.4, Equation 11).
 
template<std::size_t MaxBytes, std::size_t N>
Error bit_extract_forward (BitBuffer< MaxBytes > &output, const BitVector< N > &data, const BitVector< N > &mask) noexcept
 Bit extraction in forward order.
 
template<std::size_t MaxBytes, std::size_t N1, std::size_t N2>
Error bit_extract (BitBuffer< MaxBytes > &output, const BitVector< N1 > &data, const BitVector< N2 > &mask) noexcept
 Bit extraction with different length vectors (for flexibility).
 
const char * error_string (Error error) noexcept
 Get error message for error code.
 
template<std::size_t N>
void update_build (BitVector< N > &build, const BitVector< N > &input, const BitVector< N > &prev_input, bool new_mask_flag, std::size_t t) noexcept
 Update build vector (CCSDS Equation 6).
 
template<std::size_t N>
void update_mask (BitVector< N > &mask, const BitVector< N > &input, const BitVector< N > &prev_input, const BitVector< N > &build_prev, bool new_mask_flag) noexcept
 Update mask vector (CCSDS Equation 7).
 
template<std::size_t N>
void compute_change (BitVector< N > &change, const BitVector< N > &mask, const BitVector< N > &prev_mask, std::size_t t) noexcept
 Compute change vector (CCSDS Equation 8).
 

Variables

constexpr int VERSION_MAJOR = 1
 
constexpr int VERSION_MINOR = 0
 
constexpr int VERSION_PATCH = 0
 
constexpr std::size_t MAX_PACKET_LENGTH = 65535U
 
constexpr std::size_t MAX_PACKET_BYTES = (MAX_PACKET_LENGTH + 7U) / 8U
 
constexpr std::size_t MAX_ROBUSTNESS = 7U
 
constexpr std::size_t MAX_HISTORY = 16U
 
constexpr std::size_t MAX_VT_HISTORY = 16U
 
constexpr std::size_t MAX_OUTPUT_BYTES = MAX_PACKET_BYTES * 6U
 
constexpr std::size_t BITS_PER_WORD = 32U
 

Detailed Description

This module provides a dynamically-growing bit buffer for constructing compressed output streams. Bits are appended sequentially using MSB-first ordering as required by CCSDS 124.0-B-1.

Bit Ordering
Bits are appended MSB-first within each byte:
  • First bit appended goes to bit position 7
  • Second bit goes to position 6, etc.
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

The bit reader provides stateful bit-level access to compressed packet data, reading MSB-first within each byte.

Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

This module provides fixed-length bit vector operations optimized for CCSDS 124.0-B-1 compression. Uses 32-bit words with big-endian byte packing to match ESA/ESOC reference implementation.

Bit Numbering Convention (CCSDS 124.0-B-1 Section 1.6.1)
  • Bit 0 = MSB (transmitted first)
  • Bit N-1 = LSB (transmitted last)
Word Packing (Big-Endian)
Within each 32-bit word:
  • Bit 0 at position 31 of word 0 (most significant)
  • Bit 31 at position 0 of word 0
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Provides high-level compress() and decompress() functions for bulk data processing, suitable for file-level operations.

Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Implements CCSDS 124.0-B-1 Section 5.3 (Encoding Step):

  • Compressor initialization and state management
  • Main compression algorithm
  • Output packet encoding: o_t = h_t || q_t || u_t
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

CCSDS 124.0-B-1: Robust Compression of Fixed-Length Housekeeping Data

Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Implements CCSDS 124.0-B-1 decoding (inverse of Section 5.2):

  • Counter Decoding (COUNT) - inverse of Section 5.2.2, Equation 9
  • Run-Length Decoding (RLE) - inverse of Section 5.2.3, Equation 10
  • Bit Insertion - inverse of Section 5.2.4, Equation 11
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Implements CCSDS 124.0-B-1 decompression (inverse of Section 5.3):

  • Packet decompression and mask reconstruction
  • Full round-trip support with Compressor
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Implements CCSDS 124.0-B-1 Section 5.2 encoding schemes:

  • Counter Encoding (COUNT) - Section 5.2.2, Table 5-1, Equation 9
  • Run-Length Encoding (RLE) - Section 5.2.3, Equation 10
  • Bit Extraction (BE) - Section 5.2.4, Equation 11
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Implements CCSDS 124.0-B-1 Section 4 (Mask Update):

  • Build Vector Update (Equation 6)
  • Mask Vector Update (Equation 7)
  • Change Vector Computation (Equation 8)
Authors
Georges Labreche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.m
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

Enumeration Type Documentation

◆ Error

enum class ccsds124::Error
strong

Error codes for error-code-based error handling.

Used when exceptions are disabled (CCSDS124_NO_EXCEPTIONS=1).

Enumerator
Ok 

Success.

InvalidArg 

Invalid argument.

Overflow 

Buffer overflow.

Underflow 

Buffer underflow (not enough data)

InvalidData 

Invalid/corrupted data.

Definition at line 29 of file error.hpp.

Function Documentation

◆ bit_extract() [1/2]

template<std::size_t MaxBytes, std::size_t N>
Error ccsds124::bit_extract ( BitBuffer< MaxBytes > &  output,
const BitVector< N > &  data,
const BitVector< N > &  mask 
)
noexcept

Bit extraction in reverse order (CCSDS Section 5.2.4, Equation 11).

BE(a, b) = a_{g_{H(b)-1}} ∥ ... ∥ a_{g₁} ∥ a_{g₀}

Template Parameters
MaxBytesBitBuffer capacity
NBitVector length
Parameters
outputBit buffer to append extracted bits
dataSource data vector
maskMask indicating which bits to extract
Returns
Error::Ok on success

Definition at line 167 of file encoder.hpp.

References Ok.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ bit_extract() [2/2]

template<std::size_t MaxBytes, std::size_t N1, std::size_t N2>
Error ccsds124::bit_extract ( BitBuffer< MaxBytes > &  output,
const BitVector< N1 > &  data,
const BitVector< N2 > &  mask 
)
noexcept

Bit extraction with different length vectors (for flexibility).

Definition at line 286 of file encoder.hpp.

References InvalidArg.

◆ bit_extract_forward()

template<std::size_t MaxBytes, std::size_t N>
Error ccsds124::bit_extract_forward ( BitBuffer< MaxBytes > &  output,
const BitVector< N > &  data,
const BitVector< N > &  mask 
)
noexcept

Bit extraction in forward order.

Used specifically for kₜ component encoding where forward order is required.

Template Parameters
MaxBytesBitBuffer capacity
NBitVector length
Parameters
outputBit buffer to append extracted bits
dataSource data vector
maskMask indicating which bits to extract
Returns
Error::Ok on success

Definition at line 234 of file encoder.hpp.

References ccsds124::detail::extract_msb(), and Ok.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ bit_insert()

template<std::size_t N>
Error ccsds124::bit_insert ( BitReader reader,
BitVector< N > &  data,
const BitVector< N > &  mask 
)
noexcept

Bit insertion (inverse of CCSDS Section 5.2.4, Equation 11).

Inserts bits from reader at positions where mask has '1' bits. This is the inverse of bit_extract.

Template Parameters
NBitVector length
Parameters
readerBit reader with bits to insert
[in,out]dataData vector to insert bits into
maskMask indicating where to insert
Returns
Error::Ok on success

Definition at line 175 of file decoder.hpp.

References ccsds124::detail::extract_lsb(), Ok, and Underflow.

Referenced by ccsds124::Decompressor< N >::decompress_packet().

◆ bit_insert_forward()

template<std::size_t N>
Error ccsds124::bit_insert_forward ( BitReader reader,
BitVector< N > &  data,
const BitVector< N > &  mask 
)
noexcept

Bit insertion with forward order.

Inserts bits from reader at positions where mask has '1' bits, in forward order (MSB to LSB).

Template Parameters
NBitVector length
Parameters
readerBit reader with bits to insert
[in,out]dataData vector to insert bits into
maskMask indicating where to insert
Returns
Error::Ok on success

Definition at line 227 of file decoder.hpp.

References ccsds124::detail::extract_msb(), Ok, and Underflow.

◆ compress()

template<std::size_t N>
Error ccsds124::compress ( const std::uint8_t *  input_data,
std::size_t  input_size,
std::uint8_t *  output_buffer,
std::size_t  output_buffer_size,
std::size_t &  output_size,
std::uint8_t  robustness = 0,
int  pt_limit = 0,
int  ft_limit = 0,
int  rt_limit = 0 
)
noexcept

Compress multi-packet data stream.

Compresses input data as a sequence of fixed-size packets using CCSDS 124.0-B-1 algorithm.

Template Parameters
NPacket length in bits
Parameters
input_dataInput data bytes
input_sizeInput size in bytes (must be multiple of packet size)
output_bufferOutput buffer for compressed data
output_buffer_sizeMaximum output buffer size
[out]output_sizeActual compressed output size
robustnessRobustness level R (0-7)
pt_limitNew mask period (pt parameter)
ft_limitSend mask period (ft parameter)
rt_limitUncompressed period (rt parameter)
Returns
Error::Ok on success

Definition at line 59 of file ccsds124.hpp.

References ccsds124::Compressor< N, MaxOutputBytes >::compress_packet(), ccsds124::BitVector< N >::from_bytes(), InvalidArg, ccsds124::CompressParams::min_robustness, ccsds124::CompressParams::new_mask_flag, Ok, Overflow, ccsds124::CompressParams::send_mask_flag, ccsds124::BitBuffer< MaxBytes >::to_bytes(), and ccsds124::CompressParams::uncompressed_flag.

◆ compute_change()

template<std::size_t N>
void ccsds124::compute_change ( BitVector< N > &  change,
const BitVector< N > &  mask,
const BitVector< N > &  prev_mask,
std::size_t  t 
)
noexcept

Compute change vector (CCSDS Equation 8).

The change vector tracks mask changes between iterations.

  • D_t = M_t XOR M_{t-1} (if t > 0)
  • D_t = M_t (if t = 0, assuming M_{-1} = 0)
Template Parameters
NBitVector length
Parameters
[out]changeChange vector D_t
[in]maskCurrent mask M_t
[in]prev_maskPrevious mask M_{t-1}
[in]tTime index (0 = first packet)

Definition at line 115 of file mask.hpp.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ count_decode()

Error ccsds124::count_decode ( BitReader reader,
std::uint32_t &  value 
)
inlinenoexcept

Counter decoding (inverse of CCSDS Section 5.2.2, Equation 9).

Decodes a COUNT-encoded value from a bit reader.

  • '0' → A = 1
  • '10' → terminator (A = 0)
  • '110' + 5 bits → A = value + 2
  • '111' + variable bits → A = value + 2
Parameters
readerBit reader positioned at COUNT-encoded data
[out]valueDecoded value (0 for terminator, 1+ for values)
Returns
Error::Ok on success, Error::Underflow if not enough bits

Definition at line 50 of file decoder.hpp.

References Ok, and Underflow.

Referenced by ccsds124::Decompressor< N >::decompress_packet(), and rle_decode().

◆ count_encode()

template<std::size_t MaxBytes>
Error ccsds124::count_encode ( BitBuffer< MaxBytes > &  output,
std::uint32_t  A 
)
noexcept

Counter encoding (CCSDS Section 5.2.2, Equation 9).

Encodes an integer A as a unary prefix followed by binary suffix.

  • A = 1 → '0'
  • 2 ≤ A ≤ 33 → '110' ∥ BIT₅(A-2)
  • A ≥ 34 → '111' ∥ BIT_E(A-2)
Template Parameters
MaxBytesBitBuffer capacity
Parameters
outputBit buffer to append encoded value
AValue to encode (1 to 65535)
Returns
Error::Ok on success

Definition at line 71 of file encoder.hpp.

References ccsds124::detail::COUNT_BITS, ccsds124::detail::COUNT_VALUES, InvalidArg, and Ok.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet(), and rle_encode().

◆ decompress()

template<std::size_t N>
Error ccsds124::decompress ( const std::uint8_t *  input_data,
std::size_t  input_size,
std::uint8_t *  output_buffer,
std::size_t  output_buffer_size,
std::size_t &  output_size,
std::uint8_t  robustness = 0 
)
noexcept

Decompress multi-packet data stream.

Decompresses CCSDS 124.0-B-1 compressed data back to original packets.

Template Parameters
NPacket length in bits
Parameters
input_dataCompressed input data bytes
input_sizeCompressed input size in bytes
output_bufferOutput buffer for decompressed data
output_buffer_sizeMaximum output buffer size
[out]output_sizeActual decompressed output size
robustnessRobustness level R (0-7)
Returns
Error::Ok on success

Definition at line 184 of file ccsds124.hpp.

References ccsds124::BitReader::align_byte(), ccsds124::Decompressor< N >::decompress_packet(), Ok, Overflow, ccsds124::BitReader::remaining(), and ccsds124::BitVector< N >::to_bytes().

◆ error_string()

const char * ccsds124::error_string ( Error  error)
inlinenoexcept

Get error message for error code.

Parameters
errorError code
Returns
Human-readable error message

Definition at line 42 of file error.hpp.

References InvalidArg, InvalidData, Ok, Overflow, and Underflow.

◆ rle_decode()

template<std::size_t N>
Error ccsds124::rle_decode ( BitReader reader,
BitVector< N > &  result 
)
noexcept

Run-length decoding (inverse of CCSDS Section 5.2.3, Equation 10).

Decodes RLE-encoded data back to a BitVector.

Template Parameters
NBitVector length
Parameters
readerBit reader positioned at RLE-encoded data
[out]resultDecoded bit vector
Returns
Error::Ok on success

Definition at line 132 of file decoder.hpp.

References count_decode(), Ok, and Overflow.

Referenced by ccsds124::Decompressor< N >::decompress_packet().

◆ rle_encode()

template<std::size_t MaxBytes, std::size_t N>
Error ccsds124::rle_encode ( BitBuffer< MaxBytes > &  output,
const BitVector< N > &  input 
)
noexcept

Run-length encoding (CCSDS Section 5.2.3, Equation 10).

RLE(a) = COUNT(C₀) ∥ COUNT(C₁) ∥ ... ∥ COUNT(C_{H(a)-1}) ∥ '10'

Template Parameters
MaxBytesBitBuffer capacity
NBitVector length
Parameters
outputBit buffer to append encoded runs
inputBit vector to encode
Returns
Error::Ok on success

Definition at line 114 of file encoder.hpp.

References count_encode(), and Ok.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ update_build()

template<std::size_t N>
void ccsds124::update_build ( BitVector< N > &  build,
const BitVector< N > &  input,
const BitVector< N > &  prev_input,
bool  new_mask_flag,
std::size_t  t 
)
noexcept

Update build vector (CCSDS Equation 6).

The build vector accumulates XOR differences between consecutive packets to track which bits have changed.

  • B_t = (I_t XOR I_{t-1}) OR B_{t-1} (if t > 0 and new_mask_flag = 0)
  • B_t = 0 (otherwise: t=0 or new_mask_flag=1)
Template Parameters
NBitVector length
Parameters
[in,out]buildUpdated build vector B_t
[in]inputCurrent input I_t
[in]prev_inputPrevious input I_{t-1}
[in]new_mask_flagp_t flag (true = reset build)
[in]tTime index (0 = first packet)

Definition at line 53 of file mask.hpp.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ update_mask()

template<std::size_t N>
void ccsds124::update_mask ( BitVector< N > &  mask,
const BitVector< N > &  input,
const BitVector< N > &  prev_input,
const BitVector< N > &  build_prev,
bool  new_mask_flag 
)
noexcept

Update mask vector (CCSDS Equation 7).

The mask vector identifies unpredictable bits (1 = unpredictable).

  • M_t = (I_t XOR I_{t-1}) OR M_{t-1} (if new_mask_flag = 0)
  • M_t = (I_t XOR I_{t-1}) OR B_{t-1} (if new_mask_flag = 1)
Template Parameters
NBitVector length
Parameters
[in,out]maskUpdated mask vector M_t
[in]inputCurrent input I_t
[in]prev_inputPrevious input I_{t-1}
[in]build_prevPrevious build vector B_{t-1}
[in]new_mask_flagp_t flag (true = update from build)

Definition at line 84 of file mask.hpp.

Referenced by ccsds124::Compressor< N, MaxOutputBytes >::compress_packet().

◆ version()

const char * ccsds124::version ( )
inlinenoexcept

Get library version.

Returns
Version string

Definition at line 228 of file ccsds124.hpp.

Referenced by print_help(), and print_version().