make it more clear which methods free the buffer
This commit is contained in:
parent
b694da31f9
commit
02c486e1b3
3 changed files with 6 additions and 5 deletions
|
|
@ -1,20 +1,21 @@
|
|||
import "dart:convert";
|
||||
import "dart:ffi";
|
||||
import "dart:typed_data";
|
||||
|
||||
import "package:ffi/ffi.dart";
|
||||
import "package:nexus/src/third_party/gomuks.g.dart";
|
||||
|
||||
extension GomuksOwnedBufferToX on GomuksOwnedBuffer {
|
||||
Uint8List toBytes() {
|
||||
Uint8List toBytesAndFree() {
|
||||
try {
|
||||
if (base == nullptr || length <= 0) return .new(0);
|
||||
return .fromList(base.asTypedList(length));
|
||||
} finally {
|
||||
calloc.free(base);
|
||||
GomuksFreeBuffer(this);
|
||||
}
|
||||
}
|
||||
|
||||
dynamic toJson() => jsonDecode(utf8.decode(toBytes()));
|
||||
dynamic toJsonAndFree() => jsonDecode(utf8.decode(toBytesAndFree()));
|
||||
}
|
||||
|
||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue