11cb0ef41Sopenharmony_ci#include <node.h> 21cb0ef41Sopenharmony_ci#include <v8.h> 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cinamespace { 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci#define ENCODING_MAP(V) \ 71cb0ef41Sopenharmony_ci V(ASCII) \ 81cb0ef41Sopenharmony_ci V(BASE64) \ 91cb0ef41Sopenharmony_ci V(BASE64URL) \ 101cb0ef41Sopenharmony_ci V(BUFFER) \ 111cb0ef41Sopenharmony_ci V(HEX) \ 121cb0ef41Sopenharmony_ci V(LATIN1) \ 131cb0ef41Sopenharmony_ci V(UCS2) \ 141cb0ef41Sopenharmony_ci V(UTF8) \ 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cistatic_assert(node::BINARY == node::LATIN1, "BINARY == LATIN1"); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_civoid ParseEncoding(const v8::FunctionCallbackInfo<v8::Value>& args) { 191cb0ef41Sopenharmony_ci const node::encoding encoding = 201cb0ef41Sopenharmony_ci node::ParseEncoding(args.GetIsolate(), args[0], 211cb0ef41Sopenharmony_ci static_cast<node::encoding>(-1)); 221cb0ef41Sopenharmony_ci const char* encoding_name = "UNKNOWN"; 231cb0ef41Sopenharmony_ci#define V(name) if (encoding == node::name) encoding_name = #name; 241cb0ef41Sopenharmony_ci ENCODING_MAP(V) 251cb0ef41Sopenharmony_ci#undef V 261cb0ef41Sopenharmony_ci auto encoding_string = 271cb0ef41Sopenharmony_ci v8::String::NewFromUtf8(args.GetIsolate(), encoding_name) 281cb0ef41Sopenharmony_ci .ToLocalChecked(); 291cb0ef41Sopenharmony_ci args.GetReturnValue().Set(encoding_string); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_civoid Initialize(v8::Local<v8::Object> exports) { 331cb0ef41Sopenharmony_ci NODE_SET_METHOD(exports, "parseEncoding", ParseEncoding); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci} // anonymous namespace 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ciNODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) 39