LCOV - code coverage report

Current view
top level - src/marshalers - marshaling_context.dart
Test
lcov.info
Date
2025-03-26
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines122060.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import '../converters/context_aware_converter.dart';
2import '../converters/converter.dart';
3import '../converters/serialization_context.dart';
4import '../squadron_singleton.dart';
5import '../typedefs.dart';
6
7/// Marshaling context. Context-aware marshalers can register marshaled /
8/// unmarshaled instances; if the same input is encountered, the same instance
9/// can be fetched from the context instead of marshaling/unmarshaling a fresh
10/// instance. Context-aware marshalers can be used where object identities
11/// matter. Additionally, they also help support serialization of instances
12/// that bear cyclical dependencies.
13class MarshalingContext {
142 MarshalingContext({bool contextAware = true})
15 : _converter =
163 contextAware ? ContextAwareConverter() : Squadron.converter,
172 _objects = contextAware ? SerializationContext(identical) : null;
18
19 /// [none] can be used as a context-unaware converter.
20 static const MarshalingContext? none = null;
21
22 /// [Converter] to convert data before marshaling/unmarshaling. In a context-
23 /// aware marshaling context, the converter also keeps track of raw data
24 /// received from / sent to the worker
25 final Converter _converter;
26
27 final SerializationContext? _objects;
28
29 /// Whether this context is context-aware.
302 bool get isContextAware => _objects != null;
31
32 /// Get the instance that was registered for the same [data].
332 T? getReference<T extends Object>(dynamic data) =>
344 _objects?.getReference(data);
35
36 /// Register [instance] for this [data].
372 void setReference<T extends Object>(dynamic data, T instance) =>
384 _objects?.setReference(data, instance);
39}
40
41/// Make MarshalingContext? a converter
42extension ConverterExt on MarshalingContext? {
434 Converter get converter => this?._converter ?? Squadron.converter;
44
453 Cast<T> value<T extends Object>() => converter.value<T>();
46
472 Cast<List<T>> list<T extends Object>([Cast<T>? cast]) =>
484 converter.list<T>(cast);
49
500 Cast<List<T?>> nlist<T extends Object>([Cast<T>? cast]) =>
510 converter.nlist(cast);
52
530 Cast<Set<T>> set<T extends Object>([Cast<T>? cast]) => converter.set<T>(cast);
54
550 Cast<Set<T?>> nset<T extends Object>([Cast<T>? cast]) => converter.nset(cast);
56
570 Cast<Map<K, V>> map<K extends Object, V extends Object>(
58 {Cast<K>? kcast, Cast<V>? vcast}) =>
590 converter.map<K, V>(kcast: kcast, vcast: vcast);
60
610 Cast<Map<K, V?>> nmap<K extends Object, V extends Object>(
62 {Cast<K>? kcast, Cast<V>? vcast}) =>
630 converter.nmap<K, V>(kcast: kcast, vcast: vcast);
64}
Choose Features