37 lines
973 B
Dart
37 lines
973 B
Dart
import 'dart:async';
|
|
import 'dart:typed_data';
|
|
|
|
import '../proto/messages.pb.dart';
|
|
import 'decoder_base.dart';
|
|
|
|
export 'decoder_base.dart';
|
|
|
|
/// Web decoder. Isolates aren't available the same way on Web, so decoding
|
|
/// runs synchronously on the main isolate. At 1 kHz with small protobuf
|
|
/// messages this is acceptable.
|
|
class DecoderInline implements Decoder {
|
|
final StreamController<Envelope> _out = StreamController.broadcast();
|
|
|
|
@override
|
|
Stream<Envelope> get envelopes => _out.stream;
|
|
|
|
@override
|
|
void feed(Uint8List frame) {
|
|
try {
|
|
final env = Envelope.fromBuffer(frame);
|
|
_out.add(env);
|
|
} catch (_) {
|
|
// Malformed packet — silently dropped.
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> dispose() async {
|
|
await _out.close();
|
|
}
|
|
}
|
|
|
|
class DecoderImpl extends DecoderInline {
|
|
// The inline decoder takes no batchInterval; accept and ignore for API parity.
|
|
DecoderImpl({Duration batchInterval = const Duration(milliseconds: 8)});
|
|
} |