forked from Henry-Hiles/nexus
working build
This commit is contained in:
parent
058f68cffb
commit
20f69ca0aa
7 changed files with 55 additions and 35 deletions
|
|
@ -5,7 +5,7 @@ import "dart:typed_data";
|
|||
import "package:ffi/ffi.dart";
|
||||
import "package:nexus/src/third_party/gomuks.g.dart";
|
||||
|
||||
extension GomuksBufferToJson on GomuksBorrowedBuffer {
|
||||
extension GomuksBorrowedBufferToJson on GomuksBorrowedBuffer {
|
||||
Uint8List toBytes() {
|
||||
if (base == nullptr || length <= 0) return Uint8List(0);
|
||||
return base.asTypedList(length);
|
||||
|
|
@ -18,22 +18,39 @@ extension GomuksBufferToJson on GomuksBorrowedBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||
// GomuksBorrowedBuffer toGomuksBuffer() {
|
||||
// final jsonString = json.encode(this);
|
||||
// final bytes = utf8.encode(jsonString);
|
||||
extension GomuksOwnedBufferToJson on GomuksOwnedBuffer {
|
||||
Uint8List toBytes() {
|
||||
try {
|
||||
if (base == nullptr || length <= 0) return Uint8List(0);
|
||||
return Uint8List.fromList(base.asTypedList(length));
|
||||
} finally {
|
||||
calloc.free(base);
|
||||
}
|
||||
}
|
||||
|
||||
// final dataPtr = calloc<Uint8>(bytes.length);
|
||||
// dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
||||
|
||||
// final bufPtr = calloc<GomuksBuffer>();
|
||||
// bufPtr.ref.base = dataPtr;
|
||||
// bufPtr.ref.length = bytes.length;
|
||||
|
||||
// final bufByValue = bufPtr.ref;
|
||||
|
||||
// calloc.free(bufPtr);
|
||||
|
||||
// return bufByValue;
|
||||
// }
|
||||
Map<String, dynamic> toJson() {
|
||||
final bytes = toBytes();
|
||||
if (bytes.isEmpty) return {};
|
||||
return jsonDecode(utf8.decode(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||
GomuksBorrowedBuffer toGomuksBuffer() {
|
||||
final jsonString = json.encode(this);
|
||||
final bytes = utf8.encode(jsonString);
|
||||
|
||||
final dataPtr = calloc<Uint8>(bytes.length);
|
||||
dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
||||
|
||||
final bufPtr = calloc<GomuksBorrowedBuffer>();
|
||||
bufPtr.ref.base = dataPtr;
|
||||
bufPtr.ref.length = bytes.length;
|
||||
|
||||
final bufByValue = bufPtr.ref;
|
||||
|
||||
calloc.free(bufPtr);
|
||||
|
||||
return bufByValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue