Expand description
The wire: a display structure as bytes, with a version in front of it.
JSON is what the content tree serializes to, because a person reads it. The display structure is machine output: every glyph of every page, produced once per keystroke and decoded on someone’s main thread. So it crosses as postcard, which packs varints, sends no field names, and needs no tree of maps built before the first page can be read.
The encoding is positional, which is the price of that: a host’s
decoder reads fields in declaration order and has no way to notice
that the order changed. So a version leads the bytes, VERSION
moves whenever what crosses changes shape, and a host that reads
a number it does not know refuses at the first byte instead of
painting nonsense.
A reply need not carry the whole book: encode_range sends a
slice of the pages and says where it falls, so a host looking at
one page pays for one page. Layout still runs over the whole book
either way; what a range saves is serializing and decoding the
pages nobody asked for. fonts, assets and warnings are never
sliced, since none of them is per page.
An EPUB crosses the same wall behind the same version, with the
warnings writing it raised: see encode_epub. Its files can
cross one by one instead: see encode_epub_files.
Structs§
- Epub
- An EPUB as one wire reply, and what writing it warned about.
- Epub
File - One file of an EPUB.
- Epub
Files - An EPUB as its files, not zipped, and what writing it warned about.
- Epub
Spine Entry - One document of an EPUB’s spine.
- Reply
- What one wire reply carried, and where it falls in the book.
Enums§
- Wire
Error - Why a buffer could not be read as a display structure.
Constants§
- VERSION
- What the encoding is. A host checks this before reading anything else, and a mismatch is a refusal rather than a best effort.
Functions§
- decode
- Reads a reply back, refusing a version this build does not write.
- decode_
epub - Reads an EPUB reply back, refusing a version this build does not write.
- decode_
epub_ files - Reads an EPUB’s files back, refusing a version this build does not write.
- encode
- Encodes the whole display structure, version first.
- encode_
epub - Encodes an EPUB and its warnings, version first.
- encode_
epub_ files - Encodes an EPUB’s files, version first.
- encode_
range - Encodes
countpages starting atfirst, version first. A range past the end of the book is clamped rather than refused: an edit that shortens the book while a page past its new end is still being asked for gets back whatever is left, not a panic. - version
- The version a buffer leads with, without reading the rest of it.