encodeLibrary function
The .jetlib bytes of catalog: the codec's JSON of
buildLibraryDocument, UTF-8. The same catalog gives the same bytes.
Decodes its own output: throws the SymbolLibraryError of a catalog the format refuses, so a generator never writes such a library.
Implementation
Uint8List encodeLibrary(Catalog catalog) {
final doc = buildLibraryDocument(catalog);
try {
final bytes =
Uint8List.fromList(utf8.encode(DraftDocumentCodec.encodeToString(doc)));
SymbolLibrary.decode(bytes);
return bytes;
} finally {
unawaited(doc.dispose());
}
}