serialization library

Opt-in JSON serialization for the ebook_parser document model.

A separate library, so a caller that only parses never sees it. The encoded shape is a compatibility promise versioned by kBookDocumentSchemaVersion; image bytes stay out of the json and are handed back to the caller — see encodeBookDocument.

Constants

kBookDocumentSchemaVersion → const int
The version of the encoded shape. Written into every encoded document and block, and checked on decode.

Functions

decodeBlock(Map<String, dynamic> json, {Map<String, ImageData> images = const {}, TextSegmenter? segmenter}) Block?
Rebuilds one Block from json and the images its references name.
decodeBookDocument(Map<String, dynamic> json, {Map<String, ImageData> images = const {}, TextSegmenter? segmenter}) BookDocument?
Rebuilds a BookDocument from json and the images its references name.
encodeBlock(Block block) → ({Map<String, ImageData> images, Map<String, dynamic> json})
Encodes one block, with the same two-part shape as encodeBookDocument: an ImageBlock's bytes arrive in the returned images map, not in the json.
encodeBookDocument(BookDocument document) → ({Map<String, ImageData> images, Map<String, dynamic> json})
Encodes document as JSON plus its image bytes.