WorldManifest.parse constructor
Parse manifest file bytes (UTF-8 JSON).
Implementation
factory WorldManifest.parse(List<int> bytes) {
final String text;
try {
text = utf8.decode(bytes);
} on FormatException {
throw const WorldManifestError(
'world manifest is not valid UTF-8 --> fix: re-save the manifest '
'as UTF-8 JSON.',
);
}
final dynamic doc;
try {
doc = jsonDecode(text);
} on FormatException catch (e) {
throw WorldManifestError(
'world manifest is not valid JSON (${e.message}) '
'--> fix: repair the manifest JSON.',
);
}
if (doc is! Map<String, dynamic>) {
throw const WorldManifestError(
'world manifest is not a JSON object --> fix: the manifest must '
'be a JSON object at the top level.',
);
}
return WorldManifest.fromDocument(doc);
}