fromJson<KeyType extends Object> static method
- Map<
String, Object?> json, - StateValueDecoder<
KeyType> decodeKey
Decodes a reference-counted associative image.
Implementation
static ReferenceCountedAssociativeTableImage<KeyType>
fromJson<KeyType extends Object>(
Map<String, Object?> json,
StateValueDecoder<KeyType> decodeKey,
) {
_validateHeader(json, kind, version);
final capacity = _positiveInt(json, 'capacity');
final decoded =
List<ReferenceCountedAssociativeEntryImage<KeyType>?>.filled(
capacity, null);
for (final encoded in _entryList(json)) {
final entry = _entryMap(encoded);
final index = _entryIndex(entry, capacity);
final referenceCount = entry['referenceCount'];
if (decoded[index] != null) {
throw FormatException('Duplicate state entry index $index.');
}
if (referenceCount is! int || referenceCount <= 0) {
throw const FormatException(
'referenceCount must be a positive integer.');
}
decoded[index] = ReferenceCountedAssociativeEntryImage(
key: decodeKey(entry['key']),
referenceCount: referenceCount,
);
}
return ReferenceCountedAssociativeTableImage(decoded);
}