|
| 1 | +# DataView |
| 2 | + |
| 3 | +The `Napi::DataView` class corresponds to the |
| 4 | +[JavaScript `DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) |
| 5 | +class. |
| 6 | + |
| 7 | +## Methods |
| 8 | + |
| 9 | +### New |
| 10 | + |
| 11 | +Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. |
| 12 | + |
| 13 | +```cpp |
| 14 | +static Napi::DataView New(napi_env env, Napi::ArrayBuffer arrayBuffer); |
| 15 | +``` |
| 16 | +
|
| 17 | +- `[in] env`: The environment in which to create the `Napi::DataView` instance. |
| 18 | +- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. |
| 19 | +
|
| 20 | +Returns a new `Napi::DataView` instance. |
| 21 | +
|
| 22 | +### New |
| 23 | +
|
| 24 | +Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. |
| 25 | +
|
| 26 | +```cpp |
| 27 | +static Napi::DataView New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset); |
| 28 | +``` |
| 29 | + |
| 30 | +- `[in] env`: The environment in which to create the `Napi::DataView` instance. |
| 31 | +- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. |
| 32 | +- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`. |
| 33 | + |
| 34 | +Returns a new `Napi::DataView` instance. |
| 35 | + |
| 36 | +### New |
| 37 | + |
| 38 | +Allocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. |
| 39 | + |
| 40 | +```cpp |
| 41 | +static Napi::DataView New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset, size_t byteLength); |
| 42 | +``` |
| 43 | +
|
| 44 | +- `[in] env`: The environment in which to create the `Napi::DataView` instance. |
| 45 | +- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. |
| 46 | +- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`. |
| 47 | +- `[in] byteLength` : Number of elements in the `Napi::DataView`. |
| 48 | +
|
| 49 | +Returns a new `Napi::DataView` instance. |
| 50 | +
|
| 51 | +### Constructor |
| 52 | +
|
| 53 | +Initializes an empty instance of the `Napi::DataView` class. |
| 54 | +
|
| 55 | +```cpp |
| 56 | +DataView(); |
| 57 | +``` |
| 58 | + |
| 59 | +### Constructor |
| 60 | + |
| 61 | +Initializes a wrapper instance of an existing `Napi::DataView` instance. |
| 62 | + |
| 63 | +```cpp |
| 64 | +DataView(napi_env env, napi_value value); |
| 65 | +``` |
| 66 | +
|
| 67 | +- `[in] env`: The environment in which to create the `Napi::DataView` instance. |
| 68 | +- `[in] value`: The `Napi::DataView` reference to wrap. |
| 69 | +
|
| 70 | +### ArrayBuffer |
| 71 | +
|
| 72 | +```cpp |
| 73 | +Napi::ArrayBuffer ArrayBuffer() const; |
| 74 | +``` |
| 75 | + |
| 76 | +Returns the backing array buffer. |
| 77 | + |
| 78 | +### ByteOffset |
| 79 | + |
| 80 | +```cpp |
| 81 | +size_t ByteOffset() const; |
| 82 | +``` |
| 83 | + |
| 84 | +Returns the offset into the `Napi::DataView` where the array starts, in bytes. |
| 85 | + |
| 86 | +### ByteLength |
| 87 | + |
| 88 | +```cpp |
| 89 | +size_t ByteLength() const; |
| 90 | +``` |
| 91 | + |
| 92 | +Returns the length of the array, in bytes. |
| 93 | + |
| 94 | +### GetFloat32 |
| 95 | + |
| 96 | +```cpp |
| 97 | +float GetFloat32(size_t byteOffset) const; |
| 98 | +``` |
| 99 | +
|
| 100 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 101 | +
|
| 102 | +Returns a signed 32-bit float (float) at the specified byte offset from the start of the `DataView`. |
| 103 | +
|
| 104 | +### GetFloat64 |
| 105 | +
|
| 106 | +```cpp |
| 107 | +double GetFloat64(size_t byteOffset) const; |
| 108 | +``` |
| 109 | + |
| 110 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 111 | + |
| 112 | +Returns a signed 64-bit float (double) at the specified byte offset from the start of the `Napi::DataView`. |
| 113 | + |
| 114 | +### GetInt8 |
| 115 | + |
| 116 | +```cpp |
| 117 | +int8_t GetInt8(size_t byteOffset) const; |
| 118 | +``` |
| 119 | +
|
| 120 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 121 | +
|
| 122 | +Returns a signed 8-bit integer (byte) at the specified byte offset from the start of the `Napi::DataView`. |
| 123 | +
|
| 124 | +### GetInt16 |
| 125 | +
|
| 126 | +```cpp |
| 127 | +int16_t GetInt16(size_t byteOffset) const; |
| 128 | +``` |
| 129 | + |
| 130 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 131 | + |
| 132 | +Returns a signed 16-bit integer (short) at the specified byte offset from the start of the `Napi::DataView`. |
| 133 | + |
| 134 | +### GetInt32 |
| 135 | + |
| 136 | +```cpp |
| 137 | +int32_t GetInt32(size_t byteOffset) const; |
| 138 | +``` |
| 139 | +
|
| 140 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 141 | +
|
| 142 | +Returns a signed 32-bit integer (long) at the specified byte offset from the start of the `Napi::DataView`. |
| 143 | +
|
| 144 | +### GetUint8 |
| 145 | +
|
| 146 | +```cpp |
| 147 | +uint8_t GetUint8(size_t byteOffset) const; |
| 148 | +``` |
| 149 | + |
| 150 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 151 | + |
| 152 | +Returns a unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the `Napi::DataView`. |
| 153 | + |
| 154 | +### GetUint16 |
| 155 | + |
| 156 | +```cpp |
| 157 | +uint16_t GetUint16(size_t byteOffset) const; |
| 158 | +``` |
| 159 | +
|
| 160 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 161 | +
|
| 162 | +Returns a unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the `Napi::DataView`. |
| 163 | +
|
| 164 | +### GetUint32 |
| 165 | +
|
| 166 | +```cpp |
| 167 | +uint32_t GetUint32(size_t byteOffset) const; |
| 168 | +``` |
| 169 | + |
| 170 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 171 | + |
| 172 | +Returns a unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the `Napi::DataView`. |
| 173 | + |
| 174 | +### SetFloat32 |
| 175 | + |
| 176 | +```cpp |
| 177 | +void SetFloat32(size_t byteOffset, float value) const; |
| 178 | +``` |
| 179 | +
|
| 180 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 181 | +- `[in] value`: The value to set. |
| 182 | +
|
| 183 | +### SetFloat64 |
| 184 | +
|
| 185 | +```cpp |
| 186 | +void SetFloat64(size_t byteOffset, double value) const; |
| 187 | +``` |
| 188 | + |
| 189 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 190 | +- `[in] value`: The value to set. |
| 191 | + |
| 192 | +### SetInt8 |
| 193 | + |
| 194 | +```cpp |
| 195 | +void SetInt8(size_t byteOffset, int8_t value) const; |
| 196 | +``` |
| 197 | +
|
| 198 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 199 | +- `[in] value`: The value to set. |
| 200 | +
|
| 201 | +### SetInt16 |
| 202 | +
|
| 203 | +```cpp |
| 204 | +void SetInt16(size_t byteOffset, int16_t value) const; |
| 205 | +``` |
| 206 | + |
| 207 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 208 | +- `[in] value`: The value to set. |
| 209 | + |
| 210 | +### SetInt32 |
| 211 | + |
| 212 | +```cpp |
| 213 | +void SetInt32(size_t byteOffset, int32_t value) const; |
| 214 | +``` |
| 215 | +
|
| 216 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 217 | +- `[in] value`: The value to set. |
| 218 | +
|
| 219 | +### SetUint8 |
| 220 | +
|
| 221 | +```cpp |
| 222 | +void SetUint8(size_t byteOffset, uint8_t value) const; |
| 223 | +``` |
| 224 | + |
| 225 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 226 | +- `[in] value`: The value to set. |
| 227 | + |
| 228 | +### SetUint16 |
| 229 | + |
| 230 | +```cpp |
| 231 | +void SetUint16(size_t byteOffset, uint16_t value) const; |
| 232 | +``` |
| 233 | +
|
| 234 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 235 | +- `[in] value`: The value to set. |
| 236 | +
|
| 237 | +### SetUint32 |
| 238 | +
|
| 239 | +```cpp |
| 240 | +void SetUint32(size_t byteOffset, uint32_t value) const; |
| 241 | +``` |
| 242 | + |
| 243 | +- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. |
| 244 | +- `[in] value`: The value to set. |
0 commit comments