52 if (st->refill_pos >= st->refill_len) {
53 if (st->fetched >= st->packlen) {
57 const uint64_t remain = st->packlen - st->fetched;
61 const size_t r = st->rar->read(st->rar->ctx, st->base + st->fetched, st->refill, want);
66 st->refill_len = (uint32_t)r;
68 st->fetched += (uint64_t)r;
70 const uint8_t b = st->refill[st->refill_pos];
91 while (st->nbits < n) {
116 const uint64_t mask = ((uint64_t)1U << n) - (uint64_t)1U;
117 return (uint32_t)((st->acc >> (st->nbits - n)) & mask);
137 st->consumed += (uint64_t)n;
140 : (((uint64_t)1U << st->nbits) - (uint64_t)1U);
192 for (uint32_t i = 1U; i < (uint32_t)(
k_r5_maxbits + 1U); ++i) {
196 d->
pos[i] = d->
pos[i - 1U] + count[i - 1U];
220 for (uint16_t i = 0U; i < size; ++i) {
225 (void)
memset(d->
num, 0, (
size_t)size *
sizeof(d->
num[0]));
227 for (uint32_t i = 0U; i < (uint32_t)(
k_r5_maxbits + 1U); ++i) {
228 copypos[i] = d->
pos[i];
230 for (uint16_t i = 0U; i < size; ++i) {
233 d->
num[copypos[bl]] = i;
245 for (uint32_t i = 1U; i < (uint32_t)
k_r5_maxbits; ++i) {
246 if (bf < d->len[i]) {
252 const uint32_t dist = (bf - d->
len[bits - 1U]) >> ((uint32_t)
k_r5_bf_bits - bits);
253 uint32_t pos = d->
pos[bits] + dist;
254 if (pos >= (uint32_t)d->
max) {
291 const uint32_t bytecount =
294 for (uint32_t i = 0U; i < bytecount; ++i) {
313 for (uint32_t c = 0U; (c < count) && (i < max); ++c) {
341 out[i] = (uint8_t)len;
366 const uint32_t count =
369 if ((!is_zero) && (*idx == 0U)) {
372 const uint8_t prev = (*idx > 0U) ? tbl[*idx - 1U] : 0U;
373 const uint8_t fill = is_zero ? 0U : prev;
406 tbl[i] = (uint8_t)num;
438 st->tables_ready =
true;
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
Clean-room RAR 5.0 ("method 50") decompressor – LZ + Huffman + filters.
@ k_ra8_rar5_ldc
Low-distance alphabet size.
@ k_ra8_rar5_huff_total
NC+DC+LDC+RC combined length-table size.
@ k_ra8_rar5_bc
Bit-length pre-table alphabet size.
@ k_ra8_rar5_rc
Repeat-length alphabet size.
@ k_ra8_rar5_refill_bytes
Streaming bit-reader packed-byte window.
@ k_ra8_rar5_dc
Distance-slot alphabet size.
@ k_ra8_rar5_nc
Main alphabet size (literals+len+rep+filter).
Cross-TU seam between the RAR5 entropy front-end and the LZ decoder.
@ k_r5_nibble_mask
Low nibble of a bit-length byte.
@ k_r5_byte_mask
Single-byte mask.
@ k_r5_bf_mask
DecodeNumber bit-field, low bit cleared.
@ k_r5_bf_last
Last block in the file.
@ k_r5_bf_bcount_shift
Shift to the block-size byte count.
@ k_r5_bf_bcount_mask
Mask of the block-size byte count.
@ k_r5_hdr_chk_seed
Header-checksum seed constant.
@ k_r5_bf_tables
Block carries new Huffman tables.
@ k_r5_bf_bitsize_mask
Last-byte valid-bit count minus one.
@ k_r5_maxbits
Longest Huffman code length.
@ k_r5_byte_bits
Bits per packed byte.
@ k_r5_low3_mask
Low three bits (byte-alignment residue).
@ k_r5_acc_bits
Bit-accumulator width (mask guard).
@ k_r5_bf_bits
DecodeNumber look-ahead window width.
@ k_r5_len_escape
4-bit escape in the BD length list.
@ k_r5_tbl_copy_long
Copy previous length, 7-bit run.
@ k_r5_zeros_extra
BD zero-run length bias.
@ k_r5_tbl_zero_short
Zero length, 3-bit run.
@ k_r5_run_long_bits
Long-run extra-bit width.
@ k_r5_run_long_add
Long-run length bias.
@ k_r5_tbl_zero_long
Zero length, 7-bit run.
static void internal_ensure(ra8_rar5_state_t *st, uint32_t n)
Ensure at least n bits are buffered in the accumulator.
ra8_err_t priv_rar5_read_tables(ra8_rar5_state_t *st)
Implementation of priv_rar5_read_tables() – BD pre-table then the four LZ tables.
static void internal_make_tables(ra8_rar5_dtab_t *d, const uint8_t *lengths, uint16_t size)
Build a canonical Huffman decode table from a bit-length vector.
static ra8_err_t internal_read_bd_lengths(ra8_rar5_state_t *st, uint8_t *out)
Read the 20-entry bit-length pre-table (BD) length list.
static void internal_align(ra8_rar5_state_t *st)
Discard bits up to the next byte boundary.
uint32_t priv_rar5_get(ra8_rar5_state_t *st, uint32_t n)
Implementation of priv_rar5_get() – internal_peek then internal_drop of n bits.
uint32_t priv_rar5_decode_num(ra8_rar5_state_t *st, const ra8_rar5_dtab_t *d)
Implementation of priv_rar5_decode_num() – limit-compare canonical decode.
static ra8_err_t internal_read_full_table(ra8_rar5_state_t *st, uint8_t *tbl)
Decode the combined length table for the four LZ alphabets.
static void internal_tab_limits(ra8_rar5_dtab_t *d, const uint32_t *count)
Fill a decode table's per-length upper-limit and start-position arrays.
ra8_err_t priv_rar5_read_block_header(ra8_rar5_state_t *st, r5_block_t *b)
Implementation of priv_rar5_read_block_header() – align, flags, size, checksum.
uint32_t priv_rar5_fill_zeros(uint8_t *out, uint32_t start, uint32_t count, uint32_t max)
Implementation of priv_rar5_fill_zeros() – bounded zero-length append.
static uint8_t internal_fetch_byte(ra8_rar5_state_t *st)
Pull the next packed byte, refilling the window from the backing reader.
static uint8_t internal_checksum(uint32_t flags, uint64_t blocksize)
Compute the RAR5 block-header checksum byte.
static uint32_t internal_peek(ra8_rar5_state_t *st, uint32_t n)
Peek the next n bits without consuming them.
static void internal_drop(ra8_rar5_state_t *st, uint32_t n)
Consume n previously-peeked bits.
ra8_err_t priv_rar5_apply_run(ra8_rar5_state_t *st, uint8_t *tbl, uint32_t *idx, uint32_t num)
Implementation of priv_rar5_apply_run() – copy-previous / zero run append.
Decoded fields of one RAR5 compressed-block header.
One canonical Huffman decode table (shared by all five RAR5 alphabets).
uint32_t pos[16]
First num index per bit length.
uint32_t len[16]
Left-aligned upper-limit code per bit length.
uint16_t max
Alphabet size (populated slot count).
uint16_t num[k_ra8_rar5_nc]
Symbol per canonical code slot.
Caller-owned zero-heap scratch for one ra8_rar5_decompress call.