| 1 | | | import '../build_options.dart'; |
| 2 | | | import '../_impl/xplat/_time_stamp.dart'; |
| 3 | | | |
| 4 | | 1 | extension type StreamId._(int handle) { |
| 5 | | | static int _nextId = 1; |
| 6 | | | |
| 7 | | 3 | factory StreamId.next() => StreamId._(_nextId++); |
| 8 | | | |
| 9 | | 1 | static StreamId? from(dynamic value) => |
| 10 | | 3 | (value is num) ? StreamId._(value.toInt()) : null; |
| 11 | | | } |
| 12 | | | |
| 13 | | | /// Make [WorkerMessage] a `List` to minimize serialization overhead. |
| 14 | | 0 | extension type WorkerMessage(List data) implements Object { |
| 15 | | | /// [travelTime] is set by the receiving end and measures the time (in |
| 16 | | | /// microseconds) it took between the moment the message was serialized and |
| 17 | | | /// the moment it was deserialized. |
| 18 | | 0 | int? get travelTime => |
| 19 | | 0 | BuildOptions.withTravelTime ? data[_$traveltime] : null; |
| 20 | | | |
| 21 | | 1 | void unwrapTravelTime() { |
| 22 | | | if (BuildOptions.withTravelTime) { |
| 23 | | 2 | final ts = Timestamp.from(data[_$traveltime]); |
| 24 | | | if (ts != null) { |
| 25 | | 3 | data[_$traveltime] = Timestamp.now()! - ts; |
| 26 | | | } |
| 27 | | | } |
| 28 | | | } |
| 29 | | | } |
| 30 | | | |
| 31 | | | const _$traveltime = 0; |