1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "napi/native_api.h" 17#include "napi/native_node_api.h" 18#include "tools/log.h" 19 20extern const char _binary_json_js_js_start[]; 21extern const char _binary_json_js_js_end[]; 22extern const char _binary_json_abc_start[]; 23extern const char _binary_json_abc_end[]; 24 25static napi_value JsonInit(napi_env env, napi_value exports) 26{ 27 return exports; 28} 29 30extern "C" 31__attribute__((visibility("default"))) void NAPI_util_json_GetJSCode(const char **buf, int *bufLen) 32{ 33 if (buf != nullptr) { 34 *buf = _binary_json_js_js_start; 35 } 36 37 if (bufLen != nullptr) { 38 *bufLen = _binary_json_js_js_end - _binary_json_js_js_start; 39 } 40} 41extern "C" 42__attribute__((visibility("default"))) void NAPI_util_json_GetABCCode(const char** buf, int* buflen) 43{ 44 if (buf != nullptr) { 45 *buf = _binary_json_abc_start; 46 } 47 if (buflen != nullptr) { 48 *buflen = _binary_json_abc_end - _binary_json_abc_start; 49 } 50} 51 52static napi_module_with_js jsonModule = { 53 .nm_version = 1, 54 .nm_flags = 0, 55 .nm_filename = nullptr, 56 .nm_register_func = JsonInit, 57 .nm_modname = "util.json", 58 .nm_priv = ((void*)0), 59 .nm_get_abc_code = NAPI_util_json_GetABCCode, 60 .nm_get_js_code = NAPI_util_json_GetJSCode, 61}; 62 63extern "C" __attribute__ ((constructor)) void JsonRegisterModule() 64{ 65 napi_module_with_js_register(&jsonModule); 66} 67