Files
ai-box/cxx/common/node.h
2025-03-07 17:18:20 +08:00

33 lines
877 B
C++

#ifndef __COMMON_NODE_H__
#define __COMMON_NODE_H__
#include <iostream>
#include <map>
#include <napi.h>
#define NODE_INIT_OBJECT(name, function) \
do { \
auto obj = Napi::Object::New(env); \
function(env, obj); \
exports.Set(Napi::String::New(env, #name), obj); \
} while (0)
inline uint64_t __node_ptr_of__(Napi::Value value)
{
bool lossless;
return value.As<Napi::BigInt>().Uint64Value(&lossless);
}
#define NODE_PTR_OF(type, value) (reinterpret_cast<type *>(__node_ptr_of__(value)))
inline void *dataFromTypedArray(const Napi::Value &val, size_t &bytes)
{
auto arr = val.As<Napi::TypedArray>();
auto data = static_cast<uint8_t *>(arr.ArrayBuffer().Data());
bytes = arr.ByteLength();
return static_cast<void *>(data + arr.ByteOffset());
}
#endif