// mars::stream — top-level save-file API. // // SaveDocument doc = read_save_file(path); // or read_save_bytes(...) // doc.tree generic Node tree (always complete: unknown regions are raw) // doc.game typed shapes applied on top of the tree // doc.issues walker + shape deviations (error / warn / info) // write_save(doc.game) -> inflated bytes; gzip() them for a .sav #pragma once #include #include #include "node.h" #include "shapes.h" namespace mars::stream { struct SaveDocument { Bytes inflated; Node tree; shapes::SaveGame game; std::vector issues; // walker issues first, then shape issues Stats stats; size_t count(Issue::Level l) const { size_t n = 0; for (const Issue& i : issues) n += i.level == l; return n; } }; // Parse a .sav (gzip) or an already-inflated stream. Throws GzipError on a damaged container. SaveDocument read_save_bytes(const uint8_t* p, size_t n); SaveDocument read_save_file(const std::string& path); // Apply the typed shapes to a generic tree (root children = file items). shapes::SaveGame apply_shapes(const Node& root, std::vector& issues); // Serialize typed shapes back to an inflated stream. Bytes write_save(shapes::SaveGame& game); // Re-emit a generic tree (root children) as bytes. Bytes write_tree(const Node& root); std::string format_issue(const Issue& i); } // namespace mars::stream