32typedef enum : uint32_t {
42typedef enum : uint32_t {
47typedef enum : uint8_t {
72 uint32_t running_crc = crc;
73 for (uint32_t i = 0U; i < len; i++) {
74 running_crc ^= (uint32_t)data[i];
76 const uint32_t lsb = running_crc & 1U;
77 const uint32_t mask = 0U - lsb;
132 const uint64_t off_node = off_chap + chap_bytes;
133 const uint64_t off_attr = off_node + node_bytes;
134 const uint64_t off_style = off_attr + attr_bytes;
135 const uint64_t off_image = off_style + style_bytes;
136 const uint64_t off_string = off_image + image_bytes;
137 const uint64_t off_pool = off_string + (uint64_t)ctx->
string_size;
140 if (total > (uint64_t)UINT32_MAX) {
145 lay->off_chap = (uint32_t)off_chap;
146 lay->off_node = (uint32_t)off_node;
147 lay->off_attr = (uint32_t)off_attr;
148 lay->off_style = (uint32_t)off_style;
149 lay->off_image = (uint32_t)off_image;
150 lay->off_string = (uint32_t)off_string;
151 lay->off_pool = (uint32_t)off_pool;
152 lay->total = (uint32_t)total;
163typedef enum : uint8_t {
233 const ra8_err_t err = read(read_ctx, offset, dst, len, &got);
298 uint32_t scratch_cap,
308 uint32_t offset = 0U;
309 while (offset < ctx->image_pool_size) {
311 if (span > scratch_cap) {
400 uint32_t scratch_cap)
408 uint32_t offset = 0U;
409 while (offset < ctx->image_pool_size) {
411 if (span > scratch_cap) {
453 uint32_t scratch_cap,
500 uint32_t scratch_cap)
542 const uint8_t* scratch,
543 uint32_t scratch_cap,
544 const uint32_t* out_len)
547 if (
write ==
nullptr) {
555 bool external =
false;
560 if (image_read ==
nullptr) {
563 if (scratch ==
nullptr) {
566 if (scratch_cap == 0U) {
579 uint32_t scratch_cap,
613 *out_len = lay.total;
648 if (requested > (sink->
cap - sink->
used)) {
652 sink->
used += requested;
653 *out_written = requested;
678 const void** out_blob,
679 const uint32_t* out_len)
@ k_book_sizeof_image
Bytes in book_image_t.
@ k_book_sizeof_header
Bytes in book_header_t.
@ k_book_sizeof_node
Bytes in book_node_t.
@ k_book_sizeof_chapter
Bytes in book_chapter_t.
@ k_book_sizeof_stylesheet
Bytes in book_stylesheet_t.
@ k_book_sizeof_attr
Bytes in book_attr_t.
@ k_book_format_version
Current .rabook layout revision.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ 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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
#define ra8_log_error(tag, message)
RA8 log error.
static ra8_err_t internal_write_exact(ra8_rabook_write_fn write, void *write_ctx, const uint8_t *src, uint32_t len)
Append one exact stream chunk, rejecting a short success.
static ra8_err_t internal_crc_image_pool(const ra8_rabook_ctx_t *ctx, ra8_rabook_image_read_fn read, void *read_ctx, uint8_t *scratch, uint32_t scratch_cap, uint32_t *crc)
Fold the logical image pool into an in-progress CRC.
ra8_err_t ra8_rabook_finalize(ra8_rabook_ctx_t *ctx, const void **out_blob, uint32_t *out_len)
Lay out the tables and pools, fill the header, CRC, and emit the blob.
static ra8_err_t internal_write_image_pool(const ra8_rabook_ctx_t *ctx, ra8_rabook_image_read_fn read, void *read_ctx, ra8_rabook_write_fn write, void *write_ctx, uint8_t *scratch, uint32_t scratch_cap)
Emit the logical image pool through the exact-write callback.
static uint32_t internal_crc_update(uint32_t crc, const uint8_t *data, uint32_t len)
Continue a CRC-32/ISO-HDLC accumulator over one byte range.
static ra8_err_t internal_crc_body(const ra8_rabook_ctx_t *ctx, const ra8_rabook_segment_t seg[k_rabook_segment_count], ra8_rabook_image_read_fn read, void *read_ctx, uint8_t *scratch, uint32_t scratch_cap, uint32_t *out_crc)
Compute the finalized CRC for all canonical body segments.
ra8_rabook_pool_mode_t
Image-pool backing recorded by the builder context.
@ k_rabook_pool_external
Bytes live behind the read callback.
ra8_rabook_crc_t
CRC-32/ISO-HDLC constants matching book_validate.
@ k_rabook_crc_poly
Reflected CRC-32 polynomial.
@ k_rabook_crc_init
CRC seed and final XOR mask.
static book_header_t internal_make_header(const ra8_rabook_ctx_t *ctx, const ra8_rabook_layout_t *lay, uint32_t crc)
Fill the fixed RABOOK1 header from one layout and CRC.
ra8_rabook_segment_count_t
Number of resident body segments before the image-pool payload.
@ k_rabook_segment_nodes
DOM node table.
@ k_rabook_segment_images
Image descriptor table.
@ k_rabook_segment_attrs
DOM attribute table.
@ k_rabook_segment_chapters
Chapter table.
@ k_rabook_segment_styles
Stylesheet table.
@ k_rabook_segment_strings
Interned string pool.
@ k_rabook_segment_count
Five tables plus the string pool.
static ra8_err_t internal_memory_write(void *opaque, const uint8_t *src, uint32_t requested, uint32_t *out_written)
Append one chunk to a bounded memory sink.
static ra8_err_t internal_validate_stream_args(const ra8_rabook_ctx_t *ctx, ra8_rabook_image_read_fn image_read, ra8_rabook_write_fn write, const uint8_t *scratch, uint32_t scratch_cap, const uint32_t *out_len)
Validate streaming-finalizer arguments and builder state.
static void internal_segments(const ra8_rabook_ctx_t *ctx, const ra8_rabook_layout_t *lay, ra8_rabook_segment_t seg[k_rabook_segment_count])
Populate the canonical resident body-segment sequence.
static ra8_err_t internal_write_book(const ra8_rabook_ctx_t *ctx, const book_header_t *hdr, const ra8_rabook_segment_t seg[k_rabook_segment_count], ra8_rabook_image_read_fn read, void *read_ctx, ra8_rabook_write_fn write, void *write_ctx, uint8_t *scratch, uint32_t scratch_cap)
Emit the fixed header followed by the canonical logical body.
ra8_rabook_crc_bits_t
Per-byte fold count for the bitwise CRC inner loop.
@ k_rabook_crc_byte_bits
Bit folds per input byte.
static ra8_err_t internal_compute_layout(const ra8_rabook_ctx_t *ctx, ra8_rabook_layout_t *lay)
Compute the table / pool offsets and total blob size, overflow-guarded.
static ra8_err_t internal_read_exact(ra8_rabook_image_read_fn read, void *read_ctx, uint32_t offset, uint8_t *dst, uint32_t len)
Read one exact external-pool chunk, rejecting a short success.
ra8_err_t ra8_rabook_finalize_stream(const ra8_rabook_ctx_t *ctx, ra8_rabook_image_read_fn image_read, void *image_ctx, ra8_rabook_write_fn write, void *write_ctx, uint8_t *scratch, uint32_t scratch_cap, uint32_t *out_len)
Stream a canonical flat RABOOK1 blob without a full output arena.
static const char *const s_tag_rabook
Component tag for finalizer diagnostics.
static ra8_err_t internal_validate_memory_finalize(ra8_rabook_ctx_t *ctx, const void **out_blob, const uint32_t *out_len)
Validate the legacy in-memory finalizer and output capacity.
Zero-heap builder that emits a RABOOK1 blob (the #149 compiler back-end).
ra8_err_t(* ra8_rabook_image_read_fn)(void *ctx, uint32_t offset, uint8_t *dst, uint32_t requested, uint32_t *out_read)
Read bytes from an externally stored image pool.
ra8_err_t(* ra8_rabook_write_fn)(void *ctx, const uint8_t *src, uint32_t requested, uint32_t *out_written)
Append bytes to a streaming RABOOK1 destination.
uint32_t out_cap
Output capacity in bytes.
uint8_t * image_pool
Image-pool byte arena.
char * string_pool
String-pool byte arena.
book_image_t * images
Image-table arena.
book_stylesheet_t * stylesheets
Stylesheet-table arena.
book_node_t * nodes
Node-table arena.
uint8_t * out
Final-blob output buffer.
book_attr_t * attrs
Attribute-table arena.
book_chapter_t * chapters
Chapter-table arena.
Builder state: the arenas plus running counts and a sticky-fail flag.
bool failed
Sticky: an arena overflowed.
uint32_t title_off
Metadata: title string offset.
uint8_t image_pool_mode
Internal builder storage mode.
uint32_t string_size
String-pool bytes used.
uint32_t stylesheet_count
Stylesheets appended so far.
uint32_t cover_image_index
Cover image index, or nil.
uint32_t image_pool_size
Image-pool bytes used.
ra8_rabook_buffers_t buf
Caller-provided arenas.
uint32_t language_off
Metadata: language string offset.
uint32_t chapter_count
Chapters appended so far.
uint32_t node_count
Nodes appended so far.
uint32_t image_count
Images appended so far.
uint32_t flags
Reserved header flags (0 in v1).
uint32_t author_off
Metadata: author string offset.
uint32_t identifier_off
Metadata: identifier string offset.
uint32_t attr_count
Attributes appended so far.
Computed byte offsets of every table / pool plus the total blob size.
uint32_t off_image
Image table offset.
uint32_t off_chap
Chapter table offset (== header size).
uint32_t off_string
String-pool offset.
uint32_t total
Total blob size in bytes.
uint32_t off_style
Stylesheet table offset.
uint32_t off_attr
Attribute table offset.
uint32_t off_pool
Image-pool offset.
uint32_t off_node
Node table offset.
Bounded in-memory sink used by the legacy finalizer wrapper.
uint8_t * data
Output arena base.
uint32_t cap
Output arena bytes.
uint32_t used
Bytes appended.
One resident body segment in canonical serialization order.
const uint8_t * data
First readable byte.
uint32_t len
Segment byte count.