CCSDS 124.0-B-1 Go Implementation

Go implementation of the CCSDS 124.0-B-1 lossless compression algorithm of fixed-length housekeeping data.

Citation

If CCSDS 124.0-B-1 contributes to your research, please cite:

D. Evans, G. Labrèche, D. Marszk, S. Bammens, M. Hernandez-Cabronero, V. Zelenevskiy, V. Shiradhonkar, M. Starcik, and M. Henkel. 2022. "Implementing the New CCSDS Housekeeping Data Compression Standard 124.0-B-1 (based on POCKET+) on OPS-SAT-1," Proceedings of the Small Satellite Conference, Communications, SSC22-XII-03. https://digitalcommons.usu.edu/smallsat/2022/all2022/133/
BibTeX
@inproceedings{evans2022ccsds124,
  author    = {Evans, David and Labreche, Georges and Marszk, Dominik and Bammens, Samuel and Hernandez-Cabronero, Miguel and Zelenevskiy, Vladimir and Shiradhonkar, Vasundhara and Starcik, Mario and Henkel, Maximilian},
  title     = {Implementing the New CCSDS Housekeeping Data Compression Standard 124.0-B-1 (based on POCKET+) on OPS-SAT-1},
  booktitle = {Proceedings of the Small Satellite Conference},
  year      = {2022},
  note      = {SSC22-XII-03},
  url       = {https://digitalcommons.usu.edu/smallsat/2022/all2022/133/}
}

Package ccsds124

Package ccsds124 implements the CCSDS 124.0-B-1 lossless data compression algorithm for fixed-length housekeeping data.

Types

type Compressor
type Compressor struct {
    // Contains filtered or unexported fields
}

Compressor maintains state for CCSDS 124.0-B-1 compression across multiple packets.

Methods

func NewCompressor(F int, initialMask *BitVector, robustness, ptLimit, ftLimit, rtLimit int) (*Compressor, error)

NewCompressor creates a new compressor with the given parameters. F is the input vector length in bits, initialMask is the optional initial mask, robustness is Rt (0-7), and ptLimit/ftLimit/rtLimit control automatic mode triggers.

func (c *Compressor) CompressPacket(input *BitVector, params *Params) (*BitBuffer, error)

CompressPacket compresses a single input packet and returns the compressed output.

func (c *Compressor) Reset()

Reset resets the compressor to its initial state.

type Decompressor
type Decompressor struct {
    F          int        // Input vector length in bits
    // Contains filtered or unexported fields
}

Decompressor maintains state for CCSDS 124.0-B-1 decompression.

Methods

func NewDecompressor(F int, initialMask *BitVector, robustness int) (*Decompressor, error)

NewDecompressor creates a new decompressor with the given parameters.

func (d *Decompressor) DecompressPacket(reader *BitReader) (*BitVector, error)

DecompressPacket decompresses a single compressed packet.

func (d *Decompressor) DecompressStream(data []byte, numBits int) ([][]byte, error)

DecompressStream decompresses multiple packets from a byte stream.

func (d *Decompressor) NewPacketIterator(data []byte, numBits int) *PacketIterator

NewPacketIterator creates a streaming packet iterator for memory-efficient decompression.

func (d *Decompressor) StreamPackets(data []byte, numBits int) <-chan []byte

StreamPackets returns a channel that yields decompressed packets.

type BitVector
type BitVector struct {
    // Contains filtered or unexported fields
}

BitVector represents a fixed-length sequence of bits stored in 32-bit words with MSB-first bit ordering.

Methods

func NewBitVector(length int) (*BitVector, error)

NewBitVector creates a new BitVector with the specified length in bits.

func NewBitVectorFromBytes(data []byte, length int) (*BitVector, error)

NewBitVectorFromBytes creates a BitVector from a byte slice.

func (bv *BitVector) GetBit(pos int) int

GetBit returns the bit value (0 or 1) at the given position.

func (bv *BitVector) SetBit(pos int, value int)

SetBit sets the bit at the given position to the specified value.

func (bv *BitVector) XOR(other *BitVector) *BitVector

XOR returns a new BitVector that is the XOR of this and other.

func (bv *BitVector) OR(other *BitVector) *BitVector

OR returns a new BitVector that is the OR of this and other.

func (bv *BitVector) AND(other *BitVector) *BitVector

AND returns a new BitVector that is the AND of this and other.

func (bv *BitVector) NOT() *BitVector

NOT returns a new BitVector with all bits inverted.

func (bv *BitVector) HammingWeight() int

HammingWeight returns the number of '1' bits in the vector.

func (bv *BitVector) ToBytes() []byte

ToBytes converts the BitVector to a byte slice.

type BitBuffer
type BitBuffer struct {
    // Contains filtered or unexported fields
}

BitBuffer is a variable-length bit buffer for building compressed output.

Methods

func NewBitBuffer(capacity int) *BitBuffer

NewBitBuffer creates a new BitBuffer with the specified initial capacity.

func (bb *BitBuffer) AppendBit(bit int)

AppendBit appends a single bit (0 or 1) to the buffer.

func (bb *BitBuffer) AppendBits(value uint64, count int)

AppendBits appends multiple bits from a value (MSB first).

func (bb *BitBuffer) Size() int

Size returns the number of bits in the buffer.

func (bb *BitBuffer) ToBytes() []byte

ToBytes returns the buffer contents as a byte slice.

type BitReader
type BitReader struct {
    // Contains filtered or unexported fields
}

BitReader provides sequential bit reading from a byte buffer.

Methods

func NewBitReader(data []byte) *BitReader

NewBitReader creates a new BitReader from a byte slice.

func NewBitReaderWithBits(data []byte, numBits int) *BitReader

NewBitReaderWithBits creates a BitReader with an explicit bit count.

func (br *BitReader) ReadBit() (int, error)

ReadBit reads and returns the next bit.

func (br *BitReader) ReadBits(count int) (uint64, error)

ReadBits reads and returns the next count bits as a uint64.

func (br *BitReader) Remaining() int

Remaining returns the number of unread bits.

type Params
type Params struct {
    NewMaskFlag bool // Force new mask transmission
    ResetFlag   bool // Force full packet transmission
}

Params contains per-packet compression parameters.

type PacketIterator
type PacketIterator struct {
    // Contains filtered or unexported fields
}

PacketIterator provides streaming decompression with an iterator pattern.

Methods

func (it *PacketIterator) Next() []byte

Next returns the next decompressed packet, or nil if done or on error.

func (it *PacketIterator) Err() error

Err returns any error encountered during iteration.

Encoding Functions

func CountEncode(bb *BitBuffer, A int) error

CountEncode implements CCSDS 124.0-B-1 Section 5.2.2, Table 5-1, Equation 9. Encodes positive integers 1 <= A <= 2^16 - 1.

func CountEncodeTerminator(bb *BitBuffer)

CountEncodeTerminator writes the RLE terminator pattern '10'.

func RLEEncode(bb *BitBuffer, input *BitVector) error

RLEEncode implements CCSDS 124.0-B-1 Section 5.2.3, Equation 10. Encodes a bit vector using run-length encoding.

func BitExtract(bb *BitBuffer, data, mask *BitVector) error

BitExtract implements CCSDS 124.0-B-1 Section 5.2.4, Equation 11. Extracts bits from data at positions where mask has '1' bits.

func BitExtractForward(bb *BitBuffer, data, mask *BitVector) error

BitExtractForward extracts bits in forward order (lowest position to highest). Used for kt component.

Decoding Functions

func CountDecode(br *BitReader) (int, error)

CountDecode decodes a COUNT-encoded value. Returns the decoded positive integer.

func RLEDecode(br *BitReader, length int) (*BitVector, error)

RLEDecode decodes an RLE-encoded bit vector of the specified length.

func BitInsert(br *BitReader, data, mask *BitVector) error

BitInsert inserts bits from reader into data at positions where mask has '1' bits.

func BitInsertForward(br *BitReader, data, mask *BitVector) error

BitInsertForward inserts bits in forward order (for kt component).

Mask Operations

func UpdateBuild(build, change *BitVector) *BitVector

UpdateBuild computes B_t = B_{t-1} OR D_t (CCSDS Equation 6).

func UpdateMask(mask, build *BitVector, newMaskFlag bool) *BitVector

UpdateMask computes M_t based on CCSDS Equation 7.

func ComputeChange(prevMask, currMask *BitVector) *BitVector

ComputeChange computes D_t = M_{t-1} XOR M_t (CCSDS Equation 8).

func HorizontalXOR(input *BitVector) *BitVector

HorizontalXOR computes horizontal XOR for mask transmission: result[i] = input[i] XOR input[i+1].

Constants

const (
    MaxRobustness = 7  // Maximum robustness parameter (R_t)
)

MaxRobustness defines the maximum allowed robustness parameter value per CCSDS 124.0-B-1.

Generated on 2026-06-29 15:01:43 UTC