encodeBytes method
Encoding bytes.
You can serialize an object into bytes, then store it inside MMKV.
// assume using protobuf https://developers.google.com/protocol-buffers/docs/darttutorial
var object = MyClass();
final list = object.writeToBuffer();
final buffer = MMBuffer.fromList(list);
mmkv.encodeBytes('bytes', buffer);
buffer.destroy();
expireDurationInSecond
override the default duration setting from enableAutoKeyExpire().
- Passing MMKV.ExpireNever (aka 0) will never expire.
Implementation
bool encodeBytes(String key, MMBuffer? value, [int? expireDurationInSecond]) {
if (value == null) {
removeValue(key);
return true;
}
final keyPtr = key.toNativeUtf8();
final ret = (expireDurationInSecond == null)
? _encodeBytes(_handle, keyPtr, value.pointer!, value.length)
: _encodeBytesV2(_handle, keyPtr, value.pointer!, value.length, expireDurationInSecond);
calloc.free(keyPtr);
return _int2Bool(ret);
}