make it more clear which methods free the buffer

This commit is contained in:
Henry Hiles 2026-10-05 10:11:16 -04:00
commit 02c486e1b3
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 6 additions and 5 deletions

View file

@ -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> {