26typedef enum : uint8_t {
36typedef enum : uint8_t {
75 out[i] = (uint8_t)(value >> shift);
104 uint32_t written = 0U;
105 const ra8_err_t err = write_at(ctx, offset, src, len, &written);
134 const uint64_t* out_len,
135 const uint32_t* out_count)
137 if (read ==
nullptr) {
140 if (write_at ==
nullptr) {
146 if (out_len ==
nullptr) {
149 if (out_count ==
nullptr) {
152 if (ws->
input ==
nullptr) {
192 uint32_t chunk_bytes,
195 const uint64_t* out_len,
202 if (flat_len == 0U) {
205 if (chunk_bytes == 0U) {
214 const uint32_t count = ((flat_len - 1U) / chunk_bytes) + 1U;
215 if (count == UINT32_MAX) {
248 uint32_t chunk_bytes,
254 header[i] = rbkc_magic[i];
265 for (uint32_t i = 0U; i <= count; i++) {
302 uint32_t chunk_bytes,
307 uint64_t payload_off)
309 uint32_t flat_off = 0U;
310 uint64_t payload_len = 0U;
311 for (uint32_t i = 0U; i < count; i++) {
312 const uint32_t remaining = flat_len - flat_off;
313 const uint32_t want = (remaining < chunk_bytes) ? remaining : chunk_bytes;
322 uint32_t packed = 0U;
333 if ((uint64_t)packed > (UINT64_MAX - payload_len)) {
336 if (payload_len > (UINT64_MAX - payload_off)) {
345 payload_len += packed;
348 ws->
offsets[count] = payload_len;
376 for (uint32_t i = 0U; i <= count; i++) {
392 uint32_t chunk_bytes,
398 if (out_len !=
nullptr) {
425 if (ws->
offsets[count] > (UINT64_MAX - payload_off)) {
428 *out_len = payload_off + ws->
offsets[count];
Flat, execute-in-place container for a build-time "compiled" e-book.
@ k_book_container_header_len
Fixed header bytes ahead of the chunk table.
@ k_book_container_entry_len
One chunk-table entry (uint64 LE offset).
@ k_book_container_magic_len
Length of the "RBKC" magic.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
App-domain DEFLATE compress / decompress (zero-heap, firmware-safe).
ra8_err_t ra8_compress_zlib(const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, void *scratch, uint32_t scratch_len, uint32_t *out_len)
Zlib-wrap and DEFLATE-compress one bounded byte range.
@ k_ra8_compress_scratch_bytes
Minimum compress scratch size (one miniz tdefl_compressor).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
static ra8_err_t internal_validate(ra8_rabook_flat_read_fn read, uint32_t flat_len, uint32_t chunk_bytes, ra8_rabook_write_at_fn write_at, const ra8_rabook_container_workspace_t *ws, const uint64_t *out_len, uint32_t *out_count)
Validate pointers and workspace capacities before output mutation.
rbkc_bits_t
Number of bits shifted per little-endian output byte.
@ k_rbkc_bits_per_byte
Binary bits represented by one output byte.
static ra8_err_t internal_write_prefix(ra8_rabook_write_at_fn write_at, void *ctx, uint32_t flat_len, uint32_t chunk_bytes, uint32_t count)
Write the fixed header and reserve a zero-filled offset table.
static ra8_err_t internal_validate_pointers(ra8_rabook_flat_read_fn read, ra8_rabook_write_at_fn write_at, const ra8_rabook_container_workspace_t *ws, const uint64_t *out_len, const uint32_t *out_count)
Reject a missing callback, result, workspace, or workspace member.
static ra8_err_t internal_write_exact(ra8_rabook_write_at_fn write_at, void *ctx, uint64_t offset, const uint8_t *src, uint32_t len)
Call the destination once and require an exact successful write.
static void internal_put_u64(uint8_t *out, uint64_t value)
Encode one uint64 in little-endian order.
static void internal_put_u32(uint8_t *out, uint32_t value)
Encode one uint32 in little-endian order.
ra8_err_t ra8_rabook_container_write(ra8_rabook_flat_read_fn read, void *read_ctx, uint32_t flat_len, uint32_t chunk_bytes, ra8_rabook_write_at_fn write_at, void *write_ctx, ra8_rabook_container_workspace_t *ws, uint64_t *out_len)
Stream one flat RABOOK1 blob into a chunked RBKC staging object.
static ra8_err_t internal_write_chunks(ra8_rabook_flat_read_fn read, void *read_ctx, uint32_t flat_len, uint32_t chunk_bytes, ra8_rabook_write_at_fn write_at, void *write_ctx, ra8_rabook_container_workspace_t *ws, uint32_t count, uint64_t payload_off)
Read, compress, and append every independent chunk payload.
static ra8_err_t internal_write_table(ra8_rabook_write_at_fn write_at, void *ctx, const ra8_rabook_container_workspace_t *ws, uint32_t count)
Back-fill the little-endian table after all payload streams exist.
rbkc_layout_t
RBKC fixed-field sizes and offsets.
@ k_rbkc_chunk_bytes_off
uint32 chunk size.
@ k_rbkc_count_off
uint32 chunk count.
@ k_rbkc_total_off
uint64 inflated total.
@ k_rbkc_u32_bytes
Little-endian uint32.
@ k_rbkc_u64_bytes
Little-endian uint64.
@ k_rbkc_reserved_off
uint32 reserved zero.
Zero-heap streaming writer for the chunked RBKC .rabook container.
ra8_err_t(* ra8_rabook_write_at_fn)(void *ctx, uint64_t offset, const uint8_t *src, uint32_t requested, uint32_t *out_written)
Write a bounded range at an absolute staging-destination offset.
ra8_err_t(* ra8_rabook_flat_read_fn)(void *ctx, uint32_t offset, uint8_t *dst, uint32_t requested, uint32_t *out_read)
Read a bounded range from the flat RABOOK1 source.
Caller-owned transient storage for one RBKC write.
uint32_t compressor_cap
Writable bytes at compressor.
uint8_t * compressed
One complete zlib stream.
uint64_t * offsets
Payload-relative offset table.
uint32_t offset_cap
Number of uint64 entries at offsets.
uint32_t input_cap
Writable bytes at input.
uint32_t compressed_cap
Writable bytes at compressed.
uint8_t * input
One uncompressed flat chunk.
void * compressor
tdefl_compressor storage, 8-byte aligned.