decode static method
Decodes bytes (UTF-8 of the codec's JSON) and validates the result.
Throws SymbolLibraryError on anything the spec's D5 names, on a
document the codec itself repaired (a definition cycle it dropped an
instance for) and on bytes the codec cannot read at all.
Implementation
static SymbolLibrary decode(Uint8List bytes) {
final diagnostics = <Diagnostic>[];
final DraftDocument doc;
try {
doc = DraftDocumentCodec.decodeString(
utf8.decode(bytes),
diagnostics: diagnostics,
registerComponents: registerAppComponents,
);
} catch (e) {
// FormatException, SchemaVersionError, a TypeError from a mistyped
// field, a DuplicateHandleError: all mean "not a readable library".
throw SymbolLibraryError('not a readable library: $e');
}
return SymbolLibrary._(_validate(doc, diagnostics));
}