decode method
Restores a value previously produced by encode.
Implementation
Object? decode(Object? value) {
if (value is List) return value.map(decode).toList(growable: false);
if (value is Map) {
final typed = Map<String, Object?>.from(value);
final tag = typed[r'$type'];
if (tag is String && typed.containsKey(r'$value')) {
if (tag == 'Map') {
final entries = typed[r'$value']! as List;
return <String, Object?>{
for (final entry in entries.cast<List>())
entry[0]! as String: decode(entry[1]),
};
}
final adapter = _byTag[tag];
if (adapter == null) throw FormatException('Unknown type tag: $tag');
return adapter.decode(decode(typed[r'$value']), this);
}
return typed.map((key, item) => MapEntry(key, decode(item)));
}
return value;
}