Skip to content

Commit

Permalink
Add converter for int8_t
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Apr 12, 2024
1 parent f2fe76a commit 3025f2b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@ struct Type<void*> {
}
};

template<>
struct Type<int8_t> {
static constexpr const char* name = "Integer";
static inline napi_status ToNode(napi_env env,
int8_t value,
napi_value* result) {
return napi_create_int32(env, value, result);
}
static napi_status FromNode(napi_env env, napi_value value, int8_t* out) {
int32_t val;
napi_status s = napi_get_value_int32(env, value, &val);
if (s != napi_ok)
return s;
*out = static_cast<int8_t>(val);
return napi_ok;
}
};

template<>
struct Type<uint8_t> {
static constexpr const char* name = "Integer";
static inline napi_status ToNode(napi_env env,
uint8_t value,
napi_value* result) {
return napi_create_uint32(env, value, result);
}
static napi_status FromNode(napi_env env, napi_value value, uint8_t* out) {
uint32_t val;
napi_status s = napi_get_value_uint32(env, value, &val);
if (s != napi_ok)
return s;
*out = static_cast<uint8_t>(val);
return napi_ok;
}
};

template<>
struct Type<int32_t> {
static constexpr const char* name = "Integer";
Expand Down

0 comments on commit 3025f2b

Please sign in to comment.