Preserve Uint8Lists in serialization (#1802)

This commit is contained in:
Simon Binder 2022-04-12 18:30:44 +02:00
parent 70e1d040ab
commit 49668e3a57
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 27 additions and 2 deletions

View File

@ -253,8 +253,8 @@ class DriftProtocol {
}
Object? _decodeDbValue(Object? wire) {
if (wire is List) {
return wire.cast<int>();
if (wire is List && wire is! Uint8List) {
return Uint8List.fromList(wire.cast());
} else {
return wire;
}

View File

@ -1,5 +1,7 @@
import 'package:async/async.dart';
import 'package:drift/drift.dart';
import 'package:drift/remote.dart';
import 'package:drift/src/remote/protocol.dart';
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';
@ -20,4 +22,27 @@ void main() {
await shutdown(transformed);
});
test('Uint8Lists are mapped from and to Uint8Lists', () async {
const protocol = DriftProtocol();
final request = Request(
1,
ExecuteQuery(StatementMethod.select, 'SELECT ?', [
Uint8List.fromList([1, 2, 3])
]),
);
final mapped = protocol.deserialize(protocol.serialize(request)!);
expect(
mapped,
isA<Request>().having((e) => e.id, 'id', 1).having(
(e) => e.payload,
'payload',
isA<ExecuteQuery>()
.having((e) => e.method, 'method', StatementMethod.select)
.having((e) => e.args, 'args', [isA<Uint8List>()]),
),
);
});
}