fromJson static method
Reads a digest a host served, or null when there is none to read.
Deliberately hand-written rather than delegating to the generated
PatchbayCatalogDigestWire.fromJson: that decoder rejects unknown
fields, which is right for a request a host has to police and wrong for a
forward-compatibility mechanism. A newer host that attaches something
extra here must leave this reader with a digest it can still evaluate,
not with a decode failure.
Tolerance stops at the edge of covers. An unknown sibling field is
safe to ignore — it does not change what the fields this version does
understand mean. An unreadable entry inside covers is the opposite:
dropping it silently narrows the host's claim, and a narrowed claim that
happens to land on this version's coverage reads as "I understood all of
it" when the truth is "I could not read part of it". So an entry that is
not a string poisons the whole coverage via coversFullyRead, and the
digest degrades to not-recomputable — the same fail-closed answer an
unknown algorithm gets, for the same reason.
Implementation
static PatchbayCatalogDigest? fromJson(Object? value) {
if (value is! Map<Object?, Object?>) return null;
final Object? algorithm = value['algorithm'];
final Object? covers = value['covers'];
final Object? digest = value['value'];
if (algorithm is! String || digest is! String || covers is! List<Object?>) {
return null;
}
return PatchbayCatalogDigest(
algorithm: algorithm,
covers: <String>[
for (final Object? scope in covers)
if (scope is String) scope,
],
coversFullyRead: covers.every((Object? scope) => scope is String),
value: digest,
);
}