58template <std::
size_t N>
59Error compress(
const std::uint8_t* input_data, std::size_t input_size, std::uint8_t* output_buffer,
60 std::size_t output_buffer_size, std::size_t& output_size,
61 std::uint8_t robustness = 0,
int pt_limit = 0,
int ft_limit = 0,
62 int rt_limit = 0) noexcept {
64 constexpr std::size_t packet_bytes = (N + 7) / 8;
67 if (input_size == 0 || (input_size % packet_bytes) != 0) {
72 std::size_t num_packets = input_size / packet_bytes;
78 std::size_t total_output = 0;
81 int pt_counter = pt_limit;
82 int ft_counter = ft_limit;
83 int rt_counter = rt_limit;
86 for (std::size_t i = 0; i < num_packets; ++i) {
89 input_vec.
from_bytes(&input_data[i * packet_bytes], packet_bytes);
95 if (pt_limit > 0 && ft_limit > 0 && rt_limit > 0) {
103 if (ft_counter == 1) {
105 ft_counter = ft_limit;
112 if (pt_counter == 1) {
114 pt_counter = pt_limit;
121 if (rt_counter == 1) {
123 rt_counter = rt_limit;
130 if (i <=
static_cast<std::size_t
>(robustness)) {
151 std::uint8_t packet_bytes_out[N * 6 / 8 + 1];
152 std::size_t packet_size =
153 packet_output.
to_bytes(packet_bytes_out,
sizeof(packet_bytes_out));
156 if (total_output + packet_size > output_buffer_size) {
161 std::memcpy(&output_buffer[total_output], packet_bytes_out, packet_size);
162 total_output += packet_size;
165 output_size = total_output;
183template <std::
size_t N>
185 std::uint8_t* output_buffer, std::size_t output_buffer_size,
186 std::size_t& output_size, std::uint8_t robustness = 0) noexcept {
188 constexpr std::size_t packet_bytes = (N + 7) / 8;
194 BitReader reader(input_data, input_size * 8);
197 std::size_t total_output = 0;
208 if (total_output + packet_bytes > output_buffer_size) {
213 output.
to_bytes(&output_buffer[total_output], packet_bytes);
214 total_output += packet_bytes;
220 output_size = total_output;
Variable-length bit buffer for building compressed output.
Sequential bit reading from compressed data.
Fixed-length bit vector with static allocation.
Variable-length bit buffer with static allocation.
std::size_t to_bytes(std::uint8_t *bytes, std::size_t max_bytes) const noexcept
Convert bit buffer to byte array.
Sequential bit reader for compressed data.
void align_byte() noexcept
Skip to next byte boundary.
std::size_t remaining() const noexcept
Get remaining bits.
Fixed-length bit vector with compile-time size.
void from_bytes(const std::uint8_t *bytes, std::size_t num_bytes) noexcept
Load from byte array (big-endian).
void to_bytes(std::uint8_t *bytes, std::size_t num_bytes) const noexcept
Store to byte array (big-endian).
CCSDS 124.0-B-1 compressor with static memory allocation.
Error compress_packet(const BitVector< N > &input, BitBuffer< OutputSize > &output, const CompressParams *params=nullptr) noexcept
Compress a single input packet.
CCSDS 124.0-B-1 decompressor with static memory allocation.
Error decompress_packet(BitReader &reader, BitVector< N > &output) noexcept
Decompress a single compressed packet.
CCSDS 124.0-B-1 compression algorithm implementation.
CCSDS 124.0-B-1 compile-time configuration.
CCSDS 124.0-B-1 decompression algorithm implementation.
CCSDS 124.0-B-1 error handling.
const char * version() noexcept
Get library version.
Error
Error codes for error-code-based error handling.
@ Overflow
Buffer overflow.
@ InvalidArg
Invalid argument.
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.
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.
Compression parameters for a single packet.
bool new_mask_flag
p_t: Update mask from build vector
bool uncompressed_flag
r_t: Send uncompressed
bool send_mask_flag
f_t: Include mask in output
std::uint8_t min_robustness
R_t: Minimum robustness level (0-7)