40 const uint32_t refs[4] = {
46 for (uint8_t i = 0U; i < (uint8_t)(
sizeof(refs) /
sizeof(refs[0])); ++i) {
99 (uint32_t)
sizeof(node));
107 const uint32_t
byte = root / 8U;
108 const uint8_t mask = (uint8_t)(1U << (root % 8U));
109 if ((ctx->
scratch[
byte] & mask) != 0U) {
144 if ((link <= current) || (link >= count)) {
175 const uint32_t
byte = link / 8U;
176 const uint8_t mask = (uint8_t)(1U << (link % 8U));
177 if ((ctx->
scratch[
byte] & mask) != 0U) {
203 uint32_t* attr_cursor)
218 if ((first != *attr_cursor) || (count > (ctx->
hdr.
attr_count - *attr_cursor))) {
221 *attr_cursor += count;
275 uint32_t* attr_cursor,
318 uint32_t attr_cursor = 0U;
337 const uint8_t mask = (uint8_t)(1U << (i % 8U));
338 if ((ctx->
scratch[i / 8U] & mask) == 0U) {
369 (uint32_t)
sizeof(rec));
406 (uint32_t)
sizeof(rec));
442 if ((width == 0U) || (height == 0U) ||
446 const uint64_t pixels = (uint64_t)width * (uint64_t)height;
447 const uint64_t expect = (pixfmt == (uint8_t)
k_book_pixfmt_gray4) ? ((pixels + 1U) / 2U) : pixels;
449 if ((expect > (uint64_t)UINT32_MAX) ||
480 return ((data_size != 0U) &&
505 uint32_t pool_cursor = 0U;
511 (uint32_t)
sizeof(rec));
532 ((data_off != pool_cursor) || (data_size > (ctx->
hdr.
image_pool_size - pool_cursor)))) {
538 pool_cursor += data_size;
565 if (remain < (uint64_t)span) {
566 span = (uint32_t)remain;
605 const uint32_t mark_bytes =
632 uint64_t source_size,
634 uint32_t scratch_cap,
637 if (out_header ==
nullptr) {
641 if ((read ==
nullptr) || (scratch ==
nullptr)) {
649 .read_ctx = read_ctx,
650 .source_size = source_size,
652 .scratch_cap = scratch_cap,
657 *out_header = ctx.
hdr;
uint32_t priv_book_crc32_extend(uint32_t crc, const uint8_t *data, size_t len)
Extend a reflected CRC-32 over one byte span.
@ 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_node_element
An element: has a tag name and attributes.
@ k_book_node_text
A text run: carries a string, no children.
@ k_book_nil
Absent index / "applies to all chapters".
@ k_book_image_svg
Verbatim UTF-8 SVG source (vector; on-device rasterized).
@ k_book_image_gray4
4bpp gray, 2px/byte; pixel (x,y) is at flat index y*width + x.
@ k_book_pixfmt_gray4
4bpp packed grayscale, 2px/byte (default; every pre-field blob).
@ k_book_pixfmt_gray8
8bpp grayscale, 1px/byte (lossless against any grey panel).
book DOM-walk helpers shared across the library's translation units.
static ra8_err_t internal_validate_images(const stream_validate_t *ctx)
Validate every image descriptor and exact gap-free pool tiling.
static ra8_err_t internal_validate_nodes(const stream_validate_t *ctx)
Validate every DOM node and exact attribute ownership.
static ra8_err_t internal_mark_forward_link(const stream_validate_t *ctx, uint32_t link, uint32_t current)
Record one unique incoming node reference in the caller bitset.
ra8_err_t priv_book_stream_validate_text(const stream_validate_t *ctx, const uint8_t *rec)
Validate one text node's element-only fields and string reference.
static ra8_err_t internal_validate_attrs(const stream_validate_t *ctx)
Validate every attribute name/value string reference.
static ra8_err_t internal_validate_chapters(const stream_validate_t *ctx)
Validate every chapter string and root-node index.
static ra8_err_t internal_validate_body(stream_validate_t *ctx)
Run the strict passes after public argument validation.
static ra8_err_t internal_validate_crc(const stream_validate_t *ctx)
Hash every body byte through the caller transfer buffer.
static ra8_err_t internal_validate_raster(const uint8_t *rec)
Validate one raster image's dimensions, depth, and exact byte count.
static ra8_err_t internal_validate_svg(const uint8_t *rec)
Validate one SVG image's zero extent/depth and raw-storage length.
ra8_err_t priv_book_stream_validate_element(const stream_validate_t *ctx, const uint8_t *rec, uint32_t *attr_cursor)
Validate one element node and its canonical attribute span.
static ra8_err_t internal_validate_one_node(const stream_validate_t *ctx, const uint8_t *rec, uint32_t *attr_cursor, uint32_t index)
Validate one node record's fields and mark its forward links.
static ra8_err_t internal_forward_link(uint32_t link, uint32_t current, uint32_t count)
Validate one optional forward node link.
ra8_err_t priv_book_stream_validate_styles(const stream_validate_t *ctx)
Validate every stylesheet source and optional chapter scope.
ra8_err_t book_validate_stream_strict(book_stream_read_fn read, void *read_ctx, uint64_t source_size, uint8_t *scratch, uint32_t scratch_cap, book_header_t *out_header)
Strictly validate one callback-backed RABOOK1 flat blob.
ra8_err_t priv_book_stream_validate_metadata(const stream_validate_t *ctx)
Validate metadata string references and the optional cover index.
Strict, zero-allocation validation of a streamed RABOOK1 flat blob.
ra8_err_t(* book_stream_read_fn)(void *ctx, uint64_t offset, uint8_t *dst, uint32_t len)
Exact random-read callback over an inflated RABOOK1 flat blob.
Private wire geometry for strict RABOOK1 stream validation.
@ k_stream_image_raw_size
Decoded payload-size field.
@ k_stream_image_pixfmt
Raster pixel-format offset.
@ k_stream_image_data_off
Payload-relative offset field.
@ k_stream_image_format
Image-kind byte offset.
@ k_stream_image_width
Raster-width field offset.
@ k_stream_image_reserved
Reserved-zero field offset.
@ k_stream_image_height
Raster-height field offset.
@ k_stream_image_id
Image-id string offset.
@ k_stream_image_data_size
Stored payload-size field.
static uint32_t internal_book_stream_le32(const uint8_t *p)
Decode one little-endian 32-bit field from unaligned bytes.
ra8_err_t priv_book_stream_validate_string_envelope(const stream_validate_t *ctx)
Validate the string pool's leading and trailing NUL sentinels.
static uint16_t internal_book_stream_le16(const uint8_t *p)
Decode one little-endian 16-bit field from unaligned bytes.
ra8_err_t priv_book_stream_nonempty_string_ref(const stream_validate_t *ctx, uint32_t off)
Require a string reference to name a non-empty interned string.
@ k_stream_node_kind
Node-kind byte offset.
@ k_stream_node_reserved
Reserved-zero byte offset.
@ k_stream_node_first_child
First-child node index field.
@ k_stream_node_name
Element-name string offset.
@ k_stream_node_first_attr
First-attribute index field.
@ k_stream_node_text
Text string-offset field.
@ k_stream_node_attr_count
Attribute-count field offset.
@ k_stream_node_next_sibling
Next-sibling node index field.
ra8_err_t priv_book_stream_read_validate_header(stream_validate_t *ctx)
Read, decode, and validate the canonical stream header and layout.
ra8_err_t priv_book_stream_read(const stream_validate_t *ctx, uint64_t off, uint8_t *dst, uint32_t len)
Read one exact, bounded source span.
ra8_err_t priv_book_stream_string_ref(const stream_validate_t *ctx, uint32_t off)
Require a referenced offset to name an interned-string boundary.
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_invalid_arg
Invalid function argument.
@ k_ra8_err_range_check_failed
Value outside range enforced by RA8_CHECK_RANGE / RA8_CHECK_RANGE_TAG.
@ 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 * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
Immutable validation state shared by the bounded table passes.
uint8_t * scratch
Caller transfer buffer.
uint32_t scratch_cap
Transfer-buffer capacity.
book_header_t hdr
Decoded host-order header.