| 369 | } |
| 370 | |
| 371 | NSObject *MMKV::getObject(MMKVKey_t key, Class cls) { |
| 372 | if (isKeyEmpty(key) || !cls) { |
| 373 | return nil; |
| 374 | } |
| 375 | SCOPED_LOCK(m_lock); |
| 376 | SCOPED_LOCK(m_sharedProcessLock); |
| 377 | auto data = getDataForKey(key); |
| 378 | if (data.length() > 0) { |
| 379 | if (MiniPBCoder::isCompatibleClass(cls)) { |
| 380 | try { |
| 381 | auto result = MiniPBCoder::decodeObject(data, cls); |
| 382 | return result; |
| 383 | } catch (std::exception &exception) { |
| 384 | MMKVError("%s", exception.what()); |
| 385 | } catch (...) { |
| 386 | MMKVError("decode fail"); |
| 387 | } |
| 388 | } else { |
| 389 | if ([cls conformsToProtocol:@protocol(NSCoding)]) { |
| 390 | auto tmp = [NSData dataWithBytesNoCopy:data.getPtr() length:data.length() freeWhenDone:NO]; |
| 391 | return unSecureUnArchiveObjectWithData(tmp); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | return nil; |
| 396 | } |
| 397 | |
| 398 | # ifndef MMKV_DISABLE_CRYPT |
| 399 |
nothing calls this directly
no test coverage detected