mirror of https://github.com/AMT-Cheif/drift.git
Preserve Uint8Lists in serialization (#1802)
This commit is contained in:
parent
70e1d040ab
commit
49668e3a57
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>()]),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue