decodeBytes method
Decoding bytes.
You can decode bytes from MMKV, then deserialize an object from the bytes.
// assume using protobuf https://developers.google.com/protocol-buffers/docs/darttutorial
final bytes = mmkv.decodeBytes('bytes');
if (bytes != null) {
final list = bytes.asList();
final object = MyClass.fromBuffer(list);
// Must [destroy()] after no longer use.
bytes.destroy();
}
Implementation
MMBuffer? decodeBytes(String key) {
final keyPtr = key.toNativeUtf8();
final lengthPtr = calloc<Uint64>();
final ret = _decodeBytes(_handle, keyPtr, lengthPtr);
calloc.free(keyPtr);
if (/*ret != null && */ ret != nullptr) {
final length = lengthPtr.value;
calloc.free(lengthPtr);
if (Platform.isIOS || length == 0) {
return MMBuffer._copyFromPointer(ret, length);
} else {
return MMBuffer._fromPointer(ret, length);
}
}
calloc.free(lengthPtr);
return null;
}