CCSDS 124.0-B-1 C 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
Encoding API

CCSDS Section 5.2: Encoding primitives. More...

Functions

int ccsds124_count_encode (bitbuffer_t *output, uint32_t A)
 Counter encoding (CCSDS Section 5.2.2, Equation 9).
 
int ccsds124_rle_encode (bitbuffer_t *output, const bitvector_t *input)
 Run-length encoding (CCSDS Section 5.2.3, Equation 10).
 
int ccsds124_bit_extract (bitbuffer_t *output, const bitvector_t *data, const bitvector_t *mask)
 Bit extraction (CCSDS Section 5.2.4, Equation 11).
 
int ccsds124_bit_extract_forward (bitbuffer_t *output, const bitvector_t *data, const bitvector_t *mask)
 Bit extraction in forward order (LSB to MSB).
 

Detailed Description

CCSDS Section 5.2: Encoding primitives.

These functions implement the three encoding methods used in CCSDS 124.0-B-1 compressed packets.

Function Documentation

◆ ccsds124_bit_extract()

int ccsds124_bit_extract ( bitbuffer_t output,
const bitvector_t data,
const bitvector_t mask 
)

Bit extraction (CCSDS Section 5.2.4, Equation 11).

Extracts bits from data where mask bit is 1, in reverse order (MSB to LSB). Used for unpredictable bit encoding.

Parameters
[out]outputBit buffer to append extracted bits
[in]dataSource data vector
[in]maskMask indicating which bits to extract
Returns
CCSDS124_OK on success

Definition at line 220 of file encode.c.

References bitbuffer_append_bit(), CCSDS124_ERROR_INVALID_ARG, CCSDS124_OK, bitvector::data, bitvector::length, and bitvector::num_words.

Referenced by ccsds124_compress_packet().

◆ ccsds124_bit_extract_forward()

int ccsds124_bit_extract_forward ( bitbuffer_t output,
const bitvector_t data,
const bitvector_t mask 
)

Bit extraction in forward order (LSB to MSB).

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

Parameters
[out]outputBit buffer to append extracted bits
[in]dataSource data vector
[in]maskMask indicating which bits to extract
Returns
CCSDS124_OK on success

Definition at line 273 of file encode.c.

References bitbuffer_append_bit(), CCSDS124_ERROR_INVALID_ARG, CCSDS124_OK, bitvector::data, bitvector::length, and bitvector::num_words.

Referenced by ccsds124_compress_packet().

◆ ccsds124_count_encode()

int ccsds124_count_encode ( bitbuffer_t output,
uint32_t  A 
)

Counter encoding (CCSDS Section 5.2.2, Equation 9).

Encodes an integer A as a unary prefix followed by binary suffix. Used for run lengths and counts in compressed output.

Parameters
[out]outputBit buffer to append encoded value
[in]AValue to encode (0 to MAX)
Returns
CCSDS124_OK on success

Pre-computed COUNT encodings for values 1-33.

Eliminates per-value bit-by-bit encoding for the most common COUNT values by using bitbuffer_append_value() with pre-computed patterns.

Performance: ~2% compression speedup from this optimization. Combined with DeBruijn bit extraction and word-level operations, achieves 14-16% faster compression and 13-39% faster decompression on real-world datasets.

  • A=1: '0' (1 bit) → handled separately (single append_bit is faster)
  • A=2-33: '110' ∥ BIT₅(A-2) (8 bits) → count_values[A]=0xC0|(A-2)

Values 1-33 cover the fast path; larger values (A≥34) use bit-by-bit encoding for MISRA-C:2012 compliance (shift bounds verification).

Definition at line 40 of file encode.c.

References bitbuffer_append_bit(), bitbuffer_append_value(), CCSDS124_ERROR_INVALID_ARG, and CCSDS124_OK.

Referenced by ccsds124_compress_packet(), and ccsds124_rle_encode().

◆ ccsds124_rle_encode()

int ccsds124_rle_encode ( bitbuffer_t output,
const bitvector_t input 
)

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

Encodes a bit vector as alternating run lengths of 0s and 1s. Starts with run of 0s from MSB.

Parameters
[out]outputBit buffer to append encoded runs
[in]inputBit vector to encode (typically reversed)
Returns
CCSDS124_OK on success

Definition at line 135 of file encode.c.

References bitbuffer_append_bit(), ccsds124_count_encode(), CCSDS124_ERROR_INVALID_ARG, CCSDS124_OK, bitvector::data, bitvector::length, and bitvector::num_words.

Referenced by ccsds124_compress_packet().