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
|
|
@ -108,7 +108,7 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
() => callback(handle, bufferPointer.ref),
|
() => callback(handle, bufferPointer.ref),
|
||||||
);
|
);
|
||||||
|
|
||||||
final json = response.buf.toJson();
|
final json = response.buf.toJsonAndFree();
|
||||||
|
|
||||||
if (response.command.cast<Utf8>().toDartString() == "error") {
|
if (response.command.cast<Utf8>().toDartString() == "error") {
|
||||||
throw json;
|
throw json;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class GomuksListenerController extends AsyncNotifier<void> {
|
||||||
try {
|
try {
|
||||||
final muksEventType = command.cast<Utf8>().toDartString();
|
final muksEventType = command.cast<Utf8>().toDartString();
|
||||||
debugPrint("Handling $muksEventType...");
|
debugPrint("Handling $muksEventType...");
|
||||||
final decodedMuksEvent = data.toJson();
|
final decodedMuksEvent = data.toJsonAndFree();
|
||||||
|
|
||||||
switch (muksEventType) {
|
switch (muksEventType) {
|
||||||
case "client_state":
|
case "client_state":
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
import "dart:convert";
|
import "dart:convert";
|
||||||
import "dart:ffi";
|
import "dart:ffi";
|
||||||
import "dart:typed_data";
|
import "dart:typed_data";
|
||||||
|
|
||||||
import "package:ffi/ffi.dart";
|
import "package:ffi/ffi.dart";
|
||||||
import "package:nexus/src/third_party/gomuks.g.dart";
|
import "package:nexus/src/third_party/gomuks.g.dart";
|
||||||
|
|
||||||
extension GomuksOwnedBufferToX on GomuksOwnedBuffer {
|
extension GomuksOwnedBufferToX on GomuksOwnedBuffer {
|
||||||
Uint8List toBytes() {
|
Uint8List toBytesAndFree() {
|
||||||
try {
|
try {
|
||||||
if (base == nullptr || length <= 0) return .new(0);
|
if (base == nullptr || length <= 0) return .new(0);
|
||||||
return .fromList(base.asTypedList(length));
|
return .fromList(base.asTypedList(length));
|
||||||
} finally {
|
} finally {
|
||||||
calloc.free(base);
|
GomuksFreeBuffer(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic toJson() => jsonDecode(utf8.decode(toBytes()));
|
dynamic toJsonAndFree() => jsonDecode(utf8.decode(toBytesAndFree()));
|
||||||
}
|
}
|
||||||
|
|
||||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue