MCPcopy Create free account
hub / github.com/Tencent/MMKV / decodeBytes

Function decodeBytes

flutter/mmkv_linux/linux/flutter-bridge.cpp:342–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342MMKV_EXPORT void *decodeBytes(void *handle, const char *oKey, uint64_t *lengthPtr) {
343 MMKV *kv = static_cast<MMKV *>(handle);
344 if (kv && oKey) {
345 auto key = string(oKey);
346 mmkv::MMBuffer value;
347 auto hasValue = kv->getBytes(key, value);
348 if (hasValue) {
349 if (value.length() > 0) {
350 if (value.isStoredOnStack()) {
351 auto result = malloc(value.length());
352 if (result) {
353 memcpy(result, value.getPtr(), value.length());
354 *lengthPtr = value.length();
355 }
356 return result;
357 }
358 void *result = value.getPtr();
359 *lengthPtr = value.length();
360 value.detach();
361 return result;
362 }
363 *lengthPtr = 0;
364 // this ptr is intended for checking existence of the value
365 // don't free this ptr
366 return value.getPtr();
367 }
368 }
369 return nullptr;
370}
371
372# ifndef MMKV_DISABLE_CRYPT
373

Callers

nothing calls this directly

Calls 2

detachMethod · 0.80
getBytesMethod · 0.45

Tested by

no test coverage detected