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

Function decodeBytes

OpenHarmony/MMKV/src/main/cpp/flutter-bridge.cpp:361–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

detachMethod · 0.80
getBytesMethod · 0.45

Tested by

no test coverage detected