27#ifndef CCSDS124_DECODER_HPP
28#define CCSDS124_DECODER_HPP
51 if (reader.remaining() == 0) {
56 int bit0 = reader.read_bit();
68 int bit1 = reader.read_bit();
80 int bit2 = reader.read_bit();
87 std::uint32_t raw = reader.read_bits(5);
97 next_bit = reader.read_bit();
102 }
while (next_bit == 0 && reader.remaining() > 0);
105 std::size_t value_bits = size + 5;
109 std::uint32_t raw = 1;
110 for (std::size_t i = 0; i < value_bits - 1; ++i) {
111 int bit = reader.read_bit();
115 raw = (raw << 1) | (static_cast<std::uint32_t>(bit) & 1U);
137 std::size_t bit_position = N;
140 std::uint32_t delta = 0;
143 while (status ==
Error::Ok && delta != 0) {
148 if (delta > bit_position) {
151 bit_position -= delta;
153 result.set_bit(bit_position, 1);
174template <std::
size_t N>
176 std::size_t hamming = mask.hamming_weight();
184 if (reader.remaining() < hamming) {
191 std::uint32_t mask_word = mask.data()[word];
194 for (
int bits_remaining = __builtin_popcount(mask_word); bits_remaining > 0;
198 std::size_t global_pos =
199 (
static_cast<std::size_t
>(word) * 32) +
static_cast<std::size_t
>(bit_pos_in_word);
201 if (global_pos < N) {
202 int bit = reader.read_bit();
206 data.set_bit(global_pos, bit);
226template <std::
size_t N>
229 if (reader.remaining() < mask.hamming_weight()) {
235 for (std::size_t word = 0; word < BitVector<N>::NUM_WORDS; ++word) {
236 std::uint32_t mask_word = mask.data()[word];
239 for (
int bits_remaining = __builtin_popcount(mask_word); bits_remaining > 0;
243 std::size_t global_pos = (word * 32) +
static_cast<std::size_t
>(clz);
245 if (global_pos < N) {
246 int bit = reader.read_bit();
250 data.set_bit(global_pos, bit);
Sequential bit reading from compressed data.
Fixed-length bit vector with static allocation.
Sequential bit reader for compressed data.
Fixed-length bit vector with compile-time size.
CCSDS 124.0-B-1 compile-time configuration.
CCSDS 124.0-B-1 error handling.
int extract_msb(std::uint32_t &word) noexcept
Extract and clear the most significant set bit from a word.
int extract_lsb(std::uint32_t &word) noexcept
Extract and clear the least significant set bit from a word.
Error bit_insert_forward(BitReader &reader, BitVector< N > &data, const BitVector< N > &mask) noexcept
Bit insertion with forward order.
Error
Error codes for error-code-based error handling.
@ Underflow
Buffer underflow (not enough data)
@ Overflow
Buffer overflow.
Error count_decode(BitReader &reader, std::uint32_t &value) noexcept
Counter decoding (inverse of CCSDS Section 5.2.2, Equation 9).
Error rle_decode(BitReader &reader, BitVector< N > &result) noexcept
Run-length decoding (inverse of CCSDS Section 5.2.3, Equation 10).
Error bit_insert(BitReader &reader, BitVector< N > &data, const BitVector< N > &mask) noexcept
Bit insertion (inverse of CCSDS Section 5.2.4, Equation 11).