18c339a94Sopenharmony_ci# DataView 28c339a94Sopenharmony_ci 38c339a94Sopenharmony_ciClass `Napi::DataView` inherits from class [`Napi::Object`][]. 48c339a94Sopenharmony_ci 58c339a94Sopenharmony_ciThe `Napi::DataView` class corresponds to the 68c339a94Sopenharmony_ci[JavaScript `DataView`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) 78c339a94Sopenharmony_ciclass. 88c339a94Sopenharmony_ci 98c339a94Sopenharmony_ci## Methods 108c339a94Sopenharmony_ci 118c339a94Sopenharmony_ci### New 128c339a94Sopenharmony_ci 138c339a94Sopenharmony_ciAllocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. 148c339a94Sopenharmony_ci 158c339a94Sopenharmony_ci```cpp 168c339a94Sopenharmony_cistatic Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer); 178c339a94Sopenharmony_ci``` 188c339a94Sopenharmony_ci 198c339a94Sopenharmony_ci- `[in] env`: The environment in which to create the `Napi::DataView` instance. 208c339a94Sopenharmony_ci- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. 218c339a94Sopenharmony_ci 228c339a94Sopenharmony_ciReturns a new `Napi::DataView` instance. 238c339a94Sopenharmony_ci 248c339a94Sopenharmony_ci### New 258c339a94Sopenharmony_ci 268c339a94Sopenharmony_ciAllocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. 278c339a94Sopenharmony_ci 288c339a94Sopenharmony_ci```cpp 298c339a94Sopenharmony_cistatic Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset); 308c339a94Sopenharmony_ci``` 318c339a94Sopenharmony_ci 328c339a94Sopenharmony_ci- `[in] env`: The environment in which to create the `Napi::DataView` instance. 338c339a94Sopenharmony_ci- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. 348c339a94Sopenharmony_ci- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`. 358c339a94Sopenharmony_ci 368c339a94Sopenharmony_ciReturns a new `Napi::DataView` instance. 378c339a94Sopenharmony_ci 388c339a94Sopenharmony_ci### New 398c339a94Sopenharmony_ci 408c339a94Sopenharmony_ciAllocates a new `Napi::DataView` instance with a given `Napi::ArrayBuffer`. 418c339a94Sopenharmony_ci 428c339a94Sopenharmony_ci```cpp 438c339a94Sopenharmony_cistatic Napi::DataView Napi::DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer, size_t byteOffset, size_t byteLength); 448c339a94Sopenharmony_ci``` 458c339a94Sopenharmony_ci 468c339a94Sopenharmony_ci- `[in] env`: The environment in which to create the `Napi::DataView` instance. 478c339a94Sopenharmony_ci- `[in] arrayBuffer` : `Napi::ArrayBuffer` underlying the `Napi::DataView`. 488c339a94Sopenharmony_ci- `[in] byteOffset` : The byte offset within the `Napi::ArrayBuffer` from which to start projecting the `Napi::DataView`. 498c339a94Sopenharmony_ci- `[in] byteLength` : Number of elements in the `Napi::DataView`. 508c339a94Sopenharmony_ci 518c339a94Sopenharmony_ciReturns a new `Napi::DataView` instance. 528c339a94Sopenharmony_ci 538c339a94Sopenharmony_ci### Constructor 548c339a94Sopenharmony_ci 558c339a94Sopenharmony_ciInitializes an empty instance of the `Napi::DataView` class. 568c339a94Sopenharmony_ci 578c339a94Sopenharmony_ci```cpp 588c339a94Sopenharmony_ciNapi::DataView(); 598c339a94Sopenharmony_ci``` 608c339a94Sopenharmony_ci 618c339a94Sopenharmony_ci### Constructor 628c339a94Sopenharmony_ci 638c339a94Sopenharmony_ciInitializes a wrapper instance of an existing `Napi::DataView` instance. 648c339a94Sopenharmony_ci 658c339a94Sopenharmony_ci```cpp 668c339a94Sopenharmony_ciNapi::DataView(napi_env env, napi_value value); 678c339a94Sopenharmony_ci``` 688c339a94Sopenharmony_ci 698c339a94Sopenharmony_ci- `[in] env`: The environment in which to create the `Napi::DataView` instance. 708c339a94Sopenharmony_ci- `[in] value`: The `Napi::DataView` reference to wrap. 718c339a94Sopenharmony_ci 728c339a94Sopenharmony_ci### ArrayBuffer 738c339a94Sopenharmony_ci 748c339a94Sopenharmony_ci```cpp 758c339a94Sopenharmony_ciNapi::ArrayBuffer Napi::DataView::ArrayBuffer() const; 768c339a94Sopenharmony_ci``` 778c339a94Sopenharmony_ci 788c339a94Sopenharmony_ciReturns the backing array buffer. 798c339a94Sopenharmony_ci 808c339a94Sopenharmony_ci### ByteOffset 818c339a94Sopenharmony_ci 828c339a94Sopenharmony_ci```cpp 838c339a94Sopenharmony_cisize_t Napi::DataView::ByteOffset() const; 848c339a94Sopenharmony_ci``` 858c339a94Sopenharmony_ci 868c339a94Sopenharmony_ciReturns the offset into the `Napi::DataView` where the array starts, in bytes. 878c339a94Sopenharmony_ci 888c339a94Sopenharmony_ci### ByteLength 898c339a94Sopenharmony_ci 908c339a94Sopenharmony_ci```cpp 918c339a94Sopenharmony_cisize_t Napi::DataView::ByteLength() const; 928c339a94Sopenharmony_ci``` 938c339a94Sopenharmony_ci 948c339a94Sopenharmony_ciReturns the length of the array, in bytes. 958c339a94Sopenharmony_ci 968c339a94Sopenharmony_ci### GetFloat32 978c339a94Sopenharmony_ci 988c339a94Sopenharmony_ci```cpp 998c339a94Sopenharmony_cifloat Napi::DataView::GetFloat32(size_t byteOffset) const; 1008c339a94Sopenharmony_ci``` 1018c339a94Sopenharmony_ci 1028c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1038c339a94Sopenharmony_ci 1048c339a94Sopenharmony_ciReturns a signed 32-bit float (float) at the specified byte offset from the start of the `Napi::DataView`. 1058c339a94Sopenharmony_ci 1068c339a94Sopenharmony_ci### GetFloat64 1078c339a94Sopenharmony_ci 1088c339a94Sopenharmony_ci```cpp 1098c339a94Sopenharmony_cidouble Napi::DataView::GetFloat64(size_t byteOffset) const; 1108c339a94Sopenharmony_ci``` 1118c339a94Sopenharmony_ci 1128c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1138c339a94Sopenharmony_ci 1148c339a94Sopenharmony_ciReturns a signed 64-bit float (double) at the specified byte offset from the start of the `Napi::DataView`. 1158c339a94Sopenharmony_ci 1168c339a94Sopenharmony_ci### GetInt8 1178c339a94Sopenharmony_ci 1188c339a94Sopenharmony_ci```cpp 1198c339a94Sopenharmony_ciint8_t Napi::DataView::GetInt8(size_t byteOffset) const; 1208c339a94Sopenharmony_ci``` 1218c339a94Sopenharmony_ci 1228c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1238c339a94Sopenharmony_ci 1248c339a94Sopenharmony_ciReturns a signed 8-bit integer (byte) at the specified byte offset from the start of the `Napi::DataView`. 1258c339a94Sopenharmony_ci 1268c339a94Sopenharmony_ci### GetInt16 1278c339a94Sopenharmony_ci 1288c339a94Sopenharmony_ci```cpp 1298c339a94Sopenharmony_ciint16_t Napi::DataView::GetInt16(size_t byteOffset) const; 1308c339a94Sopenharmony_ci``` 1318c339a94Sopenharmony_ci 1328c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1338c339a94Sopenharmony_ci 1348c339a94Sopenharmony_ciReturns a signed 16-bit integer (short) at the specified byte offset from the start of the `Napi::DataView`. 1358c339a94Sopenharmony_ci 1368c339a94Sopenharmony_ci### GetInt32 1378c339a94Sopenharmony_ci 1388c339a94Sopenharmony_ci```cpp 1398c339a94Sopenharmony_ciint32_t Napi::DataView::GetInt32(size_t byteOffset) const; 1408c339a94Sopenharmony_ci``` 1418c339a94Sopenharmony_ci 1428c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1438c339a94Sopenharmony_ci 1448c339a94Sopenharmony_ciReturns a signed 32-bit integer (long) at the specified byte offset from the start of the `Napi::DataView`. 1458c339a94Sopenharmony_ci 1468c339a94Sopenharmony_ci### GetUint8 1478c339a94Sopenharmony_ci 1488c339a94Sopenharmony_ci```cpp 1498c339a94Sopenharmony_ciuint8_t Napi::DataView::GetUint8(size_t byteOffset) const; 1508c339a94Sopenharmony_ci``` 1518c339a94Sopenharmony_ci 1528c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1538c339a94Sopenharmony_ci 1548c339a94Sopenharmony_ciReturns a unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the `Napi::DataView`. 1558c339a94Sopenharmony_ci 1568c339a94Sopenharmony_ci### GetUint16 1578c339a94Sopenharmony_ci 1588c339a94Sopenharmony_ci```cpp 1598c339a94Sopenharmony_ciuint16_t Napi::DataView::GetUint16(size_t byteOffset) const; 1608c339a94Sopenharmony_ci``` 1618c339a94Sopenharmony_ci 1628c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1638c339a94Sopenharmony_ci 1648c339a94Sopenharmony_ciReturns a unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the `Napi::DataView`. 1658c339a94Sopenharmony_ci 1668c339a94Sopenharmony_ci### GetUint32 1678c339a94Sopenharmony_ci 1688c339a94Sopenharmony_ci```cpp 1698c339a94Sopenharmony_ciuint32_t Napi::DataView::GetUint32(size_t byteOffset) const; 1708c339a94Sopenharmony_ci``` 1718c339a94Sopenharmony_ci 1728c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1738c339a94Sopenharmony_ci 1748c339a94Sopenharmony_ciReturns a unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the `Napi::DataView`. 1758c339a94Sopenharmony_ci 1768c339a94Sopenharmony_ci### SetFloat32 1778c339a94Sopenharmony_ci 1788c339a94Sopenharmony_ci```cpp 1798c339a94Sopenharmony_civoid Napi::DataView::SetFloat32(size_t byteOffset, float value) const; 1808c339a94Sopenharmony_ci``` 1818c339a94Sopenharmony_ci 1828c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1838c339a94Sopenharmony_ci- `[in] value`: The value to set. 1848c339a94Sopenharmony_ci 1858c339a94Sopenharmony_ci### SetFloat64 1868c339a94Sopenharmony_ci 1878c339a94Sopenharmony_ci```cpp 1888c339a94Sopenharmony_civoid Napi::DataView::SetFloat64(size_t byteOffset, double value) const; 1898c339a94Sopenharmony_ci``` 1908c339a94Sopenharmony_ci 1918c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 1928c339a94Sopenharmony_ci- `[in] value`: The value to set. 1938c339a94Sopenharmony_ci 1948c339a94Sopenharmony_ci### SetInt8 1958c339a94Sopenharmony_ci 1968c339a94Sopenharmony_ci```cpp 1978c339a94Sopenharmony_civoid Napi::DataView::SetInt8(size_t byteOffset, int8_t value) const; 1988c339a94Sopenharmony_ci``` 1998c339a94Sopenharmony_ci 2008c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2018c339a94Sopenharmony_ci- `[in] value`: The value to set. 2028c339a94Sopenharmony_ci 2038c339a94Sopenharmony_ci### SetInt16 2048c339a94Sopenharmony_ci 2058c339a94Sopenharmony_ci```cpp 2068c339a94Sopenharmony_civoid Napi::DataView::SetInt16(size_t byteOffset, int16_t value) const; 2078c339a94Sopenharmony_ci``` 2088c339a94Sopenharmony_ci 2098c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2108c339a94Sopenharmony_ci- `[in] value`: The value to set. 2118c339a94Sopenharmony_ci 2128c339a94Sopenharmony_ci### SetInt32 2138c339a94Sopenharmony_ci 2148c339a94Sopenharmony_ci```cpp 2158c339a94Sopenharmony_civoid Napi::DataView::SetInt32(size_t byteOffset, int32_t value) const; 2168c339a94Sopenharmony_ci``` 2178c339a94Sopenharmony_ci 2188c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2198c339a94Sopenharmony_ci- `[in] value`: The value to set. 2208c339a94Sopenharmony_ci 2218c339a94Sopenharmony_ci### SetUint8 2228c339a94Sopenharmony_ci 2238c339a94Sopenharmony_ci```cpp 2248c339a94Sopenharmony_civoid Napi::DataView::SetUint8(size_t byteOffset, uint8_t value) const; 2258c339a94Sopenharmony_ci``` 2268c339a94Sopenharmony_ci 2278c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2288c339a94Sopenharmony_ci- `[in] value`: The value to set. 2298c339a94Sopenharmony_ci 2308c339a94Sopenharmony_ci### SetUint16 2318c339a94Sopenharmony_ci 2328c339a94Sopenharmony_ci```cpp 2338c339a94Sopenharmony_civoid Napi::DataView::SetUint16(size_t byteOffset, uint16_t value) const; 2348c339a94Sopenharmony_ci``` 2358c339a94Sopenharmony_ci 2368c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2378c339a94Sopenharmony_ci- `[in] value`: The value to set. 2388c339a94Sopenharmony_ci 2398c339a94Sopenharmony_ci### SetUint32 2408c339a94Sopenharmony_ci 2418c339a94Sopenharmony_ci```cpp 2428c339a94Sopenharmony_civoid Napi::DataView::SetUint32(size_t byteOffset, uint32_t value) const; 2438c339a94Sopenharmony_ci``` 2448c339a94Sopenharmony_ci 2458c339a94Sopenharmony_ci- `[in] byteOffset`: The offset, in byte, from the start of the view where to read the data. 2468c339a94Sopenharmony_ci- `[in] value`: The value to set. 2478c339a94Sopenharmony_ci 2488c339a94Sopenharmony_ci[`Napi::Object`]: ./object.md 249