DrawJson
The library's own file format: a list of shapes written as JSON, losslessly. Everything a shape is comes back as it was — styles (with their pictures), rings and holes, vertex ids and metadata, labels, descriptions, drawing order — so a drawing can be saved and loaded again, and two saves compared.
val text = DrawJson.encode(repository.entities.value)
val shapes = DrawJson.decode(text)The result is a String: where it goes (a file, a database, the network) is the host's business. A picture given as bytes is stored once in the document, in base64, however many shapes use it; one given as a URL is only its URL, so loading it later needs the network.
Every document says which VERSION of the format it is. Newer fields can be added without a new version (an old file just lacks them, and a reader ignores the ones it doesn't know); a file of a newer version than this code knows is refused rather than half understood.