File: dataview_read_write.cc

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (115 lines) | stat: -rw-r--r-- 4,282 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "napi.h"

using namespace Napi;

static Value GetFloat32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetFloat32(byteOffset));
}

static Value GetFloat64(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetFloat64(byteOffset));
}

static Value GetInt8(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetInt8(byteOffset));
}

static Value GetInt16(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetInt16(byteOffset));
}

static Value GetInt32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetInt32(byteOffset));
}

static Value GetUint8(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetUint8(byteOffset));
}

static Value GetUint16(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetUint16(byteOffset));
}

static Value GetUint32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  return Number::New(info.Env(), info[0].As<DataView>().GetUint32(byteOffset));
}

static void SetFloat32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().FloatValue();
  info[0].As<DataView>().SetFloat32(byteOffset, value);
}

static void SetFloat64(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().DoubleValue();
  info[0].As<DataView>().SetFloat64(byteOffset, value);
}

static void SetInt8(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Int32Value();
  info[0].As<DataView>().SetInt8(byteOffset, value);
}

static void SetInt16(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Int32Value();
  info[0].As<DataView>().SetInt16(byteOffset, value);
}

static void SetInt32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Int32Value();
  info[0].As<DataView>().SetInt32(byteOffset, value);
}

static void SetUint8(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Uint32Value();
  info[0].As<DataView>().SetUint8(byteOffset, value);
}

static void SetUint16(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Uint32Value();
  info[0].As<DataView>().SetUint16(byteOffset, value);
}

static void SetUint32(const CallbackInfo& info) {
  size_t byteOffset = info[1].As<Number>().Uint32Value();
  auto value = info[2].As<Number>().Uint32Value();
  info[0].As<DataView>().SetUint32(byteOffset, value);
}

Object InitDataViewReadWrite(Env env) {
  Object exports = Object::New(env);

  exports["getFloat32"] = Function::New(env, GetFloat32);
  exports["getFloat64"] = Function::New(env, GetFloat64);
  exports["getInt8"] = Function::New(env, GetInt8);
  exports["getInt16"] = Function::New(env, GetInt16);
  exports["getInt32"] = Function::New(env, GetInt32);
  exports["getUint8"] = Function::New(env, GetUint8);
  exports["getUint16"] = Function::New(env, GetUint16);
  exports["getUint32"] = Function::New(env, GetUint32);

  exports["setFloat32"] = Function::New(env, SetFloat32);
  exports["setFloat64"] = Function::New(env, SetFloat64);
  exports["setInt8"] = Function::New(env, SetInt8);
  exports["setInt16"] = Function::New(env, SetInt16);
  exports["setInt32"] = Function::New(env, SetInt32);
  exports["setUint8"] = Function::New(env, SetUint8);
  exports["setUint16"] = Function::New(env, SetUint16);
  exports["setUint32"] = Function::New(env, SetUint32);

  return exports;
}