|
1 | 1 | import 'dart:ffi'; |
2 | | -import 'dart:typed_data' show Uint8List; |
3 | 2 |
|
4 | 3 | import 'package:ffi/ffi.dart' show allocate, free, Utf8; |
5 | 4 |
|
6 | | -import '../common.dart'; |
7 | 5 | import 'bindings.dart'; |
8 | 6 |
|
9 | 7 | // ignore_for_file: public_member_api_docs |
@@ -31,56 +29,6 @@ R executeWithIdArray<R>(List<int> items, R Function(Pointer<OBX_id_array>) fn) { |
31 | 29 | } |
32 | 30 | } |
33 | 31 |
|
34 | | -class OBX_bytes_wrapper { |
35 | | - final Pointer<OBX_bytes> _cBytes; |
36 | | - |
37 | | - int get size => _cBytes == nullptr ? 0 : _cBytes.ref.size; |
38 | | - |
39 | | - Uint8List get data => safeDataAccess(_cBytes); |
40 | | - |
41 | | - /// Get access to the data (no-copy) |
42 | | - static Uint8List safeDataAccess(Pointer<OBX_bytes> /*?*/ cBytes) => |
43 | | - cBytes == null || cBytes.address == 0 || cBytes.ref.size == 0 |
44 | | - ? throw ObjectBoxException( |
45 | | - dartMsg: "can't access data of empty OBX_bytes") |
46 | | - : cBytes.ref.data.cast<Uint8>().asTypedList(cBytes.ref.size); |
47 | | - |
48 | | - bool get isEmpty => size == 0; |
49 | | - |
50 | | - Pointer<Void> get ptr => _cBytes.ref.data; |
51 | | - |
52 | | - /// Returns a pointer to OBX_bytes with copy of the passed data. |
53 | | - /// Warning: this creates two unmanaged pointers which must be freed manually: |
54 | | - /// [freeManaged()]. |
55 | | - /// ObjectBox requires object data to be aligned to the length of 4. |
56 | | - OBX_bytes_wrapper.managedCopyOf(Uint8List data, {/*required*/ bool align}) |
57 | | - : _cBytes = allocate<OBX_bytes>() { |
58 | | - final bytes = _cBytes.ref; |
59 | | - |
60 | | - bytes.size = align ? ((data.length + 3.0) ~/ 4.0) * 4 : data.length; |
61 | | - |
62 | | - // NOTE: currently there's no way to get access to the underlying memory of |
63 | | - // Uint8List to avoid a copy. |
64 | | - // See https://github.com/dart-lang/ffi/issues/27 |
65 | | - // if (data.length == bytes.length) { |
66 | | - // bytes._dataPtr = data.some-way-to-get-the-underlying-memory-pointer |
67 | | - // return ptr; |
68 | | - // } |
69 | | - |
70 | | - // create a copy of the data |
71 | | - bytes.data = allocate<Uint8>(count: bytes.size).cast<Void>(); |
72 | | - for (var i = 0; i < data.length; ++i) { |
73 | | - bytes.data.cast<Uint8>()[i] = data[i]; |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - /// Free a dart-created OBX_bytes pointer. |
78 | | - void freeManaged() { |
79 | | - free(_cBytes.ref.data); |
80 | | - free(_cBytes); |
81 | | - } |
82 | | -} |
83 | | - |
84 | 32 | class OBX_string_array_wrapper { |
85 | 33 | final Pointer<OBX_string_array> _cPtr; |
86 | 34 |
|
|
0 commit comments