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