| 362 | } |
| 363 | |
| 364 | MMKV_EXPORT void *decodeBytes(void *handle, const char *oKey, uint64_t *lengthPtr) { |
| 365 | MMKV *kv = static_cast<MMKV *>(handle); |
| 366 | if (kv && oKey) { |
| 367 | auto key = string(oKey); |
| 368 | mmkv::MMBuffer value; |
| 369 | auto hasValue = kv->getBytes(key, value); |
| 370 | if (hasValue) { |
| 371 | if (value.length() > 0) { |
| 372 | if (value.isStoredOnStack()) { |
| 373 | auto result = malloc(value.length()); |
| 374 | if (result) { |
| 375 | memcpy(result, value.getPtr(), value.length()); |
| 376 | *lengthPtr = value.length(); |
| 377 | } |
| 378 | return result; |
| 379 | } |
| 380 | void *result = value.getPtr(); |
| 381 | *lengthPtr = value.length(); |
| 382 | value.detach(); |
| 383 | return result; |
| 384 | } |
| 385 | *lengthPtr = 0; |
| 386 | // this ptr is intended for checking existence of the value |
| 387 | // don't free this ptr |
| 388 | return value.getPtr(); |
| 389 | } |
| 390 | } |
| 391 | return nullptr; |
| 392 | } |
| 393 | |
| 394 | # ifndef MMKV_DISABLE_CRYPT |
| 395 | |