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

Function encodeBytes

OpenHarmony/MMKV/src/main/cpp/native_bridge.cpp:1134–1156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1132}
1133
1134static napi_value encodeBytes(napi_env env, napi_callback_info info) {
1135 size_t argc = 6;
1136 napi_value args[6] = {nullptr};
1137 NAPI_CALL(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
1138
1139 auto handle = NValueToUInt64(env, args[0]);
1140 auto key = NValueToString(env, args[1]);
1141 MMKV *kv = reinterpret_cast<MMKV *>(handle);
1142 if (kv && key.length() > 0) {
1143 auto buffer = NValueToMMBuffer(env, args[2]);
1144 auto offset = NValueToUInt32(env, args[3]);
1145 auto length = NValueToUInt32(env, args[4]);
1146 auto value = MMBuffer((uint8_t *)buffer.getPtr() + offset, length, mmkv::MMBufferNoCopy);
1147 if (IsNValueUndefined(env, args[5])) {
1148 auto ret = kv->set(value, key);
1149 return BoolToNValue(env, ret);
1150 }
1151 uint32_t expiration = NValueToUInt32(env, args[5]);
1152 auto ret = kv->set(value, key, expiration);
1153 return BoolToNValue(env, ret);
1154 }
1155 return BoolToNValue(env, false);
1156}
1157
1158static napi_value decodeBytes(napi_env env, napi_callback_info info) {
1159 size_t argc = 3;

Callers

nothing calls this directly

Calls 8

NValueToUInt64Function · 0.85
NValueToMMBufferFunction · 0.85
NValueToUInt32Function · 0.85
NValueToStringFunction · 0.70
IsNValueUndefinedFunction · 0.70
BoolToNValueFunction · 0.70
MMBufferFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected