| 1132 | } |
| 1133 | |
| 1134 | static 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 | |
| 1158 | static napi_value decodeBytes(napi_env env, napi_callback_info info) { |
| 1159 | size_t argc = 3; |
nothing calls this directly
no test coverage detected