1 | | | import 'dart:collection'; |
2 | | |
|
3 | | | import 'package:meta/meta.dart'; |
4 | | |
|
5 | | | class SerializationContext { |
6 | | 4 | SerializationContext(bool Function(Object, Object) identical) |
7 | | 4 | : _cache = HashMap(equals: identical); |
8 | | |
|
9 | | | final HashMap<Object, Object> _cache; |
10 | | |
|
11 | | 4 | T? getReference<T extends Object>(Object data) { |
12 | | 8 | final ref = _cache[data]; |
13 | | 4 | return (ref is T) ? ref : null; |
14 | | | } |
15 | | |
|
16 | | 4 | void setReference<T extends Object>(Object data, T instance) { |
17 | | 8 | _cache[data] = instance; |
18 | | | } |
19 | | | } |
20 | | |
|
21 | | | @internal |
22 | | | extension SerializationContextImpl on SerializationContext { |
23 | | 3 | void reset() => _cache.clear(); |
24 | | |
|
25 | | 0 | Map<Object, Object> get cache => _cache; |
26 | | | } |